14 import(
'lib.pkp.classes.form.Form');
37 $this->_contextId = $contextId;
38 $this->_depositPointId = $depositPointId;
39 $this->_plugin = $swordPlugin;
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')))) {
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'));
60 if ($this->_depositPointId) {
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());
87 $this->
setData(
'name', $request->getUserVar(
'name'));
93 public function fetch($request) {
95 $templateMgr->assign(array(
96 'depositPointId' => $this->_depositPointId,
97 'depositPointTypes' => $this->_plugin->getTypeMap(),
98 'selectedType' => $this->selectedType,
99 'pluginJavaScriptURL' => $this->_plugin->getJsUrl($request),
101 return parent::fetch($request);
111 $plugin->import(
'classes.DepositPoint');
113 $depositPoint =
null;
114 if (isset($this->_depositPointId)) {
115 $depositPoint = $depositPointDao->getById($this->_depositPointId, $this->_contextId);
117 if (is_null($depositPoint)) {
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());
132 $depositPoint->setSwordPassword($swordPassword);
135 if ($depositPoint->getId() !=
null) {
136 $depositPointDao->updateObject($depositPoint);
138 $depositPoint->setSequence(REALLY_BIG_NUMBER);
139 $depositPointDao->insertObject($depositPoint);
140 $depositPointDao->resequenceDepositPoints($depositPoint->getContextId());