PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
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 3 months ago Factory.php 1 year ago Manager.php 3 months ago Request.php 6 months ago RequestConfig.php 6 months ago
Config.php
761 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 to show the 'Pivot by subtable' option (visible in the popup that displays after clicking
160 * the 'cog' icon).
161 */
162 public $show_pivot_by_subtable;
163 /**
164 * The ID of the dimension to pivot by when the 'pivot by subtable' option is clicked. Defaults
165 * to the subtable dimension of the report being displayed.
166 */
167 public $pivot_by_dimension;
168 /**
169 * The column to display in pivot tables. Defaults to the first non-label column if not specified.
170 */
171 public $pivot_by_column = '';
172 /**
173 * The human readable name of the pivot dimension.
174 */
175 public $pivot_dimension_name = \false;
176 /**
177 * Controls whether the footer icon that allows users to switch to the 'normal' DataTable view
178 * is shown.
179 */
180 public $show_table = \true;
181 /**
182 * Controls whether the 'All Columns' footer icon is shown.
183 */
184 public $show_table_all_columns = \true;
185 /**
186 * Controls whether the 'Performance columns' footer icon is shown (if available).
187 */
188 public $show_table_performance = \true;
189 /**
190 * Controls whether the entire view footer is shown.
191 */
192 public $show_footer = \true;
193 /**
194 * Controls whether the row that contains all footer icons & the limit selector is shown.
195 */
196 public $show_footer_icons = \true;
197 /**
198 * Array property that determines which columns will be shown. Columns not in this array
199 * should not appear in ViewDataTable visualizations.
200 *
201 * Example: `array('label', 'nb_visits', 'nb_uniq_visitors')`
202 *
203 * If this value is empty it will be defaulted to `array('label', 'nb_visits')` or
204 * `array('label', 'nb_uniq_visitors')` if the report contains a nb_uniq_visitors column
205 * after data is loaded.
206 */
207 public $columns_to_display = array();
208 /**
209 * Controls whether graph and non core viewDataTable footer icons are shown or not.
210 */
211 public $show_all_views_icons = \true;
212 /**
213 * Array property that contains the names of columns that can be selected in the Series Picker.
214 *
215 * Default value: false
216 */
217 public $selectable_columns = \false;
218 /**
219 * Related reports are listed below a datatable view. When clicked, the original report will
220 * change to the clicked report and the list will change so the original report can be
221 * navigated back to.
222 */
223 public $related_reports = array();
224 /**
225 * "Related Reports" is displayed by default before listing the Related reports,
226 * The string can be changed.
227 */
228 public $related_reports_title;
229 /**
230 * The report title. Used with related reports so report headings can be changed when switching
231 * reports.
232 *
233 * This must be set if related reports are added.
234 */
235 public $title = '';
236 /**
237 * If a URL is set, the title of the report will be clickable. Is supposed to be set for entities that can be
238 * configured (edited) such as goal. Eg when there is a goal report, and someone is allowed to edit the goal entity,
239 * a link is supposed to be with a URL to the edit goal form.
240 * @var string
241 */
242 public $title_edit_entity_url = '';
243 /**
244 * The report description. eg like a goal description
245 */
246 public $description = '';
247 /**
248 * Controls whether a report's related reports are listed with the view or not.
249 */
250 public $show_related_reports = \true;
251 /**
252 * Contains the documentation for a report.
253 */
254 public $documentation = \false;
255 /**
256 * URL linking to an online guide for this report (or plugin).
257 * @var string
258 */
259 public $onlineGuideUrl = \false;
260 /**
261 * Array property containing custom data to be saved in JSON in the data-params HTML attribute
262 * of a data table div. This data can be used by JavaScript DataTable classes.
263 *
264 * e.g. array('typeReferrer' => ...)
265 *
266 * It can then be accessed in the twig templates by clientSideParameters.typeReferrer
267 */
268 public $custom_parameters = array();
269 /**
270 * Controls whether the limit dropdown (which allows users to change the number of data shown)
271 * is always shown or not.
272 *
273 * Normally shown only if pagination is enabled.
274 */
275 public $show_limit_control = \true;
276 /**
277 * Controls whether the search box under the datatable is shown.
278 */
279 public $show_search = \true;
280 /**
281 * Controls whether the period selector under the datatable is shown.
282 */
283 public $show_periods = \false;
284 /**
285 * Controls which periods can be selected when the period selector is enabled
286 */
287 public $selectable_periods = [];
288 /**
289 * Controls whether the export feature under the datatable is shown.
290 *
291 * @api since Piwik 3.2.0
292 */
293 public $show_export = \true;
294 /**
295 * Controls whether the user can sort DataTables by clicking on table column headings.
296 */
297 public $enable_sort = \true;
298 /**
299 * Controls whether the footer icon that allows users to view data as a bar chart is shown.
300 */
301 public $show_bar_chart = \true;
302 /**
303 * Controls whether the footer icon that allows users to view data as a pie chart is shown.
304 */
305 public $show_pie_chart = \true;
306 /**
307 * Controls whether the footer icon that allows users to view data as a tag cloud is shown.
308 */
309 public $show_tag_cloud = \true;
310 /**
311 * If enabled, shows the visualization as a content block. This is similar to wrapping your visualization
312 * with a `<ContentBlock/>`
313 * @var bool
314 */
315 public $show_as_content_block = \true;
316 /**
317 * If enabled shows the title of the report.
318 * @var bool
319 */
320 public $show_title = \true;
321 /**
322 * Controls whether the user is allowed to export data as an RSS feed or not.
323 */
324 public $show_export_as_rss_feed = \true;
325 /**
326 * Controls whether the 'Ecoommerce Orders'/'Abandoned Cart' footer icons are shown or not.
327 */
328 public $show_ecommerce = \false;
329 /**
330 * Stores an HTML message (if any) to display above the datatable view.
331 *
332 * Attention: Message will be printed raw. Don't forget to escape where needed!
333 */
334 public $show_header_message = \false;
335 /**
336 * Stores an HTML message (if any) to display under the datatable view.
337 *
338 * Attention: Message will be printed raw. Don't forget to escape where needed!
339 */
340 public $show_footer_message = \false;
341 /**
342 * Array property that stores documentation for individual metrics.
343 *
344 * E.g. `array('nb_visits' => '...', ...)`
345 *
346 * By default this is set to values retrieved from report metadata (via API.getReportMetadata API method).
347 */
348 public $metrics_documentation = array();
349 /**
350 * Row metadata name that contains the tooltip for the specific row.
351 */
352 public $tooltip_metadata_name = \false;
353 /**
354 * The URL to the report the view is displaying. Modifying this means clicking back to this report
355 * from a Related Report will go to a different URL. Can be used to load an entire page instead
356 * of a single report when going back to the original report.
357 *
358 * The URL used to request the report without generic filters.
359 */
360 public $self_url = '';
361 /**
362 * CSS class to use in the output HTML div. This is added in addition to the visualization CSS
363 * class.
364 */
365 public $datatable_css_class = \false;
366 /**
367 * The JavaScript class to instantiate after the result HTML is obtained. This class handles all
368 * interactive behavior for the DataTable view.
369 */
370 public $datatable_js_type = 'DataTable';
371 /**
372 * If true, searching through the DataTable will search through all subtables.
373 */
374 public $search_recursive = \false;
375 /**
376 * The unit of the displayed column. Valid if only one non-label column is displayed.
377 */
378 public $y_axis_unit = \false;
379 /**
380 * Controls whether to show the 'Export as Image' footer icon.
381 */
382 public $show_export_as_image_icon = \false;
383 /**
384 * Array of DataTable filters that should be run before displaying a DataTable. Elements
385 * of this array can either be a closure or an array with at most three elements, including:
386 * - the filter name (or a closure)
387 * - an array of filter parameters
388 * - a boolean indicating if the filter is a priority filter or not
389 *
390 * Priority filters are run before queued filters. These filters should be filters that
391 * add/delete rows.
392 *
393 * If a closure is used, the view is appended as a parameter.
394 */
395 public $filters = array();
396 /**
397 * Contains the controller action to call when requesting subtables of the current report.
398 *
399 * By default, this is set to the controller action used to request the report.
400 */
401 public $subtable_controller_action = '';
402 /**
403 * Controls whether the 'prev'/'next' links are shown in the DataTable footer. These links
404 * change the 'filter_offset' query parameter, thus allowing pagination.
405 */
406 public $show_pagination_control = \true;
407 /**
408 * Controls whether offset information (ie, '5-10 of 20') is shown under the datatable.
409 */
410 public $show_offset_information = \true;
411 /**
412 * Controls whether annotations are shown or not.
413 */
414 public $hide_annotations_view = \true;
415 /**
416 * Controls whether the 'all' row limit option is shown for the limit selector.
417 *
418 * @var bool
419 */
420 public $disable_all_rows_filter_limit = \false;
421 /**
422 * Sets a limit for the maximum number of rows that can be exported.
423 * @var int
424 */
425 public $max_export_filter_limit = -1;
426 /**
427 * Message to show if not data is available for the report
428 * Defaults to `CoreHome_ThereIsNoDataForThisReport` if not set
429 *
430 * Attention: Message will be printed raw. Don't forget to escape where needed!
431 *
432 * @var string
433 */
434 public $no_data_message = '';
435 /**
436 * List of extra actions to display as icons in the datatable footer.
437 *
438 * Not API yet.
439 *
440 * @var array
441 * @ignore
442 */
443 public $datatable_actions = [];
444 /*
445 * Can be used to add a segment condition to the segment used to launch the segmented visitor log.
446 * This can be useful if you'd like to have this segment condition applied ONLY to the segmented visitor
447 * log, and not to the report itself.
448 *
449 * Contrast with just setting the 'segment', if done this way, the segment will be applied to the report
450 * data as well, which may not be desired.
451 *
452 * @var string
453 */
454 public $segmented_visitor_log_segment_suffix = '';
455 /**
456 * Disable comparison support for this specific usage of a ViewDataTable.
457 *
458 * @var bool
459 */
460 public $disable_comparison = \false;
461 /**
462 * @ignore
463 */
464 public $report_id = '';
465 /**
466 * @ignore
467 */
468 public $controllerName;
469 /**
470 * @ignore
471 */
472 public $controllerAction;
473 /**
474 * Constructor.
475 */
476 public function __construct()
477 {
478 $this->translations = array_merge(Metrics::getDefaultMetrics(), Metrics::getDefaultProcessedMetrics());
479 $periodValidator = new PeriodValidator();
480 $this->selectable_periods = $periodValidator->getPeriodsAllowedForUI();
481 $this->selectable_periods = array_diff($this->selectable_periods, array('range'));
482 foreach ($this->selectable_periods as $period) {
483 $this->translations[$period] = ucfirst(Piwik::translate('Intl_Period' . ucfirst($period)));
484 }
485 $this->show_title = (bool) Common::getRequestVar('showtitle', 0, 'int');
486 }
487 /**
488 * @ignore
489 */
490 public function setController($controllerName, $controllerAction)
491 {
492 $this->controllerName = $controllerName;
493 $this->controllerAction = $controllerAction;
494 $this->report_id = $controllerName . '.' . $controllerAction;
495 $this->loadDocumentation();
496 $this->setShouldShowPivotBySubtable();
497 $this->setShouldShowFlattener();
498 }
499 /** Load documentation from the API */
500 private function loadDocumentation()
501 {
502 $this->metrics_documentation = array();
503 $idSite = Common::getRequestVar('idSite', 0, 'int');
504 if ($idSite < 1) {
505 return;
506 }
507 $apiParameters = array();
508 $entityNames = StaticContainer::get('entities.idNames');
509 foreach ($entityNames as $entityName) {
510 $idEntity = Common::getRequestVar($entityName, 0, 'int');
511 if ($idEntity > 0) {
512 $apiParameters[$entityName] = $idEntity;
513 }
514 }
515 $report = API::getInstance()->getMetadata($idSite, $this->controllerName, $this->controllerAction, $apiParameters);
516 if (empty($report)) {
517 return;
518 }
519 $report = $report[0];
520 if (isset($report['metricsDocumentation'])) {
521 $this->metrics_documentation = $report['metricsDocumentation'];
522 }
523 if (isset($report['documentation'])) {
524 $this->documentation = $report['documentation'];
525 }
526 if (isset($report['onlineGuideUrl'])) {
527 $this->onlineGuideUrl = $report['onlineGuideUrl'];
528 }
529 }
530 /**
531 * Marks display properties as client side properties. [Read this](#client-side-properties-desc)
532 * to learn more.
533 *
534 * @param array $propertyNames List of property names, eg, `array('show_limit_control', 'show_goals')`.
535 */
536 public function addPropertiesThatShouldBeAvailableClientSide(array $propertyNames)
537 {
538 foreach ($propertyNames as $propertyName) {
539 $this->clientSideProperties[] = $propertyName;
540 }
541 }
542 /**
543 * Marks display properties as overridable. [Read this](#overridable-properties-desc) to
544 * learn more.
545 *
546 * @param array $propertyNames List of property names, eg, `array('show_limit_control', 'show_goals')`.
547 */
548 public function addPropertiesThatCanBeOverwrittenByQueryParams(array $propertyNames)
549 {
550 foreach ($propertyNames as $propertyName) {
551 $this->overridableProperties[] = $propertyName;
552 }
553 }
554 /**
555 * Returns array of all property values in this config object. Property values are mapped
556 * by name.
557 *
558 * @return array eg, `array('show_limit_control' => 0, 'show_goals' => 1, ...)`
559 */
560 public function getProperties()
561 {
562 return get_object_vars($this);
563 }
564 /**
565 * @ignore
566 */
567 public function setDefaultColumnsToDisplay($columns, $hasNbVisits, $hasNbUniqVisitors)
568 {
569 if ($hasNbVisits || $hasNbUniqVisitors) {
570 $columnsToDisplay = array('label');
571 // if unique visitors data is available, show it, otherwise just visits
572 if ($hasNbUniqVisitors) {
573 $columnsToDisplay[] = 'nb_uniq_visitors';
574 } else {
575 $columnsToDisplay[] = 'nb_visits';
576 }
577 } else {
578 $columnsToDisplay = $columns;
579 }
580 $this->columns_to_display = array_filter($columnsToDisplay);
581 }
582 public function removeColumnToDisplay($columnToRemove)
583 {
584 if (!empty($this->columns_to_display)) {
585 $key = array_search($columnToRemove, $this->columns_to_display);
586 if (\false !== $key) {
587 unset($this->columns_to_display[$key]);
588 }
589 }
590 }
591 /**
592 * @ignore
593 */
594 private function getFiltersToRun()
595 {
596 $priorityFilters = array();
597 $presentationFilters = array();
598 foreach ($this->filters as $filterInfo) {
599 if ($filterInfo instanceof \Closure) {
600 $nameOrClosure = $filterInfo;
601 $parameters = array();
602 $priority = \false;
603 } else {
604 @(list($nameOrClosure, $parameters, $priority) = $filterInfo);
605 }
606 if ($priority) {
607 $priorityFilters[] = array($nameOrClosure, $parameters);
608 } else {
609 $presentationFilters[] = array($nameOrClosure, $parameters);
610 }
611 }
612 return array($priorityFilters, $presentationFilters);
613 }
614 public function getPriorityFilters()
615 {
616 $filters = $this->getFiltersToRun();
617 return $filters[0];
618 }
619 public function getPresentationFilters()
620 {
621 $filters = $this->getFiltersToRun();
622 return $filters[1];
623 }
624 /**
625 * Sets secondary dimensions for the current report. This will make the related reports to display secondary dimension reports.
626 * This requires the API to be able to handle the `secondaryDimension` parameter.
627 * The properties {@link $related_reports} and {@link $related_reports_title} will be overwritten for this purpose.
628 *
629 * @template T of array<string, string>
630 * @param T $dimensions
631 * @param key-of<T> $defaultDimension
632 */
633 public function setSecondaryDimensions(array $dimensions, string $defaultDimension) : void
634 {
635 $this->show_related_reports = \true;
636 $this->related_reports = [];
637 $secondaryDimension = $defaultDimension;
638 $requestedDimension = Request::fromRequest()->getStringParameter('secondaryDimension', '');
639 if (array_key_exists($requestedDimension, $dimensions)) {
640 $secondaryDimension = $requestedDimension;
641 }
642 $secondaryDimensionTranslation = $dimensions[$secondaryDimension];
643 $this->related_reports_title = Piwik::translate('General_SecondaryDimension', $secondaryDimensionTranslation) . "<br/>" . Piwik::translate('General_SwitchToSecondaryDimension', '');
644 foreach ($dimensions as $dimension => $dimensionLabel) {
645 if ($dimension === $secondaryDimension) {
646 // don't show as related report the currently selected dimension
647 continue;
648 }
649 $this->addRelatedReport($this->controllerName . '.' . $this->controllerAction, $dimensionLabel, ['secondaryDimension' => $dimension]);
650 }
651 }
652 /**
653 * Adds a related report to the {@link $related_reports} property. If the report
654 * references the one that is currently being displayed, it will not be added to the related
655 * report list.
656 *
657 * @param string $relatedReport The plugin and method of the report, eg, `'DevicesDetection.getBrowsers'`.
658 * @param string $title The report's display name, eg, `'Browsers'`.
659 * @param array $queryParams Any extra query parameters to set in related report's URL, eg,
660 * `array('idGoal' => 'ecommerceOrder')`.
661 */
662 public function addRelatedReport($relatedReport, $title, $queryParams = array())
663 {
664 [$module, $action] = explode('.', $relatedReport);
665 // don't add the related report if it references this report
666 if ($this->controllerName === $module && $this->controllerAction === $action) {
667 if (empty($queryParams)) {
668 return;
669 }
670 }
671 $url = ApiRequest::getBaseReportUrl($module, $action, $queryParams);
672 $this->related_reports[$url] = $title;
673 }
674 /**
675 * Adds several related reports to the {@link $related_reports} property. If
676 * any of the reports references the report that is currently being displayed, it will not
677 * be added to the list. All other reports will still be added though.
678 *
679 * If you need to make sure the related report URL has some extra query parameters,
680 * use {@link addRelatedReport()}.
681 *
682 * @param array $relatedReports Array mapping report IDs with their internationalized display
683 * titles, eg,
684 * ```
685 * array(
686 * 'DevicesDetection.getBrowsers' => 'Browsers',
687 * 'Resolution.getConfiguration' => 'Configurations'
688 * )
689 * ```
690 */
691 public function addRelatedReports($relatedReports)
692 {
693 foreach ($relatedReports as $report => $title) {
694 $this->addRelatedReport($report, $title);
695 }
696 }
697 /**
698 * Associates internationalized text with a metric. Overwrites existing mappings.
699 *
700 * See {@link $translations}.
701 *
702 * @param string $columnName The name of a column in the report data, eg, `'nb_visits'` or
703 * `'goal_1_nb_conversions'`.
704 * @param string $translation The internationalized text, eg, `'Visits'` or `"Conversions for 'My Goal'"`.
705 */
706 public function addTranslation($columnName, $translation)
707 {
708 $this->translations[$columnName] = $translation;
709 }
710 /**
711 * Associates multiple translations with metrics.
712 *
713 * See {@link $translations} and {@link addTranslation()}.
714 *
715 * @param array $translations An array of column name => text mappings, eg,
716 * ```
717 * array(
718 * 'nb_visits' => 'Visits',
719 * 'goal_1_nb_conversions' => "Conversions for 'My Goal'"
720 * )
721 * ```
722 */
723 public function addTranslations($translations)
724 {
725 foreach ($translations as $key => $translation) {
726 $this->addTranslation($key, $translation);
727 }
728 }
729 private function setShouldShowPivotBySubtable()
730 {
731 $report = ReportsProvider::factory($this->controllerName, $this->controllerAction);
732 if (empty($report)) {
733 $this->show_pivot_by_subtable = \false;
734 $this->pivot_by_dimension = \false;
735 } else {
736 $this->show_pivot_by_subtable = PivotByDimension::isPivotingReportBySubtableSupported($report);
737 $subtableDimension = $report->getSubtableDimension();
738 if (!empty($subtableDimension)) {
739 $this->pivot_by_dimension = $subtableDimension->getId();
740 $this->pivot_dimension_name = $subtableDimension->getName();
741 }
742 }
743 }
744 private function setShouldShowFlattener()
745 {
746 $report = ReportsProvider::factory($this->controllerName, $this->controllerAction);
747 if ($report && !$report->supportsFlatten()) {
748 $this->show_flatten_table = \false;
749 }
750 }
751 public function disablePivotBySubtableIfTableHasNoSubtables(DataTable $table)
752 {
753 foreach ($table->getRows() as $row) {
754 if ($row->getIdSubDataTable() !== null) {
755 return;
756 }
757 }
758 $this->show_pivot_by_subtable = \false;
759 }
760 }
761