getData(); /** @var UserGroup $userGroup */ $columnId = $column->getId(); $workflowStages = Application::getApplicationStages(); $roleDao = DAORegistry::getDAO('RoleDAO'); /** @var RoleDAO $roleDao */ $assignedStages = Repo::userGroup()->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId())->toArray(); switch ($columnId) { case 'name': return ['label' => $userGroup->getLocalizedName()]; case 'roleId': $roleNames = Application::getRoleNames(false, [$userGroup->getRoleId()]); return ['label' => __(array_shift($roleNames))]; case in_array($columnId, $workflowStages): // Set the state of the select element that will // be used to assign the stage to the user group. $selectDisabled = false; if (in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) { // This stage should not be assigned to the user group. $selectDisabled = true; } return ['selected' => in_array($columnId, $assignedStages), 'disabled' => $selectDisabled]; default: break; } return parent::getTemplateVarsFromRowColumn($row, $column); } /** * @copydoc GridCellProvider::getCellActions() */ public function getCellActions($request, $row, $column, $position = GridHandler::GRID_ACTION_POSITION_DEFAULT) { $workflowStages = Application::getApplicationStages(); $columnId = $column->getId(); if (in_array($columnId, $workflowStages)) { $userGroup = $row->getData(); /** @var UserGroup $userGroup */ $assignedStages = Repo::userGroup()->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId())->toArray(); $router = $request->getRouter(); $roleDao = DAORegistry::getDAO('RoleDAO'); /** @var RoleDAO $roleDao */ if (!in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) { if (in_array($columnId, $assignedStages)) { $operation = 'unassignStage'; $actionTitleKey = 'grid.userGroup.unassignStage'; } else { $operation = 'assignStage'; $actionTitleKey = 'grid.userGroup.assignStage'; } $actionArgs = array_merge( ['stageId' => $columnId], $row->getRequestArgs() ); $actionUrl = $router->url($request, null, null, $operation, null, $actionArgs); $actionRequest = new AjaxAction($actionUrl); $linkAction = new LinkAction( $operation, $actionRequest, __($actionTitleKey), null ); return [$linkAction]; } } return parent::getCellActions($request, $row, $column, $position); } }