Open Journal Systems  3.3.0
PKPWorkflowTabHandler.inc.php
1 <?php
2 
16 // Import the base Handler.
17 import('classes.handler.Handler');
18 import('lib.pkp.classes.core.JSONMessage');
19 
20 // Access decision actions constants.
21 import('classes.workflow.EditorDecisionActionsManager');
22 
23 abstract class PKPWorkflowTabHandler extends Handler {
24 
28  function __construct() {
29  parent::__construct();
30  $this->addRoleAssignment(array(ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER, ROLE_ID_ASSISTANT), array('fetchTab'));
31  }
32 
33 
34  //
35  // Extended methods from Handler
36  //
40  function authorize($request, &$args, $roleAssignments) {
41  // Authorize stage id.
42  import('lib.pkp.classes.security.authorization.WorkflowStageAccessPolicy');
43  $this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', $this->_identifyStageId($request), WORKFLOW_TYPE_EDITORIAL));
44 
45  return parent::authorize($request, $args, $roleAssignments);
46  }
47 
48 
49  //
50  // Public handler operations
51  //
58  function fetchTab($args, $request) {
59 
60  $this->setupTemplate($request);
61  $templateMgr = TemplateManager::getManager($request);
62 
63  $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
64  $templateMgr->assign('stageId', $stageId);
65 
66  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
67  $templateMgr->assign('submission', $submission);
68 
69  switch ($stageId) {
70  case WORKFLOW_STAGE_ID_SUBMISSION:
71  return $templateMgr->fetchJson('controllers/tab/workflow/submission.tpl');
72  case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
73  case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
74  // Retrieve the authorized submission and stage id.
75  $selectedStageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
76 
77  // Get all review rounds for this submission, on the current stage.
78  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
79  $reviewRoundsFactory = $reviewRoundDao->getBySubmissionId($submission->getId(), $selectedStageId);
80  $reviewRoundsArray = $reviewRoundsFactory->toAssociativeArray();
81  $lastReviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $selectedStageId);
82 
83  // Get the review round number of the last review round to be used
84  // as the current review round tab index, if we have review rounds.
85  if ($lastReviewRound) {
86  $lastReviewRoundNumber = $lastReviewRound->getRound();
87  $lastReviewRoundId = $lastReviewRound->getId();
88  $templateMgr->assign('lastReviewRoundNumber', $lastReviewRoundNumber);
89  } else {
90  $lastReviewRoundId = null;
91  }
92 
93  // Add the round information to the template.
94  $templateMgr->assign('reviewRounds', $reviewRoundsArray);
95  $templateMgr->assign('reviewRoundOp', $this->_identifyReviewRoundOp($stageId));
96 
97  if ($submission->getStageId() == $selectedStageId && count($reviewRoundsArray) > 0) {
98  $dispatcher = $request->getDispatcher();
99 
100  import('lib.pkp.classes.linkAction.request.AjaxModal');
101  $newRoundAction = new LinkAction(
102  'newRound',
103  new AjaxModal(
104  $dispatcher->url(
105  $request, ROUTE_COMPONENT, null,
106  'modals.editorDecision.EditorDecisionHandler',
107  'newReviewRound', null, array(
108  'submissionId' => $submission->getId(),
109  'decision' => SUBMISSION_EDITOR_DECISION_NEW_ROUND,
110  'stageId' => $selectedStageId,
111  'reviewRoundId' => $lastReviewRoundId
112  )
113  ),
114  __('editor.submission.newRound'),
115  'modal_add_item'
116  ),
117  __('editor.submission.newRound'),
118  'add_item_small'
119  );
120  $templateMgr->assign('newRoundAction', $newRoundAction);
121  }
122 
123  // Render the view.
124  return $templateMgr->fetchJson('controllers/tab/workflow/review.tpl');
125  case WORKFLOW_STAGE_ID_EDITING:
126  // Assign banner notifications to the template.
127  $notificationRequestOptions = array(
128  NOTIFICATION_LEVEL_NORMAL => array(
129  NOTIFICATION_TYPE_ASSIGN_COPYEDITOR => array(ASSOC_TYPE_SUBMISSION, $submission->getId()),
130  NOTIFICATION_TYPE_AWAITING_COPYEDITS => array(ASSOC_TYPE_SUBMISSION, $submission->getId())),
131  NOTIFICATION_LEVEL_TRIVIAL => array()
132  );
133  $templateMgr->assign('editingNotificationRequestOptions', $notificationRequestOptions);
134  return $templateMgr->fetchJson('controllers/tab/workflow/editorial.tpl');
135  case WORKFLOW_STAGE_ID_PRODUCTION:
136  $templateMgr = TemplateManager::getManager($request);
137  $notificationRequestOptions = $this->getProductionNotificationOptions($submission->getId());
138  $selectedStageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
139  $templateMgr->assign('productionNotificationRequestOptions', $notificationRequestOptions);
140 
141  return $templateMgr->fetchJson('controllers/tab/workflow/production.tpl');
142  }
143  }
144 
149  function setupTemplate($request) {
150  parent::setupTemplate($request);
151  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION, LOCALE_COMPONENT_APP_EDITOR, LOCALE_COMPONENT_PKP_GRID, LOCALE_COMPONENT_PKP_EDITOR);
152 
153  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
154  $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
155 
156  $templateMgr = TemplateManager::getManager($request);
157 
158  // Assign the authorized submission.
159  $templateMgr->assign('submission', $submission);
160 
161  // Assign workflow stages related data.
162  $templateMgr->assign('stageId', $stageId);
163  $templateMgr->assign('submissionStageId', $submission->getStageId());
164 
165  // Get the right notifications type based on current stage id.
166  $notificationMgr = new NotificationManager();
167  $editorAssignmentNotificationType = $this->getEditorAssignmentNotificationTypeByStageId($stageId);
168 
169  // Define the workflow notification options.
170  $notificationRequestOptions = array(
171  NOTIFICATION_LEVEL_TASK => array(
172  $editorAssignmentNotificationType => array(ASSOC_TYPE_SUBMISSION, $submission->getId())
173  ),
174  NOTIFICATION_LEVEL_TRIVIAL => array()
175  );
176 
177  $templateMgr->assign('workflowNotificationRequestOptions', $notificationRequestOptions);
178  }
179 
185  protected function getEditorAssignmentNotificationTypeByStageId($stageId) {
186  switch ($stageId) {
187  case WORKFLOW_STAGE_ID_SUBMISSION:
188  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_SUBMISSION;
189  case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
190  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EXTERNAL_REVIEW;
191  case WORKFLOW_STAGE_ID_EDITING:
192  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EDITING;
193  case WORKFLOW_STAGE_ID_PRODUCTION:
194  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_PRODUCTION;
195  }
196  return null;
197  }
198 
204  abstract protected function getProductionNotificationOptions($submissionId);
205 
211  private function _identifyStageId($request) {
212  if ($stageId = $request->getUserVar('stageId')) {
213  return (int) $stageId;
214  }
215  }
216 
222  private function _identifyReviewRoundOp($stageId) {
223  switch ($stageId) {
224  case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
225  return 'internalReviewRound';
226  case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
227  return 'externalReviewRound';
228  default:
229  fatalError('unknown review round id.');
230  }
231  }
232 }
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPWorkflowTabHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: PKPWorkflowTabHandler.inc.php:40
PKPWorkflowTabHandler\setupTemplate
setupTemplate($request)
Definition: PKPWorkflowTabHandler.inc.php:149
PKPWorkflowTabHandler
Handle AJAX operations for workflow tabs.
Definition: PKPWorkflowTabHandler.inc.php:23
PKPWorkflowTabHandler\__construct
__construct()
Definition: PKPWorkflowTabHandler.inc.php:28
PKPWorkflowTabHandler\fetchTab
fetchTab($args, $request)
Definition: PKPWorkflowTabHandler.inc.php:58
AjaxModal
A modal that retrieves its content from via AJAX.
Definition: AjaxModal.inc.php:18
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
PKPWorkflowTabHandler\getEditorAssignmentNotificationTypeByStageId
getEditorAssignmentNotificationTypeByStageId($stageId)
Definition: PKPWorkflowTabHandler.inc.php:185
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
PKPWorkflowTabHandler\getProductionNotificationOptions
getProductionNotificationOptions($submissionId)
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
WorkflowStageAccessPolicy
Class to control access to OMP's submission workflow stage components.
Definition: WorkflowStageAccessPolicy.inc.php:19
NotificationManager
Definition: NotificationManager.inc.php:19
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32
Handler
Base request handler application class.
Definition: Handler.inc.php:18