-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSystemSettings.php
176 lines (154 loc) · 6.03 KB
/
SystemSettings.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\AdminNotification;
use Piwik\Piwik;
use Piwik\Notification;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
/**
* Defines Settings for AdminNotification.
*
* Usage like this:
* $settings = new SystemSettings();
* $settings->metric->getValue();
* $settings->description->getValue();
*/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @var Setting */
public $enabled;
/** @var Setting */
public $context;
/** @var Setting */
public $messageTitle;
/** @var Setting */
public $message;
/** @var Setting */
public $type;
/** @var Setting */
public $priority;
protected function init()
{
$this->enabled = $this->createEnabledSetting();
$this->messageTitle = $this->createTitleSetting();
$this->message = $this->createMessageSetting();
$this->context = $this->createContextSetting();
$this->type = $this->createTypeSetting();
$this->priority = $this->createPrioritySetting();
}
private function createEnabledSetting()
{
return $this->makeSetting(
'enabled',
$default = false,
FieldConfig::TYPE_BOOL,
function (FieldConfig $field) {
$field->title = $this->t('EnabledSettingTitle');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = $this->t('EnabledSettingDescription');
}
);
}
private function createTitleSetting()
{
return $this->makeSetting(
'title',
$default = "Message from Matomo Administrator",
FieldConfig::TYPE_STRING,
function (FieldConfig $field) {
$field->title = $this->t('TitleSettingTitle');
$field->condition = 'enabled';
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
$field->description = $this->t('TitleSettingDescription');
$field->validate = function ($value) {
$value = trim($value);
if (strlen($value) == 0) {
throw new \Exception($this->t('TitleMissing'));
}
};
}
);
}
private function createMessageSetting()
{
return $this->makeSetting(
'message',
$default = "",
FieldConfig::TYPE_STRING,
function (FieldConfig $field) {
$field->title = $this->t('MessageSettingTitle');
$field->condition = 'enabled';
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
$field->description = $this->t('MessageSettingDescription');
$field->inlineHelp = $this->t('MessageSettingHelp');
$field->validate = function ($value) {
$value = trim($value);
if (strlen($value) == 0) {
throw new \Exception($this->t('MessageMissing'));
}
};
});
}
private function createContextSetting()
{
return $this->makeSetting(
'context',
$default = Notification::CONTEXT_INFO,
FieldConfig::TYPE_STRING,
function (FieldConfig $field) {
$field->title = $this->t('ContextSettingTitle');
$field->condition = 'enabled';
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
$field->description = $this->t('ContextSettingDescription');
$field->availableValues = array(Notification::CONTEXT_INFO => Notification::CONTEXT_INFO,
Notification::CONTEXT_ERROR => Notification::CONTEXT_ERROR,
Notification::CONTEXT_SUCCESS => Notification::CONTEXT_SUCCESS,
Notification::CONTEXT_WARNING => Notification::CONTEXT_WARNING);
}
);
}
private function createTypeSetting()
{
return $this->makeSetting(
'type',
$default = Notification::TYPE_PERSISTENT,
FieldConfig::TYPE_STRING,
function (FieldConfig $field) {
$field->title = $this->t('TypeSettingTitle');
$field->condition = 'enabled';
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
$field->description = $this->t('TypeSettingDescription');
$field->availableValues = array(Notification::TYPE_PERSISTENT => Notification::TYPE_PERSISTENT,
Notification::TYPE_TRANSIENT => Notification::TYPE_TRANSIENT,
Notification::TYPE_TOAST => Notification::TYPE_TOAST);
}
);
}
private function createPrioritySetting()
{
return $this->makeSetting(
'priority',
$default = Notification::PRIORITY_MAX,
FieldConfig::TYPE_FLOAT,
function (FieldConfig $field) {
$field->title = $this->t('PrioritySettingTitle');
$field->condition = 'enabled';
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
$field->description = $this->t('PrioritySettingDescription');
$field->availableValues = array(Notification::PRIORITY_MIN => Notification::PRIORITY_MIN,
Notification::PRIORITY_LOW => Notification::PRIORITY_LOW,
Notification::PRIORITY_HIGH => Notification::PRIORITY_HIGH,
Notification::PRIORITY_MAX => Notification::PRIORITY_MAX);
}
);
}
private function t($translate_token)
{
return Piwik::translate("AdminNotification_" . $translate_token);
}
}