forked from ictineo/ojs-cookiesAlert
/
CookiesAlertPluginSettingsForm.inc.php
executable file
·100 lines (86 loc) · 3.32 KB
/
CookiesAlertPluginSettingsForm.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
<?php
/**
* @file CookiesAlertPluginSettingsForm.inc.php
*
* Copyright (c) 2014 UOC, Universitat Oberta de Catalunya
* Developed by Julià Mestieri (Journal Services -- http://journal-services.com)
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class CookiesPlugin
* @ingroup plugins_generic_cookies
*
* @brief Cookies Alert form for journal managers to configure the cookies alert
*/
import('lib.pkp.classes.form.Form');
class CookiesAlertSettingsForm extends Form {
/** @var $journalId int */
var $journalId;
/** @var $plugin object */
var $plugin;
/**
* Constructor
* @param $plugin object
* @param $journalId int
*/
function CookiesAlertSettingsForm(&$plugin, $journalId) {
$this->journalId = $journalId;
$this->plugin =& $plugin;
parent::Form($plugin->getTemplatePath() . 'settingsForm.tpl');
}
/**
* Initialize form data.
*/
function initData() {
$journalId = $this->journalId;
$plugin =& $this->plugin;
$site =& Request::getSite();
$locales = $site->getSupportedLocales();
// all aviable locales
$this->_data = array(
'locales' => $locales
);
// array to store button and text for each locale
$this->_data['cookiesAlertText'] = array();
$this->_data['cookiesAlertButton'] = array();
// values for each locale
foreach($locales as $index => $locale) {
$this->_data['cookiesAlertText'] += array($locale => $plugin->getSetting($journalId, 'cookiesAlertText' . $locale));
$this->_data['cookiesAlertButton'] += array($locale => $plugin->getSetting($journalId, 'cookiesAlertButton' . $locale));
}
// some style options for every locale
$this->_data['cookiesAlertStyleBd'] = $plugin->getSetting($journalId, 'cookiesAlertStyleBd');
$this->_data['cookiesAlertStyleBgwrapper'] = $plugin->getSetting($journalId, 'cookiesAlertStyleBgwrapper');
$this->_data['cookiesAlertStyleBgbutton'] = $plugin->getSetting($journalId, 'cookiesAlertStyleBgbutton');
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$site =& Request::getSite();
$locales = $site->getSupportedLocales();
foreach($locales as $index => $locale) {
$this->readUserVars(array('cookiesAlertButton'.$locale));
$this->readUserVars(array('cookiesAlertText'.$locale));
}
$this->readUserVars(array('cookiesAlertStyleBd'));
$this->readUserVars(array('cookiesAlertStyleBgbutton'));
$this->readUserVars(array('cookiesAlertStyleBgwrapper'));
}
/**
* Save settings.
*/
function execute() {
$plugin =& $this->plugin;
$journalId = $this->journalId;
$site =& Request::getSite();
$locales = $site->getSupportedLocales();
foreach($locales as $index => $locale) {
$plugin->updateSetting($journalId, 'cookiesAlertText'.$locale, $this->getData('cookiesAlertText'.$locale), 'string');
$plugin->updateSetting($journalId, 'cookiesAlertButton'.$locale, $this->getData('cookiesAlertButton'.$locale), 'string');
}
$plugin->updateSetting($journalId, 'cookiesAlertStyleBd', $this->getData('cookiesAlertStyleBd'), 'string');
$plugin->updateSetting($journalId, 'cookiesAlertStyleBgwrapper', $this->getData('cookiesAlertStyleBgwrapper'), 'string');
$plugin->updateSetting($journalId, 'cookiesAlertStyleBgbutton', $this->getData('cookiesAlertStyleBgbutton'), 'string');
}
}
?>