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