forked from sedici/badges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BadgesSettingsForm.php
114 lines (98 loc) · 2.74 KB
/
BadgesSettingsForm.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
<?php
/**
* @file plugins/generic/badges/BadgesSettingsForm.inc.php
*
* Copyright 2019
* Portal de Revistas de la Universidad Nacional de La Plata
* https://revistas.unlp.edu.ar
* https://sedici.unlp.edu.ar
*
* @author gonetil *
*
* @class BadgesSettingsForm
*
* @ingroup plugins_generic_badges
*
* @brief Form for journal managers to modify Almetric Badges plugin options
*/
namespace APP\plugins\generic\badges;
use APP\template\TemplateManager;
use PKP\form\Form;
use PKP\form\validation\FormValidatorCSRF;
use PKP\form\validation\FormValidatorPost;
class BadgesSettingsForm extends Form
{
public const CONFIG_VARS = [
'badgesShowDimensions' => 'string',
'badgesShowAltmetric' => 'string',
'badgesShowPlumx' => 'string',
'badgesDimensionsHideWhenEmpty' => 'string',
'badgesAltmetricHideWhenEmpty' => 'string',
'badgesPlumxHideWhenEmpty' => 'string',
'badgesDimensionsStyle' => 'string',
'badgesAltmetricStyle' => 'string'
];
/** @var int */
public $contextId;
/** @var object */
public $plugin;
/**
* Constructor
*
* @param $plugin BadgesPlugin
* @param $contextId int
*/
public function __construct($plugin, $contextId)
{
$this->contextId = $contextId;
$this->plugin = $plugin;
parent::__construct($plugin->getTemplateResource('settingsForm.tpl'));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}
/**
* Initialize form data.
*/
public function initData()
{
$this->_data = [];
foreach (self::CONFIG_VARS as $configVar => $type) {
$this->_data[$configVar] = $this->plugin->getSetting($this->contextId, $configVar);
}
}
/**
* Assign form data to user-submitted data.
*/
public function readInputData()
{
$this->readUserVars(array_keys(self::CONFIG_VARS));
}
/**
* Fetch the form.
*
* @copydoc Form::fetch()
*
* @param null|mixed $template
*/
public function fetch($request, $template = null, $display = false)
{
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->plugin->getName());
return parent::fetch($request);
}
/**
* Save settings.
*/
/**
* @copydoc Form::execute()
*/
public function execute(...$functionArgs)
{
$plugin = &$this->plugin;
$contextId = $this->contextId;
foreach (self::CONFIG_VARS as $configVar => $type) {
$plugin->updateSetting($contextId, $configVar, $this->getData($configVar), $type);
}
parent::execute(...$functionArgs);
}
}