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