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