Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PublicationEntryTabHandler.inc.php
1 <?php
2 
16 // Import the base Handler.
17 import('classes.handler.Handler');
18 
19 // Import classes for logging.
20 import('lib.pkp.classes.log.SubmissionLog');
21 import('classes.log.SubmissionEventLogEntry'); // app-specific.
22 
24 
26  var $_currentTab;
27 
29  var $_submission;
30 
32  var $_stageId;
33 
35  var $_tabPosition;
36 
40  function PublicationEntryTabHandler() {
41  parent::Handler();
42  $this->addRoleAssignment(
43  array(ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER),
44  array(
45  'submissionMetadata',
46  'saveForm',
47  )
48  );
49  }
50 
51 
52  //
53  // Getters and Setters
54  //
59  function getCurrentTab() {
60  return $this->_currentTab;
61  }
62 
67  function setCurrentTab($currentTab) {
68  $this->_currentTab = $currentTab;
69  }
70 
71 
72  //
73  // Extended methods from Handler
74  //
78  function initialize($request) {
79  $this->setCurrentTab($request->getUserVar('tab'));
80  $this->_submission =& $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
81  $this->_stageId =& $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
82  $this->_tabPosition = (int) $request->getUserVar('tabPos');
83 
84  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_APP_SUBMISSION);
85  $this->setupTemplate($request);
86  }
87 
91  function authorize($request, &$args, $roleAssignments) {
92  $stageId = (int) $request->getUserVar('stageId');
93  import('classes.security.authorization.WorkflowStageAccessPolicy');
94  $this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', $stageId));
95  return parent::authorize($request, $args, $roleAssignments);
96  }
97 
98 
99  //
100  // Public handler methods
101  //
108  function submissionMetadata($args, $request) {
109 
110  $publicationEntrySubmissionReviewForm = $this->_getPublicationEntrySubmissionReviewForm();
111 
112  $publicationEntrySubmissionReviewForm->initData($args, $request);
113  $json = new JSONMessage(true, $publicationEntrySubmissionReviewForm->fetch($request));
114  return $json->getString();
115  }
116 
120  function getSubmission() {
121  return $this->_submission;
122  }
123 
127  function getStageId() {
128  return $this->_stageId;
129  }
130 
134  function getTabPosition() {
135  return $this->_tabPosition;
136  }
137 
138 
145  function saveForm($args, $request) {
146  $json = new JSONMessage();
147  $form = null;
148 
149  $submission = $this->getSubmission();
150  $stageId = $this->getStageId();
151  $notificationKey = null;
152 
153  $this->_getFormFromCurrentTab($form, $notificationKey, $request);
154 
155  if ($form) { // null if we didn't have a valid tab
156  $form->readInputData();
157  if($form->validate()) {
158  $form->execute($request);
159  // Create trivial notification in place on the form
160  $notificationManager = new NotificationManager();
161  $user = $request->getUser();
162  $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __($notificationKey)));
163  } else {
164  // Could not validate; redisplay the form.
165  $json->setStatus(true);
166  $json->setContent($form->fetch($request));
167  }
168 
169  if ($request->getUserVar('displayedInContainer')) {
170  $router = $request->getRouter();
171  $dispatcher = $router->getDispatcher();
172  $url = $dispatcher->url($request, ROUTE_COMPONENT, null, $this->_getHandlerClassPath(), 'fetch', null, array('submissionId' => $submission->getId(), 'stageId' => $stageId, 'tabPos' => $this->getTabPosition(), 'hideHelp' => true));
173  $json->setAdditionalAttributes(array('reloadContainer' => true, 'tabsUrl' => $url));
174  $json->setContent(true); // prevents modal closure
175  return $json->getString();
176  } else {
177  return $json->getString(); // closes the modal
178  }
179  } else {
180  fatalError('Unknown or unassigned format id!');
181  }
182  }
183 
187  function _getFormFromCurrentTab(&$form, &$notificationKey, $request) {
188  switch ($this->getCurrentTab()) {
189  case 'submission':
191  $notificationKey = 'notification.savedSubmissionMetadata';
192  break;
193  }
194  }
195 
201  assert(false); // must be implemented in subclasses.
202  }
203 
208  function _getHandlerClassPath() {
209  assert(false); // in sub classes.
210  }
211 }
213 ?>
addPolicy($authorizationPolicy, $addToTop=false)
static requireComponents()
setupTemplate($request)
_getFormFromCurrentTab(&$form, &$notificationKey, $request)
Class to control access to OMP&#39;s submission workflow stage components.
addRoleAssignment($roleIds, $operations)
Class to represent a JSON (Javascript Object Notation) message.
authorize($request, &$args, $roleAssignments)
Base request handler application class.
Definition: Handler.inc.php:20
Base handler for AJAX operations for tabs on the Publication Entry management pages.
& getAuthorizedContextObject($assocType)