forked from pkp/crossrefReferenceLinking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossrefReferenceLinkingSettingsForm.inc.php
167 lines (152 loc) · 4.43 KB
/
CrossrefReferenceLinkingSettingsForm.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* @file CrossrefReferenceLinkingSettingsForm.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class CrossrefReferenceLinkingSettingsForm
* @ingroup plugins_generic_crossrefReferenceLinking
*
* @brief Form for journal managers to setup the reference linking plugin
*/
import('lib.pkp.classes.form.Form');
class CrossrefReferenceLinkingSettingsForm extends Form {
//
// Private properties
//
/** @var integer */
var $_contextId;
/** @var CrossrefReferenceLinkingPlugin */
var $_plugin;
//
// Constructor
//
/**
* Constructor
* @param $plugin CrossrefReferenceLinkingPlugin
* @param $contextId integer
*/
function __construct($plugin, $contextId) {
$this->_contextId = $contextId;
$this->_plugin = $plugin;
parent::__construct($plugin->getTemplateResource('settingsForm.tpl'));
// Add form validation checks.
$this->addCheck(new FormValidator($this, 'username', 'required', 'plugins.generic.crossrefReferenceLinking.settings.form.usernameRequired'));
$this->addCheck(new FormValidator($this, 'password', 'required', 'plugins.generic.crossrefReferenceLinking.settings.form.passwordRequired'));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}
//
// Public methods
//
/**
* Get the context ID.
* @return integer
*/
function _getContextId() {
return $this->_contextId;
}
/**
* Get the plugin.
* @return CrossrefReferenceLinkingPlugin
*/
function _getPlugin() {
return $this->_plugin;
}
//
// Implement template methods from Form
//
/**
* @copydoc Form::initData()
*/
function initData() {
$contextId = $this->_getContextId();
$plugin = $this->_getPlugin();
foreach($this->getFormFields() as $fieldName => $fieldType) {
$this->setData($fieldName, $plugin->getSetting($contextId, $fieldName));
}
}
/**
* @copydoc Form::readInputData()
*/
function readInputData() {
$this->readUserVars(array_keys($this->getFormFields()));
}
/**
* @copydoc Form::fetch()
*/
function fetch($request, $template = NULL, $display = false) {
$plugin = $this->_getPlugin();
$contextId = $request->getContext()->getId();
$dispatcher = $request->getDispatcher();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $plugin->getName());
if (!$plugin->crossrefCredentials($contextId)) {
// Crossref export/registration plugin action link
import('lib.pkp.classes.linkAction.request.RedirectAction');
$crossrefSettingsLinkAction = new LinkAction(
'settings',
new RedirectAction($dispatcher->url(
$request, ROUTE_PAGE,
null, 'management', 'importexport',
array('plugin', 'CrossRefExportPlugin')
)),
__('plugins.generic.crossrefReferenceLinking.settings.form.crossrefSettings'),
null
);
$templateMgr->assign('crossrefSettingsLinkAction', $crossrefSettingsLinkAction);
}
if (!$plugin->citationsEnabled($contextId)) {
// Settings > Workflow > Submission action link
import('lib.pkp.classes.linkAction.request.RedirectAction');
$submissionSettingsLinkAction = new LinkAction(
'settings',
new RedirectAction($dispatcher->url(
$request, ROUTE_PAGE,
null, 'management', 'settings', 'workflow',
array('uid' => uniqid()), // Force reload
'submission/metadata' // Anchor for tab
)),
__('plugins.generic.crossrefReferenceLinking.settings.form.submissionSettings'),
null
);
$templateMgr->assign('submissionSettingsLinkAction', $submissionSettingsLinkAction);
}
return parent::fetch($request);
}
/**
* @copydoc Form::execute()
*/
function execute(...$functionArgs) {
$plugin = $this->_getPlugin();
$contextId = $this->_getContextId();
foreach($this->getFormFields() as $fieldName => $fieldType) {
$plugin->updateSetting($contextId, $fieldName, $this->getData($fieldName), $fieldType);
}
}
//
// Public helper methods
//
/**
* Get form fields
* @return array (field name => field type)
*/
function getFormFields() {
return array(
'username' => 'string',
'password' => 'string',
'automaticRegistration' => 'bool',
'testMode' => 'bool'
);
}
/**
* Is the form field optional
* @param $settingName string
* @return boolean
*/
function isOptional($settingName) {
return in_array($settingName, array('automaticRegistration', 'testMode'));
}
}