Open Journal Systems  3.3.0
URNSettingsForm.inc.php
1 <?php
2 
17 import('lib.pkp.classes.form.Form');
18 
19 class URNSettingsForm extends Form {
20 
21  //
22  // Private properties
23  //
25  var $_contextId;
26 
31  function _getContextId() {
32  return $this->_contextId;
33  }
34 
36  var $_plugin;
37 
42  function _getPlugin() {
43  return $this->_plugin;
44  }
45 
46  //
47  // Constructor
48  //
54  function __construct($plugin, $contextId) {
55  $this->_contextId = $contextId;
56  $this->_plugin = $plugin;
57 
58  parent::__construct($plugin->getTemplateResource('settingsForm.tpl'));
59 
60  $form = $this;
61  $this->addCheck(new FormValidatorCustom($this, 'urnObjects', 'required', 'plugins.pubIds.urn.manager.settings.urnObjectsRequired', function($enableIssueURN) use ($form) {
62  return $form->getData('enableIssueURN') || $form->getData('enablePublicationURN') || $form->getData('enableRepresentationURN');
63  }));
64  $this->addCheck(new FormValidatorRegExp($this, 'urnPrefix', 'required', 'plugins.pubIds.urn.manager.settings.form.urnPrefixPattern', '/^urn:[a-zA-Z0-9-]*:.*/'));
65  $this->addCheck(new FormValidatorCustom($this, 'urnIssueSuffixPattern', 'required', 'plugins.pubIds.urn.manager.settings.form.urnIssueSuffixPatternRequired', function($urnIssueSuffixPattern) use ($form) {
66  if ($form->getData('urnSuffix') == 'pattern' && $form->getData('enableIssueURN')) return $urnIssueSuffixPattern != '';
67  return true;
68  }));
69  $this->addCheck(new FormValidatorCustom($this, 'urnPublicationSuffixPattern', 'required', 'plugins.pubIds.urn.manager.settings.form.urnPublicationSuffixPatternRequired', function($urnPublicationSuffixPattern) use ($form) {
70  if ($form->getData('urnSuffix') == 'pattern' && $form->getData('enablePublicationURN')) return $urnPublicationSuffixPattern != '';
71  return true;
72  }));
73  $this->addCheck(new FormValidatorCustom($this, 'urnRepresentationSuffixPattern', 'required', 'plugins.pubIds.urn.manager.settings.form.urnRepresentationSuffixPatternRequired', function($urnRepresentationSuffixPattern) use ($form) {
74  if ($form->getData('urnSuffix') == 'pattern' && $form->getData('enableRepresentationURN')) return $urnRepresentationSuffixPattern != '';
75  return true;
76  }));
77  $this->addCheck(new FormValidatorUrl($this, 'urnResolver', 'required', 'plugins.pubIds.urn.manager.settings.form.urnResolverRequired'));
78  $this->addCheck(new FormValidatorPost($this));
79  $this->addCheck(new FormValidatorCSRF($this));
80 
81  // for URN reset requests
82  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
83  $request = Application::get()->getRequest();
84  $this->setData('clearPubIdsLinkAction', new LinkAction(
85  'reassignURNs',
87  $request->getSession(),
88  __('plugins.pubIds.urn.manager.settings.urnReassign.confirm'),
89  __('common.delete'),
90  $request->url(null, null, 'manage', null, array('verb' => 'clearPubIds', 'plugin' => $plugin->getName(), 'category' => 'pubIds')),
91  'modal_delete'
92  ),
93  __('plugins.pubIds.urn.manager.settings.urnReassign'),
94  'delete'
95  ));
96  $this->setData('pluginName', $plugin->getName());
97  }
98 
99 
100  //
101  // Implement template methods from Form
102  //
106  function fetch($request) {
107  $urnNamespaces = array(
108  '' => '',
109  'urn:nbn:de' => 'urn:nbn:de',
110  'urn:nbn:at' => 'urn:nbn:at',
111  'urn:nbn:ch' => 'urn:nbn:ch',
112  'urn:nbn' => 'urn:nbn',
113  'urn' => 'urn'
114  );
115  $templateMgr = TemplateManager::getManager($request);
116  $templateMgr->assign('urnNamespaces', $urnNamespaces);
117  return parent::fetch($request);
118  }
119 
123  function initData() {
124  $contextId = $this->_getContextId();
125  $plugin = $this->_getPlugin();
126  foreach($this->_getFormFields() as $fieldName => $fieldType) {
127  $this->setData($fieldName, $plugin->getSetting($contextId, $fieldName));
128  }
129  }
130 
134  function readInputData() {
135  $this->readUserVars(array_keys($this->_getFormFields()));
136  }
137 
141  function execute(...$functionArgs) {
142  $contextId = $this->_getContextId();
143  $plugin = $this->_getPlugin();
144  foreach($this->_getFormFields() as $fieldName => $fieldType) {
145  $plugin->updateSetting($contextId, $fieldName, $this->getData($fieldName), $fieldType);
146  }
147  parent::execute(...$functionArgs);
148  }
149 
150  //
151  // Private helper methods
152  //
153  function _getFormFields() {
154  return array(
155  'enableIssueURN' => 'bool',
156  'enablePublicationURN' => 'bool',
157  'enableRepresentationURN' => 'bool',
158  'urnPrefix' => 'string',
159  'urnSuffix' => 'string',
160  'urnIssueSuffixPattern' => 'string',
161  'urnPublicationSuffixPattern' => 'string',
162  'urnRepresentationSuffixPattern' => 'string',
163  'urnCheckNo' => 'bool',
164  'urnNamespace' => 'string',
165  'urnResolver' => 'string',
166  );
167  }
168 }
169 
170 
URNSettingsForm\fetch
fetch($request)
Definition: URNSettingsForm.inc.php:112
URNSettingsForm
Form for journal managers to setup URN plugin.
Definition: URNSettingsForm.inc.php:19
RemoteActionConfirmationModal
Class defining a simple confirmation modal with a remote action and ok/cancel buttons.
Definition: RemoteActionConfirmationModal.inc.php:18
URNSettingsForm\$_plugin
$_plugin
Definition: URNSettingsForm.inc.php:42
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
URNSettingsForm\readInputData
readInputData()
Definition: URNSettingsForm.inc.php:140
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
URNSettingsForm\_getContextId
_getContextId()
Definition: URNSettingsForm.inc.php:34
URNSettingsForm\_getPlugin
_getPlugin()
Definition: URNSettingsForm.inc.php:48
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
URNSettingsForm\execute
execute(... $functionArgs)
Definition: URNSettingsForm.inc.php:147
FormValidatorRegExp
Form validation check using a regular expression.
Definition: FormValidatorRegExp.inc.php:18
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
URNSettingsForm\initData
initData()
Definition: URNSettingsForm.inc.php:129
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
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
URNSettingsForm\__construct
__construct($plugin, $contextId)
Definition: URNSettingsForm.inc.php:60
URNSettingsForm\$_contextId
$_contextId
Definition: URNSettingsForm.inc.php:28
URNSettingsForm\_getFormFields
_getFormFields()
Definition: URNSettingsForm.inc.php:159