/**
  * Return a mapping of workflow stages and its translation keys.
  * @return array
  */
 static function getWorkflowStageTranslationKeys()
 {
     $applicationStages = Application::getApplicationStages();
     AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);
     static $stageMapping = array(WORKFLOW_STAGE_ID_SUBMISSION => 'submission.submission', WORKFLOW_STAGE_ID_INTERNAL_REVIEW => 'workflow.review.internalReview', WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => 'workflow.review.externalReview', WORKFLOW_STAGE_ID_EDITING => 'submission.editorial', WORKFLOW_STAGE_ID_PRODUCTION => 'submission.production');
     return array_intersect_key($stageMapping, array_flip($applicationStages));
 }
 /**
  * @copydoc GridCellProvider::getCellActions()
  */
 function getCellActions($request, $row, $column, $position = GRID_ACTION_POSITION_DEFAULT)
 {
     $workflowStages = Application::getApplicationStages();
     $columnId = $column->getId();
     if (in_array($columnId, $workflowStages)) {
         $userGroup = $row->getData();
         /* @var $userGroup UserGroup */
         $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
         /* @var $userGroupDao UserGroupDAO */
         $assignedStages = $userGroupDao->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId());
         $router = $request->getRouter();
         $roleDao = DAORegistry::getDAO('RoleDAO');
         /* @var $roleDao RoleDAO */
         if (!in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) {
             if (in_array($columnId, array_keys($assignedStages))) {
                 $operation = 'unassignStage';
                 $actionTitleKey = 'grid.userGroup.unassignStage';
             } else {
                 $operation = 'assignStage';
                 $actionTitleKey = 'grid.userGroup.assignStage';
             }
             $actionArgs = array_merge(array('stageId' => $columnId), $row->getRequestArgs());
             $actionUrl = $router->url($request, null, null, $operation, null, $actionArgs);
             import('lib.pkp.classes.linkAction.request.AjaxAction');
             $actionRequest = new AjaxAction($actionUrl);
             $linkAction = new LinkAction($operation, $actionRequest, __($actionTitleKey), null);
             return array($linkAction);
         }
     }
     return parent::getCellActions($request, $row, $column, $position);
 }
 /**
  * @see AuthorizationPolicy::effect()
  */
 function effect()
 {
     // Check the stage id.
     $validAppStages = Application::getApplicationStages();
     if (!in_array($this->_stageId, array_values($validAppStages))) {
         return AUTHORIZATION_DENY;
     }
     // Save the workflow stage to the authorization context.
     $this->addAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE, $this->_stageId);
     return AUTHORIZATION_PERMIT;
 }
 /**
  * Delete the participant from the user groups
  * @param $args
  * @param $request
  * @return JSONMessage JSON object
  */
 function deleteParticipant($args, $request)
 {
     $submission = $this->getSubmission();
     $stageId = $this->getStageId();
     $assignmentId = (int) $request->getUserVar('assignmentId');
     $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
     /* @var $stageAssignmentDao StageAssignmentDAO */
     $stageAssignment = $stageAssignmentDao->getById($assignmentId);
     if (!$stageAssignment || $stageAssignment->getSubmissionId() != $submission->getId()) {
         fatalError('Invalid Assignment');
     }
     // Delete the assignment
     $stageAssignmentDao->deleteObject($stageAssignment);
     // FIXME: perhaps we can just insert the notification on page load
     // instead of having it there all the time?
     $stages = Application::getApplicationStages();
     foreach ($stages as $workingStageId) {
         // remove user's assignment from this user group from all the stages
         // (no need to check if user group is assigned, since nothing will be deleted if there isn't)
         $stageAssignmentDao->deleteByAll($submission->getId(), $workingStageId, $stageAssignment->getUserGroupId(), $stageAssignment->getUserId());
     }
     $notificationMgr = new NotificationManager();
     import('classes.workflow.EditorDecisionActionsManager');
     $notificationMgr->updateNotification($request, EditorDecisionActionsManager::getStageNotifications(), null, ASSOC_TYPE_SUBMISSION, $submission->getId());
     // Log removal.
     $userDao = DAORegistry::getDAO('UserDAO');
     $assignedUser = $userDao->getById($userId);
     $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
     $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId());
     import('lib.pkp.classes.log.SubmissionLog');
     SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_REMOVE_PARTICIPANT, 'submission.event.participantRemoved', array('name' => $assignedUser->getFullName(), 'username' => $assignedUser->getUsername(), 'userGroupName' => $userGroup->getLocalizedName()));
     // Redraw the category
     return DAO::getDataChangedEvent($stageAssignment->getUserGroupId());
 }
 /**
  * Update the row for the current userGroup's stage participant list.
  * @param $args array
  * @param $request PKPRequest
  * @return JSONMessage JSON object
  */
 function saveParticipant($args, $request)
 {
     $submission = $this->getSubmission();
     $stageId = $this->getStageId();
     $userGroups = $this->getGridDataElements($request);
     import('lib.pkp.controllers.grid.users.stageParticipant.form.AddParticipantForm');
     $form = new AddParticipantForm($submission, $stageId);
     $form->readInputData();
     if ($form->validate()) {
         list($userGroupId, $userId, $stageAssignmentId) = $form->execute($request);
         $notificationMgr = new NotificationManager();
         // Check user group role id.
         $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
         $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
         $userGroup = $userGroupDao->getById($userGroupId);
         import('classes.workflow.EditorDecisionActionsManager');
         if ($userGroup->getRoleId() == ROLE_ID_MANAGER) {
             $notificationMgr->updateNotification($request, EditorDecisionActionsManager::getStageNotifications(), null, ASSOC_TYPE_SUBMISSION, $submission->getId());
             $stages = Application::getApplicationStages();
             foreach ($stages as $workingStageId) {
                 // remove the 'editor required' task if we now have an editor assigned
                 if ($stageAssignmentDao->editorAssignedToStage($submission->getId(), $stageId)) {
                     $notificationDao = DAORegistry::getDAO('NotificationDAO');
                     $notificationDao->deleteByAssoc(ASSOC_TYPE_SUBMISSION, $submission->getId(), null, NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_REQUIRED);
                 }
             }
         }
         // Create trivial notification.
         $user = $request->getUser();
         $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.addedStageParticipant')));
         // Log addition.
         $userDao = DAORegistry::getDAO('UserDAO');
         $assignedUser = $userDao->getById($userId);
         import('lib.pkp.classes.log.SubmissionLog');
         SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_ADD_PARTICIPANT, 'submission.event.participantAdded', array('name' => $assignedUser->getFullName(), 'username' => $assignedUser->getUsername(), 'userGroupName' => $userGroup->getLocalizedName()));
         // send message to user if form is filled in.
         if ($form->getData('message')) {
             $form->sendMessage($form->getData('userId'), $submission, $request);
             $this->_logEventAndCreateNotification($request);
         }
         return DAO::getDataChangedEvent($userGroupId);
     } else {
         return new JSONMessage(true, $form->fetch($request));
     }
 }