Open Preprint Systems  3.3.0
pages/submission/SubmissionHandler.inc.php
1 <?php
2 
16 import('classes.handler.Handler');
17 import('lib.pkp.classes.core.JSONMessage');
18 import('lib.pkp.pages.submission.PKPSubmissionHandler');
19 
24  function __construct() {
25  parent::__construct();
26  $this->addRoleAssignment(array(ROLE_ID_AUTHOR, ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER),
27  array('index', 'wizard', 'step', 'saveStep', 'fetchChoices'));
28  }
29 
30 
31  //
32  // Public methods
33  //
37  function step($args, $request) {
38  $step = isset($args[0]) ? (int) $args[0] : 1;
39  if ($step == $this->getStepCount()) {
40  $templateMgr = TemplateManager::getManager($request);
41  $context = $request->getContext();
42  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
43 
44  // OPS: Check if author can publish
45  // OPS: Author can publish, see if other criteria exists and create an array of errors
46  import('classes.core.Services');
47  if (Services::get('publication')->canAuthorPublish($submission->getId())){
48 
49  $primaryLocale = $context->getPrimaryLocale();
50  $allowedLocales = $context->getSupportedLocales();
51  $errors = Services::get('publication')->validatePublish($submission->getLatestPublication(), $submission, $allowedLocales, $primaryLocale);
52 
53  if (!empty($errors)){
54  $msg .= '<ul class="plain">';
55  foreach ($errors as $error) {
56  $msg .= '<li>' . $error . '</li>';
57  }
58  $msg .= '</ul>';
59  $templateMgr->assign('errors', $msg);
60  }
61  }
62  // OPS: Author can not publish
63  else {
64  $templateMgr->assign('authorCanNotPublish', true);
65  }
66  }
67  return parent::step($args, $request);
68  }
69 
75  function fetchChoices($args, $request) {
76  $term = $request->getUserVar('term');
77  $locale = $request->getUserVar('locale');
78  if (!$locale) {
79  $locale = AppLocale::getLocale();
80  }
81  switch ($request->getUserVar('list')) {
82  case 'languages':
83  $isoCodes = new \Sokil\IsoCodes\IsoCodesFactory(\Sokil\IsoCodes\IsoCodesFactory::OPTIMISATION_IO);
84  $matches = array();
85  foreach ($isoCodes->getLanguages() as $language) {
86  if (!$language->getAlpha2() || $language->getType() != 'L' || $language->getScope() != 'I') continue;
87  if (stristr($language->getLocalName(), $term)) $matches[$language->getAlpha3()] = $language->getLocalName();
88  };
89  header('Content-Type: text/json');
90  echo json_encode($matches);
91  }
92  assert(false);
93  }
94 
95 
96  //
97  // Protected helper methods
98  //
103  function setupTemplate($request) {
104  AppLocale::requireComponents(LOCALE_COMPONENT_APP_AUTHOR);
105  return parent::setupTemplate($request);
106  }
107 
113  return array(
114  1 => 'author.submit.start',
115  2 => 'author.submit.upload',
116  3 => 'author.submit.metadata',
117  4 => 'author.submit.confirmation',
118  5 => 'author.submit.nextSteps',
119  );
120  }
121 
126  function getStepCount() {
127  return 5;
128  }
129 }
130 
131 
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
SubmissionHandler\__construct
__construct()
Definition: pages/submission/SubmissionHandler.inc.php:24
SubmissionHandler\getStepsNumberAndLocaleKeys
getStepsNumberAndLocaleKeys()
Definition: pages/submission/SubmissionHandler.inc.php:112
SubmissionHandler\setupTemplate
setupTemplate($request)
Definition: pages/submission/SubmissionHandler.inc.php:103
SubmissionHandler\getStepCount
getStepCount()
Definition: pages/submission/SubmissionHandler.inc.php:126
SubmissionHandler
Handle API requests for submission operations.
Definition: api/v1/submissions/SubmissionHandler.inc.php:21
PKPSubmissionHandler
Base handler for submission requests.
Definition: api/v1/submissions/PKPSubmissionHandler.inc.php:20
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1226
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
SubmissionHandler\step
step($args, $request)
Definition: pages/submission/SubmissionHandler.inc.php:37
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
SubmissionHandler\fetchChoices
fetchChoices($args, $request)
Definition: pages/submission/SubmissionHandler.inc.php:75
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49