Open Journal Systems  3.3.0
SwordDepositPointForm.inc.php
1 <?php
2 
14 import('lib.pkp.classes.form.Form');
15 
16 class SwordDepositPointForm extends Form {
18  protected $_contextId;
19 
21  protected $_depositPointId;
22 
24  protected $_plugin;
25 
27  protected $selectedType = null;
28 
35  public function __construct(SwordPlugin $swordPlugin, $contextId, $depositPointId = null) {
36  parent::__construct($swordPlugin->getTemplateResource('editDepositPointForm.tpl'));
37  $this->_contextId = $contextId;
38  $this->_depositPointId = $depositPointId;
39  $this->_plugin = $swordPlugin;
40 
41  // Add form checks
42  $this->addCheck(new FormValidatorPost($this));
43  $this->addCheck(new FormValidatorCSRF($this));
44  $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'plugins.generic.sword.depositPoints.required.field'));
45  $this->addCheck(new FormValidatorCustom($this, 'swordApikey', 'required_if', 'plugins.generic.sword.depositPoints.required.field', function($apiKey) {
46  if (empty($apiKey) and (empty($this->getData('swordUsername')) or empty($this->getData('swordPassword')))) {
47  return false;
48  }
49  return true;
50  }
51  ));
52  $this->addCheck(new FormValidator($this, 'depositPointType', 'required', 'plugins.generic.sword.depositPoints.required.field'));
53  $this->addCheck(new FormValidatorUrl($this, 'swordUrl', 'required', 'plugins.generic.sword.depositPoints.required.field'));
54  }
55 
59  public function initData() {
60  if ($this->_depositPointId) {
61  $depositPointDao = DAORegistry::getDAO('DepositPointDAO');
62  $depositPoint = $depositPointDao->getById($this->_depositPointId, $this->_contextId);
63  $this->setData('swordUrl', $depositPoint->getSwordUrl());
64  $this->setData('name', $depositPoint->getName(null));
65  $this->selectedType = $depositPoint->getType();
66  $this->setData('type', $this->selectedType);
67  $this->setData('swordUsername', $depositPoint->getSwordUsername());
68  $this->setData('swordPassword', SWORD_PASSWORD_SLUG);
69  $this->setData('swordApikey', $depositPoint->getSwordApikey());
70  }
71  }
72 
77  public function readInputData($request) {
78  $this->readUserVars(
79  array(
80  'swordUrl',
81  'swordUsername',
82  'swordPassword',
83  'swordApikey',
84  'depositPointType'
85  )
86  );
87  $this->setData('name', $request->getUserVar('name'));
88  }
89 
93  public function fetch($request) {
94  $templateMgr = TemplateManager::getManager($request);
95  $templateMgr->assign(array(
96  'depositPointId' => $this->_depositPointId,
97  'depositPointTypes' => $this->_plugin->getTypeMap(),
98  'selectedType' => $this->selectedType,
99  'pluginJavaScriptURL' => $this->_plugin->getJsUrl($request),
100  ));
101  return parent::fetch($request);
102  }
103 
107  public function execute() {
108  $plugin = $this->_plugin;
109 
110  $depositPointDao = DAORegistry::getDAO('DepositPointDAO');
111  $plugin->import('classes.DepositPoint');
112 
113  $depositPoint = null;
114  if (isset($this->_depositPointId)) {
115  $depositPoint = $depositPointDao->getById($this->_depositPointId, $this->_contextId);
116  }
117  if (is_null($depositPoint)) {
118  $depositPoint = new DepositPoint();
119  }
120 
121  $depositPoint->setContextId($this->_contextId);
122  $depositPoint->setName($this->getData('name'));
123  $depositPoint->setType($this->getData('depositPointType'));
124  $depositPoint->setSwordUrl($this->getData('swordUrl'));
125  $depositPoint->setSwordUsername($this->getData('swordUsername'));
126  $depositPoint->setSwordApikey($this->getData('swordApikey'));
127  $swordPassword = $this->getData('swordPassword');
128  if (($swordPassword == SWORD_PASSWORD_SLUG) && !empty($depositPoint->getId())) {
129  $depositPoint->setSwordPassword($depositPoint->getSwordPassword());
130  }
131  else {
132  $depositPoint->setSwordPassword($swordPassword);
133  }
134  // Update or insert deposit point
135  if ($depositPoint->getId() != null) {
136  $depositPointDao->updateObject($depositPoint);
137  } else {
138  $depositPoint->setSequence(REALLY_BIG_NUMBER);
139  $depositPointDao->insertObject($depositPoint);
140  $depositPointDao->resequenceDepositPoints($depositPoint->getContextId());
141  }
142  }
143 }
SwordDepositPointForm\$_plugin
$_plugin
Definition: SwordDepositPointForm.inc.php:33
SwordPlugin
SWORD deposit plugin class.
Definition: SwordPlugin.inc.php:23
SwordDepositPointForm\execute
execute()
Definition: SwordDepositPointForm.inc.php:119
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
DepositPoint
Deposit point entity.
Definition: DepositPoint.inc.php:14
FormValidatorLocale
Class to represent a form validation check for localized fields.
Definition: FormValidatorLocale.inc.php:16
Form\setData
setData($key, $value=null)
Definition: Form.inc.php:229
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
Form\getData
getData($key)
Definition: Form.inc.php:220
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
Form\readInputData
readInputData()
Definition: Form.inc.php:253
SwordDepositPointForm\$selectedType
$selectedType
Definition: SwordDepositPointForm.inc.php:39
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
SwordDepositPointForm
Form to create and modify deposit points.
Definition: SwordDepositPointForm.inc.php:16
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
SwordDepositPointForm\fetch
fetch($request)
Definition: SwordDepositPointForm.inc.php:105
Plugin\getTemplateResource
getTemplateResource($template=null, $inCore=false)
Definition: Plugin.inc.php:349
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
FormValidatorCSRF
Form validation check to make sure the CSRF token is correct.
Definition: FormValidatorCSRF.inc.php:18
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
SwordDepositPointForm\$_depositPointId
$_depositPointId
Definition: SwordDepositPointForm.inc.php:27
FormValidatorUrl
Form validation check for URLs.
Definition: FormValidatorUrl.inc.php:20
FormValidatorCustom
Form validation check with a custom user function performing the validation check.
Definition: FormValidatorCustom.inc.php:18
SwordDepositPointForm\readInputData
readInputData($request)
Definition: SwordDepositPointForm.inc.php:89
SwordDepositPointForm\initData
initData()
Definition: SwordDepositPointForm.inc.php:71
SwordDepositPointForm\__construct
__construct(SwordPlugin $swordPlugin, $contextId, $depositPointId=null)
Definition: SwordDepositPointForm.inc.php:47
SwordDepositPointForm\$_contextId
$_contextId
Definition: SwordDepositPointForm.inc.php:21