PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / ViewDataTable / Config.php
matomo / app / core / ViewDataTable Last commit date
Config.php 2 weeks ago Factory.php 1 year ago Manager.php 3 months ago Request.php 6 months ago RequestConfig.php 2 weeks ago
Config.php
775 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\ViewDataTable;
10
11 use Piwik\API\Request as ApiRequest;
12 use Piwik\Common;
13 use Piwik\Container\StaticContainer;
14 use Piwik\DataTable;
15 use Piwik\DataTable\Filter\PivotByDimension;
16 use Piwik\Metrics;
17 use Piwik\Period\PeriodValidator;
18 use Piwik\Piwik;
19 use Piwik\Plugins\API\API;
20 use Piwik\Plugin\ReportsProvider;
21 use Piwik\Request;
22 /**
23 * Contains base display properties for {@link Piwik\Plugin\ViewDataTable}s. Manipulating these
24 * properties in a ViewDataTable instance will change how its report will be displayed.
25 *
26 * <a name="client-side-properties-desc"></a>
27 * **Client Side Properties**
28 *
29 * Client side properties are properties that should be passed on to the browser so
30 * client side JavaScript can use them. Only affects ViewDataTables that output HTML.
31 *
32 * <a name="overridable-properties-desc"></a>
33 * **Overridable Properties**
34 *
35 * Overridable properties are properties that can be set via the query string.
36 * If a request has a query parameter that matches an overridable property, the property
37 * will be set to the query parameter value.
38 *
39 * **Reusing base properties**
40 *
41 * Many of the properties in this class only have meaning for the {@link Piwik\Plugin\Visualization}
42 * class, but can be set for other visualizations that extend {@link Piwik\Plugin\ViewDataTable}
43 * directly.
44 *
45 * Visualizations that extend {@link Piwik\Plugin\ViewDataTable} directly and want to re-use these
46 * properties must make sure the properties are used in the exact same way they are used in
47 * {@link Piwik\Plugin\Visualization}.
48 *
49 * **Defining new display properties**
50 *
51 * If you are creating your own visualization and want to add new display properties for
52 * it, extend this class and add your properties as fields.
53 *
54 * Properties are marked as client side properties by calling the
55 * {@link addPropertiesThatShouldBeAvailableClientSide()} method.
56 *
57 * Properties are marked as overridable by calling the
58 * {@link addPropertiesThatCanBeOverwrittenByQueryParams()} method.
59 *
60 * ### Example
61 *
62 * **Defining new display properties**
63 *
64 * class MyCustomVizConfig extends Config
65 * {
66 * /**
67 * * My custom property. It is overridable.
68 * *\/
69 * public $my_custom_property = false;
70 *
71 * /**
72 * * Another custom property. It is available client side.
73 * *\/
74 * public $another_custom_property = true;
75 *
76 * public function __construct()
77 * {
78 * parent::__construct();
79 *
80 * $this->addPropertiesThatShouldBeAvailableClientSide(array('another_custom_property'));
81 * $this->addPropertiesThatCanBeOverwrittenByQueryParams(array('my_custom_property'));
82 * }
83 * }
84 *
85 * @api
86 */
87 class Config
88 {
89 /**
90 * The list of ViewDataTable properties that are 'Client Side Properties'.
91 */
92 public $clientSideProperties = array('show_limit_control', 'pivot_by_dimension', 'pivot_by_column', 'pivot_dimension_name', 'disable_all_rows_filter_limit', 'segmented_visitor_log_segment_suffix');
93 /**
94 * The list of ViewDataTable properties that can be overridden by query parameters.
95 */
96 public $overridableProperties = array('show_goals', 'show_exclude_low_population', 'show_flatten_table', 'show_pivot_by_subtable', 'show_table', 'show_table_all_columns', 'show_table_performance', 'show_footer', 'show_footer_icons', 'show_all_views_icons', 'show_related_reports', 'show_limit_control', 'show_search', 'show_export', 'enable_sort', 'show_bar_chart', 'show_pie_chart', 'show_tag_cloud', 'show_export_as_rss_feed', 'show_ecommerce', 'search_recursive', 'show_export_as_image_icon', 'show_pagination_control', 'show_offset_information', 'hide_annotations_view', 'columns_to_display', 'rows_to_display', 'segmented_visitor_log_segment_suffix');
97 /**
98 * Controls what footer icons are displayed on the bottom left of the DataTable view.
99 * The value of this property must be an array of footer icon groups. Footer icon groups
100 * have set of properties, including an array of arrays describing footer icons. For
101 * example:
102 *
103 * array(
104 * array( // footer icon group 1
105 * 'class' => 'footerIconGroup1CssClass',
106 * 'buttons' => array(
107 * 'id' => 'myid',
108 * 'title' => 'My Tooltip',
109 * 'icon' => 'path/to/my/icon.png'
110 * )
111 * ),
112 * array( // footer icon group 2
113 * 'class' => 'footerIconGroup2CssClass',
114 * 'buttons' => array(...)
115 * )
116 * )
117 *
118 * By default, when a user clicks on a footer icon, Piwik will assume the 'id' is
119 * a viewDataTable ID and try to reload the DataTable w/ the new viewDataTable. You
120 * can provide your own footer icon behavior by adding an appropriate handler via
121 * DataTable.registerFooterIconHandler in your JavaScript code.
122 *
123 * The default value of this property is not set here and will show the 'Normal Table'
124 * icon, the 'All Columns' icon, the 'Goals Columns' icon and all jqPlot graph columns,
125 * unless other properties tell the view to exclude them.
126 */
127 public $footer_icons = \false;
128 /**
129 * Controls whether the buttons and UI controls around the visualization or shown or
130 * if just the visualization alone is shown.
131 */
132 public $show_visualization_only = \false;
133 /**
134 * Controls whether the goals footer icon is shown.
135 */
136 public $show_goals = \false;
137 /**
138 * Controls whether the 'insights' footer icon is shown.
139 */
140 public $show_insights = \true;
141 /**
142 * Array property mapping DataTable column names with their internationalized names.
143 *
144 * The default value for this property is set elsewhere. It will contain translations
145 * of common metrics.
146 */
147 public $translations = array();
148 /**
149 * Controls whether the 'Exclude Low Population' option (visible in the popup that displays after
150 * clicking the 'cog' icon) is shown.
151 */
152 public $show_exclude_low_population = \true;
153 /**
154 * Whether to show the 'Flatten' option (visible in the popup that displays after clicking the
155 * 'cog' icon).
156 */
157 public $show_flatten_table = \true;
158 /**
159 * Whether the underlying report supports flattening, independent of whether the flatten UI is
160 * currently shown.
161 */
162 public $report_supports_flatten = \true;
163 /**
164 * Whether the export UI should offer flattening for this report.
165 */
166 public $show_flatten_table_export = \true;
167 /**
168 * Query parameter overrides specifically for export links generated by the report UI.
169 */
170 public $export_parameters_to_modify = array();
171 /**
172 * Whether to show the 'Pivot by subtable' option (visible in the popup that displays after clicking
173 * the 'cog' icon).
174 */
175 public $show_pivot_by_subtable;
176 /**
177 * The ID of the dimension to pivot by when the 'pivot by subtable' option is clicked. Defaults
178 * to the subtable dimension of the report being displayed.
179 */
180 public $pivot_by_dimension;
181 /**
182 * The column to display in pivot tables. Defaults to the first non-label column if not specified.
183 */
184 public $pivot_by_column = '';
185 /**
186 * The human readable name of the pivot dimension.
187 */
188 public $pivot_dimension_name = \false;
189 /**
190 * Controls whether the footer icon that allows users to switch to the 'normal' DataTable view
191 * is shown.
192 */
193 public $show_table = \true;
194 /**
195 * Controls whether the 'All Columns' footer icon is shown.
196 */
197 public $show_table_all_columns = \true;
198 /**
199 * Controls whether the 'Performance columns' footer icon is shown (if available).
200 */
201 public $show_table_performance = \true;
202 /**
203 * Controls whether the entire view footer is shown.
204 */
205 public $show_footer = \true;
206 /**
207 * Controls whether the row that contains all footer icons & the limit selector is shown.
208 */
209 public $show_footer_icons = \true;
210 /**
211 * Array property that determines which columns will be shown. Columns not in this array
212 * should not appear in ViewDataTable visualizations.
213 *
214 * Example: `array('label', 'nb_visits', 'nb_uniq_visitors')`
215 *
216 * If this value is empty it will be defaulted to `array('label', 'nb_visits')` or
217 * `array('label', 'nb_uniq_visitors')` if the report contains a nb_uniq_visitors column
218 * after data is loaded.
219 */
220 public $columns_to_display = array();
221 /**
222 * Controls whether graph and non core viewDataTable footer icons are shown or not.
223 */
224 public $show_all_views_icons = \true;
225 /**
226 * Array property that contains the names of columns that can be selected in the Series Picker.
227 *
228 * Default value: false
229 */
230 public $selectable_columns = \false;
231 /**
232 * Related reports are listed below a datatable view. When clicked, the original report will
233 * change to the clicked report and the list will change so the original report can be
234 * navigated back to.
235 */
236 public $related_reports = array();
237 /**
238 * "Related Reports" is displayed by default before listing the Related reports,
239 * The string can be changed.
240 */
241 public $related_reports_title;
242 /**
243 * The report title. Used with related reports so report headings can be changed when switching
244 * reports.
245 *
246 * This must be set if related reports are added.
247 */
248 public $title = '';
249 /**
250 * If a URL is set, the title of the report will be clickable. Is supposed to be set for entities that can be
251 * configured (edited) such as goal. Eg when there is a goal report, and someone is allowed to edit the goal entity,
252 * a link is supposed to be with a URL to the edit goal form.
253 * @var string
254 */
255 public $title_edit_entity_url = '';
256 /**
257 * The report description. eg like a goal description
258 */
259 public $description = '';
260 /**
261 * Controls whether a report's related reports are listed with the view or not.
262 */
263 public $show_related_reports = \true;
264 /**
265 * Contains the documentation for a report.
266 */
267 public $documentation = \false;
268 /**
269 * URL linking to an online guide for this report (or plugin).
270 * @var string
271 */
272 public $onlineGuideUrl = \false;
273 /**
274 * Array property containing custom data to be saved in JSON in the data-params HTML attribute
275 * of a data table div. This data can be used by JavaScript DataTable classes.
276 *
277 * e.g. array('typeReferrer' => ...)
278 *
279 * It can then be accessed in the twig templates by clientSideParameters.typeReferrer
280 */
281 public $custom_parameters = array();
282 /**
283 * Controls whether the limit dropdown (which allows users to change the number of data shown)
284 * is always shown or not.
285 *
286 * Normally shown only if pagination is enabled.
287 */
288 public $show_limit_control = \true;
289 /**
290 * Controls whether the search box under the datatable is shown.
291 */
292 public $show_search = \true;
293 /**
294 * Controls whether the period selector under the datatable is shown.
295 */
296 public $show_periods = \false;
297 /**
298 * Controls which periods can be selected when the period selector is enabled
299 */
300 public $selectable_periods = [];
301 /**
302 * Controls whether the export feature under the datatable is shown.
303 *
304 * @api since Piwik 3.2.0
305 */
306 public $show_export = \true;
307 /**
308 * Controls whether the user can sort DataTables by clicking on table column headings.
309 */
310 public $enable_sort = \true;
311 /**
312 * Controls whether the footer icon that allows users to view data as a bar chart is shown.
313 */
314 public $show_bar_chart = \true;
315 /**
316 * Controls whether the footer icon that allows users to view data as a pie chart is shown.
317 */
318 public $show_pie_chart = \true;
319 /**
320 * Controls whether the footer icon that allows users to view data as a tag cloud is shown.
321 */
322 public $show_tag_cloud = \true;
323 /**
324 * If enabled, shows the visualization as a content block. This is similar to wrapping your visualization
325 * with a `<ContentBlock/>`
326 * @var bool
327 */
328 public $show_as_content_block = \true;
329 /**
330 * If enabled shows the title of the report.
331 * @var bool
332 */
333 public $show_title = \true;
334 /**
335 * Controls whether the user is allowed to export data as an RSS feed or not.
336 */
337 public $show_export_as_rss_feed = \true;
338 /**
339 * Controls whether the 'Ecoommerce Orders'/'Abandoned Cart' footer icons are shown or not.
340 */
341 public $show_ecommerce = \false;
342 /**
343 * Stores an HTML message (if any) to display above the datatable view.
344 *
345 * Attention: Message will be printed raw. Don't forget to escape where needed!
346 */
347 public $show_header_message = \false;
348 /**
349 * Stores an HTML message (if any) to display under the datatable view.
350 *
351 * Attention: Message will be printed raw. Don't forget to escape where needed!
352 */
353 public $show_footer_message = \false;
354 /**
355 * Array property that stores documentation for individual metrics.
356 *
357 * E.g. `array('nb_visits' => '...', ...)`
358 *
359 * By default this is set to values retrieved from report metadata (via API.getReportMetadata API method).
360 */
361 public $metrics_documentation = array();
362 /**
363 * Row metadata name that contains the tooltip for the specific row.
364 */
365 public $tooltip_metadata_name = \false;
366 /**
367 * The URL to the report the view is displaying. Modifying this means clicking back to this report
368 * from a Related Report will go to a different URL. Can be used to load an entire page instead
369 * of a single report when going back to the original report.
370 *
371 * The URL used to request the report without generic filters.
372 */
373 public $self_url = '';
374 /**
375 * CSS class to use in the output HTML div. This is added in addition to the visualization CSS
376 * class.
377 */
378 public $datatable_css_class = \false;
379 /**
380 * The JavaScript class to instantiate after the result HTML is obtained. This class handles all
381 * interactive behavior for the DataTable view.
382 */
383 public $datatable_js_type = 'DataTable';
384 /**
385 * If true, searching through the DataTable will search through all subtables.
386 */
387 public $search_recursive = \false;
388 /**
389 * The unit of the displayed column. Valid if only one non-label column is displayed.
390 */
391 public $y_axis_unit = \false;
392 /**
393 * Controls whether to show the 'Export as Image' footer icon.
394 */
395 public $show_export_as_image_icon = \false;
396 /**
397 * Array of DataTable filters that should be run before displaying a DataTable. Elements
398 * of this array can either be a closure or an array with at most three elements, including:
399 * - the filter name (or a closure)
400 * - an array of filter parameters
401 * - a boolean indicating if the filter is a priority filter or not
402 *
403 * Priority filters are run before queued filters. These filters should be filters that
404 * add/delete rows.
405 *
406 * If a closure is used, the view is appended as a parameter.
407 */
408 public $filters = array();
409 /**
410 * Contains the controller action to call when requesting subtables of the current report.
411 *
412 * By default, this is set to the controller action used to request the report.
413 */
414 public $subtable_controller_action = '';
415 /**
416 * Controls whether the 'prev'/'next' links are shown in the DataTable footer. These links
417 * change the 'filter_offset' query parameter, thus allowing pagination.
418 */
419 public $show_pagination_control = \true;
420 /**
421 * Controls whether offset information (ie, '5-10 of 20') is shown under the datatable.
422 */
423 public $show_offset_information = \true;
424 /**
425 * Controls whether annotations are shown or not.
426 */
427 public $hide_annotations_view = \true;
428 /**
429 * Controls whether the 'all' row limit option is shown for the limit selector.
430 *
431 * @var bool
432 */
433 public $disable_all_rows_filter_limit = \false;
434 /**
435 * Sets a limit for the maximum number of rows that can be exported.
436 * @var int
437 */
438 public $max_export_filter_limit = -1;
439 /**
440 * Message to show if not data is available for the report
441 * Defaults to `CoreHome_ThereIsNoDataForThisReport` if not set
442 *
443 * Attention: Message will be printed raw. Don't forget to escape where needed!
444 *
445 * @var string
446 */
447 public $no_data_message = '';
448 /**
449 * List of extra actions to display as icons in the datatable footer.
450 *
451 * Not API yet.
452 *
453 * @var array
454 * @ignore
455 */
456 public $datatable_actions = [];
457 /*
458 * Can be used to add a segment condition to the segment used to launch the segmented visitor log.
459 * This can be useful if you'd like to have this segment condition applied ONLY to the segmented visitor
460 * log, and not to the report itself.
461 *
462 * Contrast with just setting the 'segment', if done this way, the segment will be applied to the report
463 * data as well, which may not be desired.
464 *
465 * @var string
466 */
467 public $segmented_visitor_log_segment_suffix = '';
468 /**
469 * Disable comparison support for this specific usage of a ViewDataTable.
470 *
471 * @var bool
472 */
473 public $disable_comparison = \false;
474 /**
475 * @ignore
476 */
477 public $report_id = '';
478 /**
479 * @ignore
480 */
481 public $controllerName;
482 /**
483 * @ignore
484 */
485 public $controllerAction;
486 public function __construct()
487 {
488 $this->translations = array_merge(Metrics::getDefaultMetrics(), Metrics::getDefaultProcessedMetrics());
489 $periodValidator = new PeriodValidator();
490 $this->selectable_periods = $periodValidator->getPeriodsAllowedForUI();
491 $this->selectable_periods = array_diff($this->selectable_periods, array('range'));
492 foreach ($this->selectable_periods as $period) {
493 $this->translations[$period] = ucfirst(Piwik::translate('Intl_Period' . ucfirst($period)));
494 }
495 $this->show_title = (bool) Common::getRequestVar('showtitle', 0, 'int');
496 }
497 /**
498 * @ignore
499 */
500 public function setController($controllerName, $controllerAction)
501 {
502 $this->controllerName = $controllerName;
503 $this->controllerAction = $controllerAction;
504 $this->report_id = $controllerName . '.' . $controllerAction;
505 $this->loadDocumentation();
506 $this->setShouldShowPivotBySubtable();
507 $this->setShouldShowFlattener();
508 }
509 /** Load documentation from the API */
510 private function loadDocumentation()
511 {
512 $this->metrics_documentation = array();
513 $idSite = Common::getRequestVar('idSite', 0, 'int');
514 if ($idSite < 1) {
515 return;
516 }
517 $apiParameters = array();
518 $entityNames = StaticContainer::get('entities.idNames');
519 foreach ($entityNames as $entityName) {
520 $idEntity = Common::getRequestVar($entityName, 0, 'int');
521 if ($idEntity > 0) {
522 $apiParameters[$entityName] = $idEntity;
523 }
524 }
525 $report = API::getInstance()->getMetadata($idSite, $this->controllerName, $this->controllerAction, $apiParameters);
526 if (empty($report)) {
527 return;
528 }
529 $report = $report[0];
530 if (isset($report['metricsDocumentation'])) {
531 $this->metrics_documentation = $report['metricsDocumentation'];
532 }
533 if (isset($report['documentation'])) {
534 $this->documentation = $report['documentation'];
535 }
536 if (isset($report['onlineGuideUrl'])) {
537 $this->onlineGuideUrl = $report['onlineGuideUrl'];
538 }
539 }
540 /**
541 * Marks display properties as client side properties. [Read this](#client-side-properties-desc)
542 * to learn more.
543 *
544 * @param array $propertyNames List of property names, eg, `array('show_limit_control', 'show_goals')`.
545 */
546 public function addPropertiesThatShouldBeAvailableClientSide(array $propertyNames)
547 {
548 foreach ($propertyNames as $propertyName) {
549 $this->clientSideProperties[] = $propertyName;
550 }
551 }
552 /**
553 * Marks display properties as overridable. [Read this](#overridable-properties-desc) to
554 * learn more.
555 *
556 * @param array $propertyNames List of property names, eg, `array('show_limit_control', 'show_goals')`.
557 */
558 public function addPropertiesThatCanBeOverwrittenByQueryParams(array $propertyNames)
559 {
560 foreach ($propertyNames as $propertyName) {
561 $this->overridableProperties[] = $propertyName;
562 }
563 }
564 /**
565 * Returns array of all property values in this config object. Property values are mapped
566 * by name.
567 *
568 * @return array eg, `array('show_limit_control' => 0, 'show_goals' => 1, ...)`
569 */
570 public function getProperties()
571 {
572 return get_object_vars($this);
573 }
574 /**
575 * @ignore
576 */
577 public function setDefaultColumnsToDisplay($columns, $hasNbVisits, $hasNbUniqVisitors)
578 {
579 if ($hasNbVisits || $hasNbUniqVisitors) {
580 $columnsToDisplay = array('label');
581 // if unique visitors data is available, show it, otherwise just visits
582 if ($hasNbUniqVisitors) {
583 $columnsToDisplay[] = 'nb_uniq_visitors';
584 } else {
585 $columnsToDisplay[] = 'nb_visits';
586 }
587 } else {
588 $columnsToDisplay = $columns;
589 }
590 $this->columns_to_display = array_filter($columnsToDisplay);
591 }
592 public function removeColumnToDisplay($columnToRemove)
593 {
594 if (!empty($this->columns_to_display)) {
595 $key = array_search($columnToRemove, $this->columns_to_display);
596 if (\false !== $key) {
597 unset($this->columns_to_display[$key]);
598 }
599 }
600 }
601 /**
602 * @ignore
603 */
604 private function getFiltersToRun()
605 {
606 $priorityFilters = array();
607 $presentationFilters = array();
608 foreach ($this->filters as $filterInfo) {
609 if ($filterInfo instanceof \Closure) {
610 $nameOrClosure = $filterInfo;
611 $parameters = array();
612 $priority = \false;
613 } else {
614 @(list($nameOrClosure, $parameters, $priority) = $filterInfo);
615 }
616 if ($priority) {
617 $priorityFilters[] = array($nameOrClosure, $parameters);
618 } else {
619 $presentationFilters[] = array($nameOrClosure, $parameters);
620 }
621 }
622 return array($priorityFilters, $presentationFilters);
623 }
624 public function getPriorityFilters()
625 {
626 $filters = $this->getFiltersToRun();
627 return $filters[0];
628 }
629 public function getPresentationFilters()
630 {
631 $filters = $this->getFiltersToRun();
632 return $filters[1];
633 }
634 /**
635 * Sets secondary dimensions for the current report. This will make the related reports to display secondary dimension reports.
636 * This requires the API to be able to handle the `secondaryDimension` parameter.
637 * The properties {@link $related_reports} and {@link $related_reports_title} will be overwritten for this purpose.
638 *
639 * @template T of array<string, string>
640 * @param T $dimensions
641 * @param key-of<T> $defaultDimension
642 */
643 public function setSecondaryDimensions(array $dimensions, string $defaultDimension) : void
644 {
645 $this->show_related_reports = \true;
646 $this->related_reports = [];
647 $secondaryDimension = $defaultDimension;
648 $requestedDimension = Request::fromRequest()->getStringParameter('secondaryDimension', '');
649 if (array_key_exists($requestedDimension, $dimensions)) {
650 $secondaryDimension = $requestedDimension;
651 }
652 $secondaryDimensionTranslation = $dimensions[$secondaryDimension];
653 $this->related_reports_title = Piwik::translate('General_SecondaryDimension', $secondaryDimensionTranslation) . "<br/>" . Piwik::translate('General_SwitchToSecondaryDimension', '');
654 foreach ($dimensions as $dimension => $dimensionLabel) {
655 if ($dimension === $secondaryDimension) {
656 // don't show as related report the currently selected dimension
657 continue;
658 }
659 $this->addRelatedReport($this->controllerName . '.' . $this->controllerAction, $dimensionLabel, ['secondaryDimension' => $dimension]);
660 }
661 }
662 /**
663 * Adds a related report to the {@link $related_reports} property. If the report
664 * references the one that is currently being displayed, it will not be added to the related
665 * report list.
666 *
667 * @param string $relatedReport The plugin and method of the report, eg, `'DevicesDetection.getBrowsers'`.
668 * @param string $title The report's display name, eg, `'Browsers'`.
669 * @param array $queryParams Any extra query parameters to set in related report's URL, eg,
670 * `array('idGoal' => 'ecommerceOrder')`.
671 */
672 public function addRelatedReport($relatedReport, $title, $queryParams = array())
673 {
674 [$module, $action] = explode('.', $relatedReport);
675 // don't add the related report if it references this report
676 if ($this->controllerName === $module && $this->controllerAction === $action) {
677 if (empty($queryParams)) {
678 return;
679 }
680 }
681 $url = ApiRequest::getBaseReportUrl($module, $action, $queryParams);
682 $this->related_reports[$url] = $title;
683 }
684 /**
685 * Adds several related reports to the {@link $related_reports} property. If
686 * any of the reports references the report that is currently being displayed, it will not
687 * be added to the list. All other reports will still be added though.
688 *
689 * If you need to make sure the related report URL has some extra query parameters,
690 * use {@link addRelatedReport()}.
691 *
692 * @param array $relatedReports Array mapping report IDs with their internationalized display
693 * titles, eg,
694 * ```
695 * array(
696 * 'DevicesDetection.getBrowsers' => 'Browsers',
697 * 'Resolution.getConfiguration' => 'Configurations'
698 * )
699 * ```
700 */
701 public function addRelatedReports($relatedReports)
702 {
703 foreach ($relatedReports as $report => $title) {
704 $this->addRelatedReport($report, $title);
705 }
706 }
707 /**
708 * Associates internationalized text with a metric. Overwrites existing mappings.
709 *
710 * See {@link $translations}.
711 *
712 * @param string $columnName The name of a column in the report data, eg, `'nb_visits'` or
713 * `'goal_1_nb_conversions'`.
714 * @param string $translation The internationalized text, eg, `'Visits'` or `"Conversions for 'My Goal'"`.
715 */
716 public function addTranslation($columnName, $translation)
717 {
718 $this->translations[$columnName] = $translation;
719 }
720 /**
721 * Associates multiple translations with metrics.
722 *
723 * See {@link $translations} and {@link addTranslation()}.
724 *
725 * @param array $translations An array of column name => text mappings, eg,
726 * ```
727 * array(
728 * 'nb_visits' => 'Visits',
729 * 'goal_1_nb_conversions' => "Conversions for 'My Goal'"
730 * )
731 * ```
732 */
733 public function addTranslations($translations)
734 {
735 foreach ($translations as $key => $translation) {
736 $this->addTranslation($key, $translation);
737 }
738 }
739 private function setShouldShowPivotBySubtable()
740 {
741 $report = ReportsProvider::factory($this->controllerName, $this->controllerAction);
742 if (empty($report)) {
743 $this->show_pivot_by_subtable = \false;
744 $this->pivot_by_dimension = \false;
745 } else {
746 $this->show_pivot_by_subtable = PivotByDimension::isPivotingReportBySubtableSupported($report);
747 $subtableDimension = $report->getSubtableDimension();
748 if (!empty($subtableDimension)) {
749 $this->pivot_by_dimension = $subtableDimension->getId();
750 $this->pivot_dimension_name = $subtableDimension->getName();
751 }
752 }
753 }
754 private function setShouldShowFlattener()
755 {
756 $report = ReportsProvider::factory($this->controllerName, $this->controllerAction);
757 if ($report) {
758 $this->report_supports_flatten = $report->supportsFlatten();
759 if (!$this->report_supports_flatten) {
760 $this->show_flatten_table = \false;
761 $this->show_flatten_table_export = \false;
762 }
763 }
764 }
765 public function disablePivotBySubtableIfTableHasNoSubtables(DataTable $table)
766 {
767 foreach ($table->getRows() as $row) {
768 if ($row->getIdSubDataTable() !== null) {
769 return;
770 }
771 }
772 $this->show_pivot_by_subtable = \false;
773 }
774 }
775