Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPSubmissionHandler.inc.php
1 <?php
2 
16 import('classes.handler.Handler');
17 import('lib.pkp.classes.core.JSONMessage');
18 
23  function PKPSubmissionHandler() {
24  parent::Handler();
25  }
26 
30  function authorize($request, &$args, $roleAssignments) {
31  // The policy for the submission handler depends on the
32  // step currently requested.
33  $step = isset($args[0]) ? (int) $args[0] : 1;
34  if ($step<1 || $step>$this->_getStepCount()) return false;
35 
36  // Do we have a submission present in the request?
37  $submissionId = (int)$request->getUserVar('submissionId');
38 
39  // Are we in step one without a submission present?
40  if ($step === 1 && $submissionId === 0) {
41  // Authorize submission creation.
42  import('lib.pkp.classes.security.authorization.PkpContextAccessPolicy');
43  $this->addPolicy(new PkpContextAccessPolicy($request, $roleAssignments));
44  } else {
45  // Authorize editing of incomplete submissions.
46  import('classes.security.authorization.SubmissionAccessPolicy');
47  $this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments, 'submissionId'));
48  }
49 
50  // Do policy checking.
51  if (!parent::authorize($request, $args, $roleAssignments)) return false;
52 
53  // Execute additional checking of the step.
54  // NB: Move this to its own policy for reuse when required in other places.
55  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
56 
57  // Permit if there is no submission set, but request is for initial step.
58  if (!is_a($submission, 'Submission') && $step == 1) return true;
59 
60  // In all other cases we expect an authorized submission due to
61  // the submission access policy above.
62  assert(is_a($submission, 'Submission'));
63 
64  // Deny if submission is complete (==0 means complete) and at
65  // any step other than the "complete" step (the last one)
66  if ($submission->getSubmissionProgress() == 0 && $step != $this->_getStepCount() ) return false;
67 
68  // Deny if trying to access a step greater than the current progress
69  if ($submission->getSubmissionProgress() != 0 && $step > $submission->getSubmissionProgress()) return false;
70 
71  return true;
72  }
73 
74 
75  //
76  // Public Handler Methods
77  //
83  function index($args, $request) {
84  $request->redirect(null, null, 'wizard');
85  }
86 
92  function wizard($args, $request) {
93  $this->setupTemplate($request);
94  $templateMgr = TemplateManager::getManager($request);
95  $step = isset($args[0]) ? (int) $args[0] : 1;
96  $templateMgr->assign('step', $step);
97 
98  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
99  if ($submission) {
100  $templateMgr->assign('submissionId', $submission->getId());
101  $templateMgr->assign('submissionProgress', (int) $submission->getSubmissionProgress());
102  } else {
103  $templateMgr->assign('submissionProgress', 1);
104  }
105  $templateMgr->display('submission/form/index.tpl');
106  }
107 
114  function step($args, $request) {
115  $step = isset($args[0]) ? (int) $args[0] : 1;
116 
117  $context = $request->getContext();
118  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
119 
120  $this->setupTemplate($request);
121 
122  if ( $step < $this->_getStepCount() ) {
123  $formClass = "SubmissionSubmitStep{$step}Form";
124  import("classes.submission.form.$formClass");
125 
126  $submitForm = new $formClass($context, $submission);
127  if ($submitForm->isLocaleResubmit()) {
128  $submitForm->readInputData();
129  } else {
130  $submitForm->initData();
131  }
132  $json = new JSONMessage(true, $submitForm->fetch($request));
133  return $json->getString();
134  $submitForm->display($request);
135  } elseif($step == $this->_getStepCount()) {
136  $templateMgr = TemplateManager::getManager($request);
137  $templateMgr->assign('context', $context);
138 
139  // Retrieve the correct url for author review his submission.
140  import('lib.pkp.controllers.grid.submissions.SubmissionsListGridCellProvider');
141  list($page, $operation) = SubmissionsListGridCellProvider::getPageAndOperationByUserRoles($request, $submission);
142  $router = $request->getRouter();
143  $dispatcher = $router->getDispatcher();
144  $reviewSubmissionUrl = $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), $page, $operation, $submission->getId());
145 
146  $templateMgr->assign('reviewSubmissionUrl', $reviewSubmissionUrl);
147  $templateMgr->assign('submissionId', $submission->getId());
148  $templateMgr->assign('submitStep', $step);
149  $templateMgr->assign('submissionProgress', $submission->getSubmissionProgress());
150  if ($this->_canExpedite($request->getUser(), $context)) {
151  $templateMgr->assign('canExpedite', true);
152 
153  import('lib.pkp.classes.linkAction.request.AjaxModal');
154  $templateMgr->assign('expediteLinkAction', new LinkAction(
155  'expedite',
156  new AjaxModal(
157  $router->url($request, null, 'workflow', 'expedite', $submission->getId()),
158  __('submission.submit.confirmExpedite'),
159  'modal_edit',
160  true
161  ),
162  __('submission.submit.expediteSubmission')
163  ));
164  }
165 
166  $json = new JSONMessage(true, $templateMgr->fetch('submission/form/complete.tpl'));
167  return $json->getString();
168  }
169  }
170 
176  function saveStep($args, $request) {
177  $step = isset($args[0]) ? (int) $args[0] : 1;
178 
179  $router = $request->getRouter();
180  $context = $router->getContext($request);
181  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
182 
183  $this->setupTemplate($request);
184 
185  $formClass = "SubmissionSubmitStep{$step}Form";
186  import("classes.submission.form.$formClass");
187 
188  $submitForm = new $formClass($context, $submission);
189  $submitForm->readInputData();
190 
191  if (!HookRegistry::call('SubmissionHandler::saveSubmit', array($step, &$submission, &$submitForm))) {
192  if ($submitForm->validate()) {
193  $submissionId = $submitForm->execute($args, $request);
194  if (!$submission) {
195  return $request->redirectUrlJson($router->url($request, null, null, 'wizard', $step+1, array('submissionId' => $submissionId), '2'));
196  }
197  $json = new JSONMessage(true);
198  $json->setEvent('setStep', max($step+1, $submission->getSubmissionProgress()));
199  } else {
200  $json = new JSONMessage(true, $submitForm->fetch($request));
201  }
202  return $json->getString();
203  }
204  }
205 
206  //
207  // Protected helper methods
208  //
213  function setupTemplate($request) {
214  parent::setupTemplate($request);
215  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
216 
217  // Get steps information.
218  $templateMgr = TemplateManager::getManager($request);
219  $templateMgr->assign('steps', $this->_getStepsNumberAndLocaleKeys());
220  }
221 
226  protected function _getStepsNumberAndLocaleKeys() {
227  assert(false); // Subclasses to implement
228  }
229 
234  protected function _getStepCount() {
235  assert(false); // Subclasses to implement
236  }
237 
243  protected function _canExpedite($user, $context) {
244  $userGroupAssignmentDao = DAORegistry::getDAO('UserGroupAssignmentDAO');
245  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
246  $userGroupAssignments = $userGroupAssignmentDao->getByUserId($user->getId(), $context->getId());
247  if (!$userGroupAssignments->wasEmpty()) {
248  while ($userGroupAssignment = $userGroupAssignments->next()) {
249  $userGroup = $userGroupDao->getById($userGroupAssignment->getUserGroupId());
250  if (in_array($userGroup->getRoleId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) {
251  return true;
252  }
253  }
254  }
255 
256  return false;
257  }
258 }
259 
260 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
static requireComponents()
Class to control access to PKP applications&#39; setup components.
Class to control (write) access to submissions and (read) access to submission details in OMP...
A modal that retrieves its content from via AJAX.
Base handler for submission requests.
Class to represent a JSON (Javascript Object Notation) message.
static call($hookName, $args=null)
Base request handler application class.
Definition: Handler.inc.php:20
static getPageAndOperationByUserRoles($request, $submission, $userId=null)
& getAuthorizedContextObject($assocType)
authorize($request, &$args, $roleAssignments)
Base class defining an action that can be performed by the user in the user interface.