Open Journal Systems  3.3.0
SwordHandler.inc.php
1 <?php
2 
14 import('classes.handler.Handler');
15 class SwordHandler extends Handler {
17  protected $_parentPlugin = null;
18 
22  public function __construct() {
23  parent::__construct();
24  // set reference to markup plugin
25  $this->_parentPlugin = PluginRegistry::getPlugin('generic', 'swordplugin');
26  $this->addRoleAssignment(
27  array(ROLE_ID_MANAGER),
28  array('depositPoints','performManagerOnlyDeposit')
29  );
30  $this->addRoleAssignment(
31  array(ROLE_ID_MANAGER, ROLE_ID_AUTHOR),
32  array('index')
33  );
34  }
35 
39  function authorize($request, &$args, $roleAssignments) {
40  import('lib.pkp.classes.security.authorization.ContextAccessPolicy');
41  $this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));
42  return parent::authorize($request, $args, $roleAssignments);
43  }
44 
49  public function getSwordPlugin() {
50  return $this->_parentPlugin;
51  }
52 
60  public function depositPoints($args, $request) {
61  $context = $request->getContext();
62  $depositPointId = $request->getUserVar('depositPointId');
63  $this->getSwordPlugin()->import('classes.DepositPoint');
64  $depositPointDao = DAORegistry::getDAO('DepositPointDAO');
65  $depositPoint = $depositPointDao->getById($depositPointId, $context->getId());
66  if (!$depositPoint) {
67  return new JSONMessage(false);
68  }
69 
70  $this->getSwordPlugin()->import('classes.DepositPointsHelper');
72  $depositPoint->getSwordUrl(),
73  $depositPoint->getSwordUsername(),
74  $depositPoint->getSwordPassword(),
75  $depositPoint->getSwordApikey()
76  );
77  return new JSONMessage(true, array(
78  'username' => $depositPoint->getSwordUsername(),
79  'password' => SWORD_PASSWORD_SLUG,
80  'apikey' => $depositPoint->getSwordApikey(),
81  'depositPoints' => $collections,
82  ));
83  }
84 
92  public function index($args, $request) {
93  $context = $request->getContext();
94  $user = $request->getUser();
95  $submissionId = (int) array_shift($args);
96  $save = array_shift($args) == 'save';
97 
98  $submissionDao = Application::getSubmissionDAO();
99  $submission = $submissionDao->getById($submissionId);
100 
101  if (!$submission || !$user || !$context ||
102  ($submission->getContextId() != $context->getId())) {
103  $request->redirect(null, 'index');
104  }
105 
106  $userCanDeposit = false;
107  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
108  $daoResult = $stageAssignmentDao->getBySubmissionAndRoleId($submission->getId(), ROLE_ID_AUTHOR);
109  while ($record = $daoResult->next()) {
110  if($user->getId() == $record->getData('userId')) {
111  $userCanDeposit = true;
112  break;
113  }
114  }
115 
116  if (!userCanDeposit) {
117  $request->redirect(null, 'index');
118  }
119 
120  $swordPlugin = $this->getSwordPlugin();
121  $swordPlugin->import('AuthorDepositForm');
122  $authorDepositForm = new AuthorDepositForm($swordPlugin, $context, $submission);
123 
124  if ($save) {
125  $authorDepositForm->readInputData();
126  if ($authorDepositForm->validate()) {
127  $authorDepositForm->execute($request);
128  $request->redirect(null, 'submissions');
129  }
130  }
131  $authorDepositForm->initData();
132  $authorDepositForm->display();
133  }
134 }
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
SwordHandler
Handles request for sword plugin.
Definition: SwordHandler.inc.php:15
SwordHandler\__construct
__construct()
Definition: SwordHandler.inc.php:25
ContextAccessPolicy
Class to control access to PKP applications' setup components.
Definition: ContextAccessPolicy.inc.php:17
SwordHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: SwordHandler.inc.php:42
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
SwordHandler\depositPoints
depositPoints($args, $request)
Definition: SwordHandler.inc.php:63
SwordHandler\$_parentPlugin
$_parentPlugin
Definition: SwordHandler.inc.php:20
JSONMessage
Class to represent a JSON (Javascript Object Notation) message.
Definition: JSONMessage.inc.php:18
Application\getSubmissionDAO
static getSubmissionDAO()
Definition: Application.inc.php:146
DepositPointsHelper\loadCollectionsFromServer
static loadCollectionsFromServer($url, $username, $password, $apikey=null)
Definition: DepositPointsHelper.inc.php:24
AuthorDepositForm
Form to perform an author's SWORD deposit(s)
Definition: AuthorDepositForm.inc.php:16
PluginRegistry\getPlugin
static getPlugin($category, $name)
Definition: PluginRegistry.inc.php:85
SwordHandler\getSwordPlugin
getSwordPlugin()
Definition: SwordHandler.inc.php:52
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
SwordHandler\index
index($args, $request)
Definition: SwordHandler.inc.php:95
Handler
Base request handler application class.
Definition: Handler.inc.php:18