Open Journal Systems  3.3.0
AuthorDepositForm.inc.php
1 <?php
2 
14 import('lib.pkp.classes.form.Form');
15 
16 class AuthorDepositForm extends Form {
18  protected $_context = null;
19 
21  protected $_plugin = null;
22 
24  protected $_submission = null;
25 
32  public function __construct(SwordPlugin $plugin, Context $context, Submission $submission) {
33  $this->_plugin = $plugin;
34  $this->_context = $context;
35  $this->_submission = $submission;
36  PKPLocale::requireComponents(LOCALE_COMPONENT_PKP_USER);
37  parent::__construct($plugin->getTemplateResource('authorDepositForm.tpl'));
38  }
39 
44  public function getSwordPlugin() {
45  return $this->_plugin;
46  }
47 
51  public function readInputData() {
52  $this->readUserVars(array(
53  'authorDepositUrl',
54  'authorDepositUsername',
55  'authorDepositPassword',
56  'depositPoint',
57  ));
58  }
59 
63  public function display() {
64  $request = Application::getRequest();
65  $templateMgr = TemplateManager::getManager($request);
66  $depositPoints = $this->_getDepositableDepositPoints($this->_context);
67  $templateMgr->assign(array(
68  'depositPoints' => $depositPoints,
69  'submission' => $this->_submission,
70  'allowAuthorSpecify' => $this->getSwordPlugin()->getSetting($this->_context->getId(), 'allowAuthorSpecify'),
71  'pluginJavaScriptURL' => $this->_plugin->getJsUrl($request),
72  ));
73  parent::display();
74  }
75 
80  public function execute($request) {
81  $user = $request->getUser();
82  $notificationManager = new NotificationManager();
83  $this->getSwordPlugin()->import('classes.PKPSwordDeposit');
84 
85  $deposit = new PKPSwordDeposit($this->_submission);
86  $deposit->setMetadata($request);
87  $deposit->addEditorial();
88  $deposit->createPackage();
89 
90  $allowAuthorSpecify = $this->getSwordPlugin()->getSetting($this->_context->getId(), 'allowAuthorSpecify');
91  $authorDepositUrl = $this->getData('authorDepositUrl');
92  if (($allowAuthorSpecify) && ($authorDepositUrl != '')) {
93  try {
94  $deposit->deposit(
95  $this->getData('authorDepositUrl'),
96  $this->getData('authorDepositUsername'),
97  $this->getData('authorDepositPassword')
98  );
99  $params = array(
100  'itemTitle' => $this->_submission->getLocalizedTitle(),
101  'repositoryName' => $this->getData('authorDepositUrl')
102  );
103  $notificationManager->createTrivialNotification(
104  $user->getId(),
105  NOTIFICATION_TYPE_SUCCESS,
106  array('contents' => __('plugins.generic.sword.depositComplete', $params))
107  );
108  }
109  catch(Exception $e) {
110  $contents = __('plugins.importexport.sword.depositFailed') . ': ' . $e->getMessage();
111  $notificationManager->createTrivialNotification(
112  $user->getId(),
113  NOTIFICATION_TYPE_ERROR,
114  array('contents' => $contents)
115  );
116  error_log($e->getTraceAsString());
117  }
118  }
119 
120  $url = '';
121  $this->getSwordPlugin()->import('classes.DepositPoint');
122  $depositPoints = $this->getData('depositPoint');
123  $depositableDepositPoints = $this->_getDepositableDepositPoints($this->_context);
124  foreach ($depositableDepositPoints as $key => $depositPoint) {
125  if (!isset($depositPoints[$key]['enabled']))
126  continue;
127  if ($depositPoint['type'] == SWORD_DEPOSIT_TYPE_OPTIONAL_SELECTION) {
128  $url = $depositPoints[$key]['depositPoint'];
129  } else { // SWORD_DEPOSIT_TYPE_OPTIONAL_FIXED
130  $url = $depositPoint['url'];
131  }
132  try {
133  $deposit->deposit(
134  $url,
135  $depositPoint['username'],
136  $depositPoint['password'],
137  $depositPoint['apikey']
138  );
139  $params = array(
140  'itemTitle' => $this->_submission->getLocalizedTitle(),
141  'repositoryName' => $depositPoint['name']
142  );
143  $notificationManager->createTrivialNotification(
144  $user->getId(),
145  NOTIFICATION_TYPE_SUCCESS,
146  array('contents' => __('plugins.generic.sword.depositComplete', $params))
147  );
148  }
149  catch(Exception $e) {
150  $contents = __('plugins.importexport.sword.depositFailed') . ': ' . $e->getMessage();
151  $notificationManager->createTrivialNotification(
152  $user->getId(),
153  NOTIFICATION_TYPE_ERROR,
154  array('contents' => $contents)
155  );
156  error_log($e->getTraceAsString());
157  }
158  }
159  $deposit->cleanup();
160  }
161 
167  protected function _getDepositableDepositPoints($context) {
168  $list = array();
169  $this->getSwordPlugin()->import('classes.DepositPoint');
170  $depositPointDao = DAORegistry::getDAO('DepositPointDAO');
171  $this->getSwordPlugin()->import('classes.DepositPointsHelper');
172  $depositPoints = $depositPointDao->getByContextId($context->getId(), null);
173  while ($depositPoint = $depositPoints->next()) {
174  if (!in_array($depositPoint->getType(), array(SWORD_DEPOSIT_TYPE_OPTIONAL_SELECTION, SWORD_DEPOSIT_TYPE_OPTIONAL_FIXED)))
175  continue;
176 
177  $list[$depositPoint->getId()]['name'] = $depositPoint->getLocalizedName();
178  $list[$depositPoint->getId()]['url'] = $depositPoint->getSwordUrl();
179  $list[$depositPoint->getId()]['type'] = $depositPoint->getType();
180  $list[$depositPoint->getId()]['username'] = $depositPoint->getSwordUsername();
181  $list[$depositPoint->getId()]['password'] = $depositPoint->getSwordPassword();
182  $list[$depositPoint->getId()]['apikey'] = $depositPoint->getSwordApikey();
183  if ($depositPoint->getType() == SWORD_DEPOSIT_TYPE_OPTIONAL_SELECTION) {
185  $depositPoint->getSwordUrl(),
186  $depositPoint->getSwordUsername(),
187  $depositPoint->getSwordPassword(),
188  $depositPoint->getSwordApikey()
189  );
190  $list[$depositPoint->getId()]['depositPoints'] = $collections;
191  }
192  }
193  return $list;
194  }
195 }
AuthorDepositForm\readInputData
readInputData()
Definition: AuthorDepositForm.inc.php:60
SwordPlugin
SWORD deposit plugin class.
Definition: SwordPlugin.inc.php:23
AuthorDepositForm\_getDepositableDepositPoints
_getDepositableDepositPoints($context)
Definition: AuthorDepositForm.inc.php:176
AuthorDepositForm\$_plugin
$_plugin
Definition: AuthorDepositForm.inc.php:27
Submission
Article class.
Definition: Submission.inc.php:34
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
AuthorDepositForm\$_context
$_context
Definition: AuthorDepositForm.inc.php:21
AuthorDepositForm\$_submission
$_submission
Definition: AuthorDepositForm.inc.php:33
PKPSwordDeposit
Class providing a SWORD deposit wrapper for submissions.
Definition: PKPSwordDeposit.inc.php:20
AuthorDepositForm\display
display()
Definition: AuthorDepositForm.inc.php:72
Context
Basic class describing a context.
Definition: Context.inc.php:23
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
Form\getData
getData($key)
Definition: Form.inc.php:220
AuthorDepositForm\getSwordPlugin
getSwordPlugin()
Definition: AuthorDepositForm.inc.php:53
AuthorDepositForm\__construct
__construct(SwordPlugin $plugin, Context $context, Submission $submission)
Definition: AuthorDepositForm.inc.php:41
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
DepositPointsHelper\loadCollectionsFromServer
static loadCollectionsFromServer($url, $username, $password, $apikey=null)
Definition: DepositPointsHelper.inc.php:24
Plugin\getTemplateResource
getTemplateResource($template=null, $inCore=false)
Definition: Plugin.inc.php:349
AuthorDepositForm
Form to perform an author's SWORD deposit(s)
Definition: AuthorDepositForm.inc.php:16
NotificationManager
Definition: NotificationManager.inc.php:19
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
PKPApplication\getRequest
getRequest()
Definition: PKPApplication.inc.php:270
PKPLocale\requireComponents
static requireComponents()
Definition: PKPLocale.inc.php:374
AuthorDepositForm\execute
execute($request)
Definition: AuthorDepositForm.inc.php:89