Open Monograph Press  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  public 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, 'urnPublicationSuffixPattern', 'required', 'plugins.pubIds.urn.manager.settings.form.urnPublicationSuffixPatternRequired', function($urnPublicationSuffixPattern) use ($form) {
66  if ($form->getData('urnSuffix') == 'pattern' && $form->getData('enablePublicationURN')) return $urnPublicationSuffixPattern != '';
67  return true;
68  }));
69  $this->addCheck(new FormValidatorCustom($this, 'urnChapterSuffixPattern', 'required', 'plugins.pubIds.urn.manager.settings.form.urnChapterSuffixPatternRequired', function($urnChapterSuffixPattern) use ($form) {
70  if ($form->getData('urnSuffix') == 'pattern' && $form->getData('enableChapterURN')) return $urnChapterSuffixPattern != '';
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 FormValidatorCustom($this, 'urnSubmissionFileSuffixPattern', 'required', 'plugins.pubIds.urn.manager.settings.form.urnSubmissionFileSuffixPattern', function($urnSubmissionFileSuffixPattern) use ($form) {
78  if ($form->getData('urnSuffix') == 'pattern' && $form->getData('enableSubmissionFileURN')) return $urnSubmissionFileSuffixPattern != '';
79  return true;
80  }));
81  $this->addCheck(new FormValidatorUrl($this, 'urnResolver', 'required', 'plugins.pubIds.urn.manager.settings.form.urnResolverRequired'));
82  $this->addCheck(new FormValidatorPost($this));
83  $this->addCheck(new FormValidatorCSRF($this));
84 
85  // for URN reset requests
86  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
87  $request = Application::get()->getRequest();
88  $this->setData('clearPubIdsLinkAction', new LinkAction(
89  'reassignURNs',
91  $request->getSession(),
92  __('plugins.pubIds.urn.manager.settings.urnReassign.confirm'),
93  __('common.delete'),
94  $request->url(null, null, 'manage', null, array('verb' => 'clearPubIds', 'plugin' => $plugin->getName(), 'category' => 'pubIds')),
95  'modal_delete'
96  ),
97  __('plugins.pubIds.urn.manager.settings.urnReassign'),
98  'delete'
99  ));
100  $this->setData('pluginName', $plugin->getName());
101  }
102 
103 
104  //
105  // Implement template methods from Form
106  //
110  public function fetch($request, $template = null, $display = false) {
111  $urnNamespaces = array(
112  '' => '',
113  'urn:nbn:de' => 'urn:nbn:de',
114  'urn:nbn:at' => 'urn:nbn:at',
115  'urn:nbn:ch' => 'urn:nbn:ch',
116  'urn:nbn' => 'urn:nbn',
117  'urn' => 'urn'
118  );
119  $templateMgr = TemplateManager::getManager($request);
120  $templateMgr->assign('urnNamespaces', $urnNamespaces);
121  return parent::fetch($request, $template, $display);
122  }
123 
127  public function initData() {
128  $contextId = $this->_getContextId();
129  $plugin = $this->_getPlugin();
130  foreach($this->_getFormFields() as $fieldName => $fieldType) {
131  $this->setData($fieldName, $plugin->getSetting($contextId, $fieldName));
132  }
133  }
134 
138  public function readInputData() {
139  $this->readUserVars(array_keys($this->_getFormFields()));
140  }
141 
145  public function execute(...$functionArgs) {
146  $contextId = $this->_getContextId();
147  $plugin = $this->_getPlugin();
148  foreach($this->_getFormFields() as $fieldName => $fieldType) {
149  $plugin->updateSetting($contextId, $fieldName, $this->getData($fieldName), $fieldType);
150  }
151  parent::execute(...$functionArgs);
152  }
153 
154  //
155  // Private helper methods
156  //
157  public function _getFormFields() {
158  return array(
159  'enablePublicationURN' => 'bool',
160  'enableChapterURN' => 'bool',
161  'enableRepresentationURN' => 'bool',
162  'enableSubmissionFileURN' => 'bool',
163  'urnPrefix' => 'string',
164  'urnSuffix' => 'string',
165  'urnPublicationSuffixPattern' => 'string',
166  'urnChapterSuffixPattern' => 'string',
167  'urnRepresentationSuffixPattern' => 'string',
168  'urnSubmissionFileSuffixPattern' => 'string',
169  'urnCheckNo' => 'bool',
170  'urnNamespace' => 'string',
171  'urnResolver' => 'string',
172  );
173  }
174 }
175 
176 
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:144
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
URNSettingsForm\fetch
fetch($request, $template=null, $display=false)
Definition: URNSettingsForm.inc.php:116
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:151
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:133
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:163