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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
<?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\ViewDataTable;
/**
* Contains base request properties for {@link Piwik\Plugin\ViewDataTable} instances. Manipulating
* these properties will change the way a {@link Piwik\Plugin\ViewDataTable} loads report data.
*
* <a name="client-side-parameters-desc"></a>
* **Client Side Parameters**
*
* Client side parameters are request properties that should be passed on to the browser so
* client side JavaScript can use them. These properties will also be passed to the server with
* every AJAX request made.
*
* Only affects ViewDataTables that output HTML.
*
* <a name="overridable-properties-desc"></a>
* **Overridable Properties**
*
* Overridable properties are properties that can be set via the query string.
* If a request has a query parameter that matches an overridable property, the property
* will be set to the query parameter value.
*
* **Reusing base properties**
*
* Many of the properties in this class only have meaning for the {@link Piwik\Plugin\Visualization}
* class, but can be set for other visualizations that extend {@link Piwik\Plugin\ViewDataTable}
* directly.
*
* Visualizations that extend {@link Piwik\Plugin\ViewDataTable} directly and want to re-use these
* properties must make sure the properties are used in the exact same way they are used in
* {@link Piwik\Plugin\Visualization}.
*
* **Defining new request properties**
*
* If you are creating your own visualization and want to add new request properties for
* it, extend this class and add your properties as fields.
*
* Properties are marked as client side parameters by calling the
* {@link addPropertiesThatShouldBeAvailableClientSide()} method.
*
* Properties are marked as overridable by calling the
* {@link addPropertiesThatCanBeOverwrittenByQueryParams()} method.
*
* ### Example
*
* **Defining new request properties**
*
* class MyCustomVizRequestConfig extends RequestConfig
* {
* /**
* * My custom property. It is overridable.
* *\/
* public $my_custom_property = false;
*
* /**
* * Another custom property. It is available client side.
* *\/
* public $another_custom_property = true;
*
* public function __construct()
* {
* parent::__construct();
*
* $this->addPropertiesThatShouldBeAvailableClientSide(array('another_custom_property'));
* $this->addPropertiesThatCanBeOverwrittenByQueryParams(array('my_custom_property'));
* }
* }
*
* @api
*/
class RequestConfig
{
/**
* The list of request parameters that are 'Client Side Parameters'.
*/
public $clientSideParameters = array(
'filter_excludelowpop',
'filter_excludelowpop_value',
'filter_pattern',
'filter_column',
'filter_offset',
'flat',
'expanded',
'pivotBy',
'pivotByColumn',
'pivotByColumnLimit'
);
/**
* The list of ViewDataTable properties that can be overriden by query parameters.
*/
public $overridableProperties = array(
'filter_sort_column',
'filter_sort_order',
'filter_limit',
'filter_offset',
'filter_pattern',
'filter_column',
'filter_excludelowpop',
'filter_excludelowpop_value',
'disable_generic_filters',
'disable_queued_filters',
'flat',
'expanded',
'pivotBy',
'pivotByColumn',
'pivotByColumnLimit'
);
/**
* Controls which column to sort the DataTable by before truncating and displaying.
*
* Default value: If the report contains nb_uniq_visitors and nb_uniq_visitors is a
* displayed column, then the default value is 'nb_uniq_visitors'.
* Otherwise, it is 'nb_visits'.
*/
public $filter_sort_column = false;
/**
* Controls the sort order. Either 'asc' or 'desc'.
*
* Default value: 'desc'
*/
public $filter_sort_order = 'desc';
/**
* The number of items to truncate the data set to before rendering the DataTable view.
*
* Default value: false
*/
public $filter_limit = false;
/**
* If set to true, the returned data will contain the flattened view of the table data set.
* The children of all first level rows will be aggregated under one row.
*
* Default value: false
*/
public $flat = false;
/**
* If set to true, the returned data will contain the first level results, as well as all sub-tables.
*
* Default value: false
*/
public $expanded = false;
/**
* The number of items from the start of the data set that should be ignored.
*
* Default value: 0
*/
public $filter_offset = 0;
/**
* A regex pattern to use to filter the DataTable before it is shown.
*
* @see also self::FILTER_PATTERN_COLUMN
*
* Default value: false
*/
public $filter_pattern = false;
/**
* The column to apply a filter pattern to.
*
* @see also self::FILTER_PATTERN
*
* Default value: false
*/
public $filter_column = false;
/**
* Stores the column name to filter when filtering out rows with low values.
*
* Default value: false
*/
public $filter_excludelowpop = false;
/**
* Stores the value considered 'low' when filtering out rows w/ low values.
*
* Default value: false
* @var \Closure|string
*/
public $filter_excludelowpop_value = false;
/**
* An array property that contains query parameter name/value overrides for API requests made
* by ViewDataTable.
*
* E.g. array('idSite' => ..., 'period' => 'month')
*
* Default value: array()
*/
public $request_parameters_to_modify = array();
/**
* Whether to run generic filters on the DataTable before rendering or not.
*
* @see Piwik\API\DataTableGenericFilter
*
* Default value: false
*/
public $disable_generic_filters = false;
/**
* Whether to run ViewDataTable's list of queued filters or not.
*
* _NOTE: Priority queued filters are always run._
*
* Default value: false
*/
public $disable_queued_filters = false;
/**
* returns 'Plugin.apiMethodName' used for this ViewDataTable,
* eg. 'Actions.getPageUrls'
*
* @var string
*/
public $apiMethodToRequestDataTable = '';
/**
* If the current dataTable refers to a subDataTable (eg. keywordsBySearchEngineId for id=X) this variable is set to the Id
*
* @var bool|int
*/
public $idSubtable = false;
/**
* Dimension ID to pivot by. See {@link Piwik\DataTable\Filter\PivotByDimension} for more info.
*
* @var string
*/
public $pivotBy = false;
/**
* The column to display in a pivot table, eg, `'nb_visits'`. See {@link Piwik\DataTable\Filter\PivotByDimension}
* for more info.
*
* @var string
*/
public $pivotByColumn = false;
/**
* The maximum number of columns to display in a pivot table. See {@link Piwik\DataTable\Filter\PivotByDimension}
* for more info.
*
* @var int
*/
public $pivotByColumnLimit = false;
public function getProperties()
{
return get_object_vars($this);
}
/**
* Marks request properties as client side properties. [Read this](#client-side-properties-desc)
* to learn more.
*
* @param array $propertyNames List of property names, eg, `array('disable_queued_filters', 'filter_column')`.
*/
public function addPropertiesThatShouldBeAvailableClientSide(array $propertyNames)
{
foreach ($propertyNames as $propertyName) {
$this->clientSideParameters[] = $propertyName;
}
}
/**
* Marks display properties as overridable. [Read this](#overridable-properties-desc) to
* learn more.
*
* @param array $propertyNames List of property names, eg, `array('disable_queued_filters', 'filter_column')`.
*/
public function addPropertiesThatCanBeOverwrittenByQueryParams(array $propertyNames)
{
foreach ($propertyNames as $propertyName) {
$this->overridableProperties[] = $propertyName;
}
}
public function setDefaultSort($columnsToDisplay, $hasNbUniqVisitors, $actualColumns)
{
// default sort order to visits/visitors data
if ($hasNbUniqVisitors && in_array('nb_uniq_visitors', $columnsToDisplay)) {
$this->filter_sort_column = 'nb_uniq_visitors';
} else {
$this->filter_sort_column = 'nb_visits';
}
// if the default sort column does not exist, sort by the first non-label column
if (!in_array($this->filter_sort_column, $actualColumns)) {
foreach ($actualColumns as $column) {
if ($column != 'label') {
$this->filter_sort_column = $column;
break;
}
}
}
$this->filter_sort_order = 'desc';
}
public function getApiModuleToRequest()
{
list($module, $method) = explode('.', $this->apiMethodToRequestDataTable);
return $module;
}
public function getApiMethodToRequest()
{
list($module, $method) = explode('.', $this->apiMethodToRequestDataTable);
return $method;
}
}
|