20
20
21
21
class MeasurableSettings extends BaseMeasurableSettings
22
22
{
23
+ /** @var Setting */
24
+ public $ isEnabled ;
25
+
26
+ /** @var Setting */
27
+ public $ runCount ;
28
+
23
29
/** @var Setting */
24
30
public $ emulatedDevice ;
25
31
@@ -35,9 +41,6 @@ class MeasurableSettings extends BaseMeasurableSettings
35
41
/** @var Setting */
36
42
public $ extraHttpHeaderValue ;
37
43
38
- /** @var Setting */
39
- public $ runCount ;
40
-
41
44
/**
42
45
* Initialise plugin settings.
43
46
*
@@ -48,6 +51,7 @@ protected function init()
48
51
{
49
52
Piwik::checkUserHasSomeViewAccess ();
50
53
54
+ $ this ->isEnabled = $ this ->makeIsEnabledSetting ();
51
55
$ this ->runCount = $ this ->makeRunCountSetting ();
52
56
$ this ->emulatedDevice = $ this ->makeEmulatedDeviceSetting ();
53
57
$ this ->hasGroupedUrls = $ this ->makeHasGroupedUrlsSetting ();
@@ -56,6 +60,21 @@ protected function init()
56
60
$ this ->extraHttpHeaderValue = $ this ->makeExtraHttpHeaderValueSetting ();
57
61
}
58
62
63
+ /**
64
+ * Create is enabled setting.
65
+ *
66
+ * @return MeasurableSetting
67
+ * @throws ValidatorException|Exception
68
+ */
69
+ private function makeIsEnabledSetting ()
70
+ {
71
+ return $ this ->makeSetting ('is_enabled ' , true , FieldConfig::TYPE_BOOL , function (FieldConfig $ field ) {
72
+ $ field ->title = Piwik::translate ('PerformanceAudit_Settings_IsEnabled_Title ' );
73
+ $ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_IsEnabled_Help ' );
74
+ $ field ->uiControl = FieldConfig::UI_CONTROL_CHECKBOX ;
75
+ });
76
+ }
77
+
59
78
/**
60
79
* Create run count setting.
61
80
*
@@ -67,6 +86,7 @@ private function makeRunCountSetting()
67
86
return $ this ->makeSetting ('run_count ' , 3 , FieldConfig::TYPE_INT , function (FieldConfig $ field ) {
68
87
$ field ->title = Piwik::translate ('PerformanceAudit_Settings_RunCount_Title ' );
69
88
$ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_RunCount_Help ' );
89
+ $ field ->condition = 'is_enabled ' ;
70
90
$ field ->uiControl = FieldConfig::UI_CONTROL_TEXT ;
71
91
$ field ->validate = function ($ value ) {
72
92
if (empty ($ value ) && $ value != 0 ) {
@@ -90,6 +110,7 @@ private function makeEmulatedDeviceSetting()
90
110
return $ this ->makeSetting ('emulated_device ' , EmulatedDevice::__default, FieldConfig::TYPE_STRING , function (FieldConfig $ field ) {
91
111
$ field ->title = Piwik::translate ('PerformanceAudit_Settings_EmulatedDevice_Title ' );
92
112
$ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_EmulatedDevice_Help ' );
113
+ $ field ->condition = 'is_enabled ' ;
93
114
$ field ->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT ;
94
115
$ field ->availableValues = [
95
116
EmulatedDevice::Desktop => ucfirst (Piwik::translate ('PerformanceAudit_EnvironmentDesktop ' )),
@@ -118,6 +139,7 @@ private function makeHasGroupedUrlsSetting()
118
139
return $ this ->makeSetting ('has_grouped_urls ' , false , FieldConfig::TYPE_BOOL , function (FieldConfig $ field ) {
119
140
$ field ->title = Piwik::translate ('PerformanceAudit_Settings_HasGroupedUrls_Title ' );
120
141
$ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_HasGroupedUrls_Help ' );
142
+ $ field ->condition = 'is_enabled ' ;
121
143
$ field ->uiControl = FieldConfig::UI_CONTROL_CHECKBOX ;
122
144
});
123
145
}
@@ -133,6 +155,7 @@ private function makeHasExtraHttpHeaderSetting()
133
155
return $ this ->makeSetting ('has_extra_http_header ' , false , FieldConfig::TYPE_BOOL , function (FieldConfig $ field ) {
134
156
$ field ->title = Piwik::translate ('PerformanceAudit_Settings_HasExtraHttpHeader_Title ' );
135
157
$ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_HasExtraHttpHeader_Help ' );
158
+ $ field ->condition = 'is_enabled ' ;
136
159
$ field ->uiControl = FieldConfig::UI_CONTROL_CHECKBOX ;
137
160
});
138
161
}
@@ -150,14 +173,14 @@ private function makeExtraHttpHeaderKeySetting()
150
173
return $ this ->makeSetting ('extra_http_header_key ' , '' , FieldConfig::TYPE_STRING , function (FieldConfig $ field ) use ($ self ) {
151
174
$ field ->title = Piwik::translate ('PerformanceAudit_Settings_ExtraHttpHeaderKey_Title ' );
152
175
$ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_ExtraHttpHeaderKey_Help ' );
153
- $ field ->condition = 'has_extra_http_header ' ;
176
+ $ field ->condition = 'is_enabled && has_extra_http_header ' ;
154
177
$ field ->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT ;
155
178
$ field ->availableValues = [
156
179
'Authorization ' => Piwik::translate ('PerformanceAudit_Settings_ExtraHttpHeaderKey_Authorization ' ),
157
180
'Cookie ' => Piwik::translate ('PerformanceAudit_Settings_ExtraHttpHeaderKey_Cookie ' ),
158
181
];
159
182
$ field ->validate = function ($ value ) use ($ self , $ field ) {
160
- if ($ self ->getSetting ($ field -> condition )->getValue ()) {
183
+ if ($ self ->getSetting (' has_extra_http_header ' )->getValue ()) {
161
184
if (empty ($ value )) {
162
185
throw new ValidatorException (Piwik::translate ('General_ValidatorErrorEmptyValue ' ));
163
186
}
@@ -182,10 +205,10 @@ private function makeExtraHttpHeaderValueSetting()
182
205
return $ this ->makeSetting ('extra_http_header_value ' , '' , FieldConfig::TYPE_STRING , function (FieldConfig $ field ) use ($ self ) {
183
206
$ field ->title = Piwik::translate ('PerformanceAudit_Settings_ExtraHttpHeaderValue_Title ' );
184
207
$ field ->inlineHelp = Piwik::translate ('PerformanceAudit_Settings_ExtraHttpHeaderValue_Help ' );
185
- $ field ->condition = 'has_extra_http_header ' ;
208
+ $ field ->condition = 'is_enabled && has_extra_http_header ' ;
186
209
$ field ->uiControl = FieldConfig::UI_CONTROL_TEXT ;
187
210
$ field ->validate = function ($ value ) use ($ self , $ field ) {
188
- if ($ self ->getSetting ($ field -> condition )->getValue ()) {
211
+ if ($ self ->getSetting (' has_extra_http_header ' )->getValue ()) {
189
212
if (empty ($ value )) {
190
213
throw new ValidatorException (Piwik::translate ('General_ValidatorErrorEmptyValue ' ));
191
214
}
@@ -217,6 +240,16 @@ public function getEmulatedDevicesList()
217
240
return EmulatedDevice::getList ($ this ->getSetting ('emulated_device ' )->getValue ());
218
241
}
219
242
243
+ /**
244
+ * Returns if site has audits enabled or not.
245
+ *
246
+ * @return bool
247
+ */
248
+ public function isAuditEnabled ()
249
+ {
250
+ return $ this ->getSetting ('is_enabled ' )->getValue ();
251
+ }
252
+
220
253
/**
221
254
* Returns if site has grouped URLs for site.
222
255
*
0 commit comments