Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
WorkflowHandler.inc.php
1 <?php
2 
16 import('lib.pkp.pages.workflow.PKPWorkflowHandler');
17 
18 // Access decision actions constants.
19 import('classes.workflow.EditorDecisionActionsManager');
20 
21 class WorkflowHandler extends PKPWorkflowHandler {
25  function WorkflowHandler() {
26  parent::PKPWorkflowHandler();
27 
28  $this->addRoleAssignment(
29  array(ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER, ROLE_ID_ASSISTANT),
30  array(
31  'access', 'submission',
32  'editorDecisionActions', // Submission & review
33  'internalReview', // Internal review
34  'externalReview', // External review
35  'editorial',
36  'production', 'productionFormatsTab', // Production
37  'submissionProgressBar',
38  'expedite'
39  )
40  );
41  }
42 
43 
44  //
45  // Public handler methods
46  //
52  function internalReview($args, $request) {
53  // Use different ops so we can identify stage by op.
54  $templateMgr = TemplateManager::getManager($request);
55  $templateMgr->assign('reviewRoundOp', 'internalReviewRound');
56  return $this->_review($args, $request);
57  }
58 
64  function production(&$args, $request) {
65  $templateMgr = TemplateManager::getManager($request);
66  $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
67  $notificationRequestOptions = array(
68  NOTIFICATION_LEVEL_NORMAL => array(
69  NOTIFICATION_TYPE_VISIT_CATALOG => array(ASSOC_TYPE_MONOGRAPH, $monograph->getId()),
70  NOTIFICATION_TYPE_APPROVE_SUBMISSION => array(ASSOC_TYPE_MONOGRAPH, $monograph->getId()),
71  ),
72  NOTIFICATION_LEVEL_TRIVIAL => array()
73  );
74 
75  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
76  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
77  $publicationFormats = $publicationFormatDao->getBySubmissionId($submission->getId());
78  $templateMgr->assign('publicationFormats', $publicationFormats->toAssociativeArray());
79 
80  $templateMgr->assign('productionNotificationRequestOptions', $notificationRequestOptions);
81  $templateMgr->display('workflow/production.tpl');
82  }
83 
89  function productionFormatsTab(&$args, $request) {
90  $templateMgr = TemplateManager::getManager($request);
91  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
92  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
93  $publicationFormats = $publicationFormatDao->getBySubmissionId($submission->getId());
94  $templateMgr->assign('submission', $submission);
95  $templateMgr->assign('publicationFormats', $publicationFormats->toAssociativeArray());
96  $templateMgr->assign('currentFormatTabId', (int) $request->getUserVar('currentFormatTabId'));
97 
98  return $templateMgr->fetchJson('workflow/productionFormatsTab.tpl');
99  }
100 
106  function submissionProgressBar($args, $request) {
107  // Assign the actions to the template.
108  $templateMgr = TemplateManager::getManager($request);
109  $press = $request->getPress();
110 
111  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
112  $workflowStages = $userGroupDao->getWorkflowStageKeysAndPaths();
113  $stageNotifications = array();
114  foreach (array_keys($workflowStages) as $stageId) {
115  $stageNotifications[$stageId] = $this->_notificationOptionsByStage($request->getUser(), $stageId, $press->getId());
116  }
117 
118  $templateMgr->assign('stageNotifications', $stageNotifications);
119 
120  $monograph = $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
121  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
122  $publishedMonograph = $publishedMonographDao->getById($monograph->getId());
123  if ($publishedMonograph) { // first check, there's a published monograph
124  $publicationFormats = $publishedMonograph->getPublicationFormats(true);
125  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
126  import('classes.monograph.MonographFile'); // constants
127 
128  foreach ($publicationFormats as $format) { // there is at least one publication format.
129  if ($format->getIsApproved()) { // it's ready to be included in the catalog
130 
131  $monographFiles = $submissionFileDao->getLatestRevisionsByAssocId(
132  ASSOC_TYPE_PUBLICATION_FORMAT, $format->getId(),
133  $publishedMonograph->getId()
134  );
135 
136  foreach ($monographFiles as $file) {
137  if ($file->getViewable() && !is_null($file->getDirectSalesPrice())) { // at least one file has a price set.
138  $templateMgr->assign('submissionIsReady', true);
139  }
140  }
141  }
142  }
143  }
144  return $templateMgr->fetchJson('workflow/submissionProgressBar.tpl');
145  }
146 
152  function expedite($args, $request) {
153 
154  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
155  import('controllers.modals.submissionMetadata.form.CatalogEntrySubmissionReviewForm');
156  $user = $request->getUser();
157  $form = new CatalogEntrySubmissionReviewForm($submission->getId(), null, array('expeditedSubmission' => true));
158  if ($submission && $request->getUserVar('confirm') != '') {
159 
160  // Process our submitted form in order to create the catalog entry.
161  $form->readInputData();
162  if($form->validate()) {
163  $form->execute($request);
164  // Create trivial notification in place on the form.
165  $notificationManager = new NotificationManager();
166  $user = $request->getUser();
167  $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.savedSubmissionMetadata')));
168 
169  // Now, create a publication format for this submission. Assume PDF, digital, and set to 'available'.
170  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
171  $publicationFormat = $publicationFormatDao->newDataObject();
172  $publicationFormat->setPhysicalFormat(false);
173  $publicationFormat->setIsApproved(true);
174  $publicationFormat->setIsAvailable(true);
175  $publicationFormat->setSubmissionId($submission->getId());
176  $publicationFormat->setProductAvailabilityCode('20'); // ONIX code for Available.
177  $publicationFormat->setEntryKey('DA'); // ONIX code for Digital
178  $publicationFormat->setData('name', 'PDF', $submission->getLocale());
179  $publicationFormat->setSeq(REALLY_BIG_NUMBER);
180  $publicationFormatId = $publicationFormatDao->insertObject($publicationFormat);
181 
182  // Next, create a galley PROOF file out of the submission file uploaded.
183  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
184  import('lib.pkp.classes.submission.SubmissionFile'); // constants.
185  $submissionFiles = $submissionFileDao->getLatestRevisions($submission->getId(), SUBMISSION_FILE_SUBMISSION);
186  // Assume a single file was uploaded, but check for something that's PDF anyway.
187  foreach ($submissionFiles as $submissionFile) {
188  // test both mime type and file extension in case the mime type isn't correct after uploading.
189  if ($submissionFile->getFileType() == 'application/pdf' || preg_match('/\.pdf$/', $submissionFile->getOriginalFileName())) {
190 
191  // Get the path of the current file because we change the file stage in a bit.
192  $currentFilePath = $submissionFile->getFilePath();
193 
194  // this will be a new file based on the old one.
195  $submissionFile->setFileId(null);
196  $submissionFile->setRevision(1);
197  $submissionFile->setViewable(true);
198  $submissionFile->setFileStage(SUBMISSION_FILE_PROOF);
199  $submissionFile->setAssocType(ASSOC_TYPE_REPRESENTATION);
200  $submissionFile->setAssocId($publicationFormatId);
201 
202  // Assign the sales type and price for the submission file.
203  switch ($request->getUserVar('salesType')) {
204  case 'notAvailable':
205  $submissionFile->setDirectSalesPrice(null);
206  $submissionFile->setSalesType('notAvailable');
207  break;
208  case 'openAccess':
209  $submissionFile->setDirectSalesPrice(0);
210  $submissionFile->setSalesType('openAccess');
211  break;
212  default:
213  $submissionFile->setDirectSalesPrice($request->getUserVar('price'));
214  $submissionFile->setSalesType('directSales');
215  }
216 
217  $submissionFileDao->insertObject($submissionFile, $currentFilePath);
218  break;
219  }
220  }
221 
222  // no errors, close the modal.
223  $json = new JSONMessage(true);
224  return $json->getString();
225  } else {
226  $json = new JSONMessage(true, $form->fetch($request));
227  return $json->getString();
228  }
229  } else {
230  $json = new JSONMessage(true, $form->fetch($request));
231  return $json->getString();
232  }
233  }
234 
242  function _notificationOptionsByStage($user, $stageId, $contextId) {
243 
244  $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
245  $notificationDao = DAORegistry::getDAO('NotificationDAO');
246 
247  $signOffNotificationType = $this->_getSignoffNotificationTypeByStageId($stageId);
248  $editorAssignmentNotificationType = $this->_getEditorAssignmentNotificationTypeByStageId($stageId);
249 
250  $editorAssignments =& $notificationDao->getByAssoc(ASSOC_TYPE_MONOGRAPH, $monograph->getId(), null, $editorAssignmentNotificationType, $contextId);
251  if (isset($signOffNotificationType)) {
252  $signoffAssignments =& $notificationDao->getByAssoc(ASSOC_TYPE_MONOGRAPH, $monograph->getId(), $user->getId(), $signOffNotificationType, $contextId);
253  }
254 
255  // if the User has assigned TASKs in this stage check, return true
256  if (!$editorAssignments->wasEmpty() || (isset($signoffAssignments) && !$signoffAssignments->wasEmpty())) {
257  return true;
258  }
259 
260  // check for more specific notifications on those stages that have them.
261  if ($stageId == WORKFLOW_STAGE_ID_PRODUCTION) {
262  $submissionApprovalNotification =& $notificationDao->getByAssoc(ASSOC_TYPE_MONOGRAPH, $monograph->getId(), null, NOTIFICATION_TYPE_APPROVE_SUBMISSION, $contextId);
263  if (!$submissionApprovalNotification->wasEmpty()) {
264  return true;
265  }
266  }
267 
268  if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW || $stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
269  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
270  $reviewRounds =& $reviewRoundDao->getBySubmissionId($monograph->getId(), $stageId);
271  $notificationTypes = array(NOTIFICATION_TYPE_REVIEW_ROUND_STATUS, NOTIFICATION_TYPE_ALL_REVIEWS_IN);
272  while ($reviewRound = $reviewRounds->next()) {
273  foreach ($notificationTypes as $type) {
274  $notifications = $notificationDao->getByAssoc(ASSOC_TYPE_REVIEW_ROUND, $reviewRound->getId(), null, $type, $contextId);
275  if (!$notifications->wasEmpty()) {
276  return true;
277  }
278  }
279  }
280  }
281 
282  return false;
283  }
284 
285  //
286  // Protected helper methods
287  //
293  protected function _getEditorAssignmentNotificationTypeByStageId($stageId) {
294  switch ($stageId) {
295  case WORKFLOW_STAGE_ID_SUBMISSION:
296  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_SUBMISSION;
297  case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
298  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_INTERNAL_REVIEW;
299  case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
300  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EXTERNAL_REVIEW;
301  case WORKFLOW_STAGE_ID_EDITING:
302  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EDITING;
303  case WORKFLOW_STAGE_ID_PRODUCTION:
304  return NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_PRODUCTION;
305  }
306  return null;
307  }
308 }
309 
310 ?>
static & getDAO($name, $dbconn=null)
Handle requests for the submssion workflow.
internalReview($args, $request)
Displays a submission&#39;s metadata view.
_getEditorAssignmentNotificationTypeByStageId($stageId)
expedite($args, $request)
addRoleAssignment($roleIds, $operations)
production(&$args, $request)
Class to represent a JSON (Javascript Object Notation) message.
submissionProgressBar($args, $request)
_notificationOptionsByStage($user, $stageId, $contextId)
productionFormatsTab(&$args, $request)
& getAuthorizedContextObject($assocType)