-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArticleNumberSettingsForm.inc.php
More file actions
135 lines (123 loc) · 5.61 KB
/
Copy pathArticleNumberSettingsForm.inc.php
File metadata and controls
135 lines (123 loc) · 5.61 KB
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
<?php
/**
* @file ArticleNumberSettingsForm.inc.php
*
* Article Number Plugin for OJS — per-journal settings form.
*
* Phase 1 persists a single per-journal setting:
* - enableWorkNumber (bool) — master opt-in for the Article Number feature.
* Default OFF. When OFF, the plugin injects nothing and OJS is unchanged.
*/
import('lib.pkp.classes.form.Form');
import('lib.pkp.classes.form.validation.FormValidatorPost');
import('lib.pkp.classes.form.validation.FormValidatorCSRF');
class ArticleNumberSettingsForm extends Form
{
/** @var ArticleNumberPlugin */
private $plugin;
/** @var int */
private $contextId;
public function __construct($plugin, $contextId)
{
parent::__construct($plugin->getTemplateResource('settingsForm.tpl'));
$this->plugin = $plugin;
$this->contextId = (int) $contextId;
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}
public function initData()
{
$this->setData('enableWorkNumber', (bool) $this->plugin->getSetting(
$this->contextId, ArticleNumberPlugin::SETTING_ENABLE
));
// The form shows a "Show …" checkbox; internally we store the inverse
// "hide" flag (truthy = hide). Default = show.
$hide = $this->plugin->getSetting($this->contextId, ArticleNumberPlugin::SETTING_HIDE_DETAILS_BLOCK);
$this->setData('showArticleNumberInDetails', !$hide);
// Same inverted "hide" flag for the issue table-of-contents display.
$hideToc = $this->plugin->getSetting($this->contextId, ArticleNumberPlugin::SETTING_HIDE_IN_TOC);
$this->setData('showArticleNumberInToc', !$hideToc);
$this->setData('workNumberGeneratorEnabled', (bool) $this->plugin->getSetting(
$this->contextId, ArticleNumberPlugin::SETTING_GENERATOR
));
$template = $this->plugin->getSetting($this->contextId, ArticleNumberPlugin::SETTING_TEMPLATE);
$this->setData('workNumberTemplate', ($template === null || $template === '')
? ArticleNumberPlugin::DEFAULT_TEMPLATE : $template);
// Uniqueness scope defaults to whole-journal.
$this->setData('workNumberUniquenessScope', $this->plugin->getUniquenessScope($this->contextId));
// In-panel migration candidate-count cap (overridable; default 2000).
$this->setData('workNumberMigrationThreshold', $this->plugin->getMigrationThreshold($this->contextId));
parent::initData();
}
public function readInputData()
{
$this->readUserVars(array('enableWorkNumber', 'showArticleNumberInDetails', 'showArticleNumberInToc', 'workNumberUniquenessScope', 'workNumberGeneratorEnabled', 'workNumberTemplate', 'workNumberMigrationThreshold'));
// Constrain scope to the allowed set; default to journal-wide.
$scope = $this->getData('workNumberUniquenessScope');
$this->setData('workNumberUniquenessScope', ($scope === 'issue') ? 'issue' : 'journal');
// Keep the migration threshold a sane positive integer; default if blank/invalid.
$threshold = (int) $this->getData('workNumberMigrationThreshold');
$this->setData('workNumberMigrationThreshold', $threshold > 0 ? $threshold : ArticleNumberPlugin::DEFAULT_MIGRATION_THRESHOLD);
// Keep the template a sane, non-empty free-string pattern.
$template = trim((string) $this->getData('workNumberTemplate'));
if ($template === '') {
$template = ArticleNumberPlugin::DEFAULT_TEMPLATE;
}
$this->setData('workNumberTemplate', $template);
parent::readInputData();
}
public function fetch($request, $template = null, $display = false)
{
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->plugin->getName());
return parent::fetch($request, $template, $display);
}
public function execute(...$functionArgs)
{
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_ENABLE,
(bool) $this->getData('enableWorkNumber'),
'bool'
);
// Store the inverse "hide" flag as a truthy int (1 = hide) so it reads
// back reliably; "show" stores 0 (which reads back as null = default show).
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_HIDE_DETAILS_BLOCK,
$this->getData('showArticleNumberInDetails') ? 0 : 1,
'int'
);
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_HIDE_IN_TOC,
$this->getData('showArticleNumberInToc') ? 0 : 1,
'int'
);
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_UNIQUENESS_SCOPE,
(string) $this->getData('workNumberUniquenessScope'),
'string'
);
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_MIGRATION_THRESHOLD,
(int) $this->getData('workNumberMigrationThreshold'),
'int'
);
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_GENERATOR,
(bool) $this->getData('workNumberGeneratorEnabled'),
'bool'
);
$this->plugin->updateSetting(
$this->contextId,
ArticleNumberPlugin::SETTING_TEMPLATE,
(string) $this->getData('workNumberTemplate'),
'string'
);
parent::execute(...$functionArgs);
}
}