Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SubmissionMetadataHandler.inc.php
1 <?php
2 
16 import('classes.handler.Handler');
17 
18 // import JSON class for use with all AJAX requests
19 import('lib.pkp.classes.core.JSONMessage');
20 
26  parent::Handler();
27  }
28 
29 
30  //
31  // Implement template methods from PKPHandler.
32  //
36  function initialize($request) {
37  $this->setupTemplate($request);
38  }
39 
40 
41  //
42  // Public handler methods
43  //
50  function fetch($args, $request, $params = null) {
51  // Identify the submission
52  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
53  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION);
54 
55  // Identify the stage, if we have one.
56  $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
57 
58  // prevent anyone but managers and editors from submitting the catalog entry form
59  $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
60  if (!array_intersect(array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR), $userRoles)) {
61  $params['hideSubmit'] = true;
62  $params['readOnly'] = true;
63  }
64 
65  // Form handling
66  $submissionMetadataViewForm = $this->getFormInstance($submission->getId(), $stageId, $params);
67 
68  $submissionMetadataViewForm->initData($args, $request);
69 
70  $json = new JSONMessage(true, $submissionMetadataViewForm->fetch($request));
71  return $json->getString();
72  }
73 
79  function saveForm($args, $request) {
80  $submissionId = $request->getUserVar('submissionId');
81 
82  // Form handling
83  $submissionMetadataViewForm = $this->getFormInstance($submissionId);
84 
85  $json = new JSONMessage();
86 
87  // Try to save the form data.
88  $submissionMetadataViewForm->readInputData($request);
89  if($submissionMetadataViewForm->validate()) {
90  $submissionMetadataViewForm->execute($request);
91  // Create trivial notification.
92  $notificationManager = new NotificationManager();
93  $user = $request->getUser();
94  $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.savedSubmissionMetadata')));
95  } else {
96  $json->setStatus(false);
97  }
98 
99  return $json->getString();
100  }
101 
107  function getFormInstance($submissionId, $stageId = null, $params = null) {
108  // N.B.: All subclasses (within each application) currently
109  // use the same form class, but as it's app-dependent, we
110  // can't put the instantiation higher up the class tree.
111  assert(false); // To be implemented by subclasses
112  }
113 }
114 
115 ?>
getFormInstance($submissionId, $stageId=null, $params=null)
Base class for submission metadata view/edit operations.
static requireComponents()
setupTemplate($request)
Class to represent a JSON (Javascript Object Notation) message.
Base request handler application class.
Definition: Handler.inc.php:20
& getAuthorizedContextObject($assocType)
fetch($args, $request, $params=null)