ViewDataTable instances load analytics data via Piwik's Reporting API and then output some type of visualization of that data. Visualizations can be in any format. HTML-based visualizations should extend {@link Visualization}. Visualizations that use other formats, such as visualizations that output an image, should extend ViewDataTable directly. ### Creating ViewDataTables ViewDataTable instances are not created via the new operator, instead the {@link Piwik\ViewDataTable\Factory} class is used. The specific subclass to create is determined, first, by the **viewDataTable** query paramater. If this parameter is not set, then the default visualization type for the report being displayed is used. ### Configuring ViewDataTables **Display properties** ViewDataTable output can be customized by setting one of many available display properties. Display properties are stored as fields in {@link Piwik\ViewDataTable\Config} objects. ViewDataTables store a {@link Piwik\ViewDataTable\Config} object in the {@link $config} field. Display properties can be set at any time before rendering. **Request properties** Request properties are similar to display properties in the way they are set. They are, however, not used to customize ViewDataTable instances, but in the request to Piwik's API when loading analytics data. Request properties are set by setting the fields of a {@link Piwik\ViewDataTable\RequestConfig} object stored in the {@link $requestConfig} field. They can be set at any time before rendering. Setting them after data is loaded will have no effect. **Customizing how reports are displayed** Each individual report should be rendered in its own controller method. There are two ways to render a report within its controller method. You can either: 1. manually create and configure a ViewDataTable instance 2. invoke {@link Piwik\Plugin\Controller::renderReport} and configure the ViewDataTable instance in the {@hook ViewDataTable.configure} event. ViewDataTable instances are configured by setting and modifying display properties and request properties. ### Creating new visualizations New visualizations can be created by extending the ViewDataTable class or one of its descendants. To learn more read our guide on creating new visualizations. ### Examples **Manually configuring a ViewDataTable** a controller method that displays a single report public function myReport() { $view = \Piwik\ViewDataTable\Factory::build('table', 'MyPlugin.myReport'); $view->config->show_limit_control = true; $view->config->translations['myFancyMetric'] = "My Fancy Metric"; ... return $view->render(); } **Using {@link Piwik\Plugin\Controller::renderReport}** First, a controller method that displays a single report: public function myReport() { return $this->renderReport(__FUNCTION__);` } Then the event handler for the {@hook ViewDataTable.configure} event: public function configureViewDataTable(ViewDataTable $view) { switch ($view->requestConfig->apiMethodToRequestDataTable) { case 'MyPlugin.myReport': $view->config->show_limit_control = true; $view->config->translations['myFancyMetric'] = "My Fancy Metric"; ... break; } } **Using custom configuration objects in a new visualization** class MyVisualizationConfig extends Piwik\ViewDataTable\Config { public $my_new_property = true; } class MyVisualizationRequestConfig extends Piwik\ViewDataTable\RequestConfig { public $my_new_property = false; } class MyVisualization extends Piwik\Plugin\ViewDataTable { public static function getDefaultConfig() { return new MyVisualizationConfig(); } public static function getDefaultRequestConfig() { return new MyVisualizationRequestConfig(); } }
Inheritance: implements Piwik\View\ViewInterface
Example #1
0
 /**
  * Here you can configure how your report should be displayed. For instance whether your report supports a search
  * etc. You can also change the default request config. For instance change how many rows are displayed by default.
  *
  * @param ViewDataTable $view
  */
 public function configureView(ViewDataTable $view)
 {
     if ($view->isViewDataTableId(Sparklines::ID)) {
         /** @var Sparklines $view */
         $view->config->addSparklineMetric(array('server1'));
         $view->config->addSparklineMetric(array('server2'));
         $view->config->addTranslations(array('server1' => 'Evolution of temperature for server piwik.org'));
         $view->config->addTranslations(array('server2' => 'Evolution of temperature for server dev.piwik.org'));
     } elseif ($view->isViewDataTableId(Evolution::ID)) {
         /** @var Evolution $view */
         $selectableColumns = array('server1', 'server2');
         $columns = Common::getRequestVar('columns', false);
         if (!empty($columns)) {
             $columns = Piwik::getArrayFromApiParameter($columns);
         }
         $columns = array_merge($columns ? $columns : array(), $selectableColumns);
         $view->config->columns_to_display = $columns;
         $view->config->addTranslations(array_combine($columns, $columns));
         $view->config->selectable_columns = $selectableColumns;
         $view->requestConfig->filter_sort_column = 'label';
         $view->requestConfig->filter_sort_order = 'asc';
         $view->config->documentation = 'My documentation';
         $view->config->show_goals = false;
     }
 }
Example #2
0
 public function configureView(ViewDataTable $view)
 {
     if ($view->isViewDataTableId(BAR::ID)) {
         $view->config->y_axis_unit = '°C';
         $view->config->show_footer = false;
         $view->config->translations['value'] = "Temperature";
         $view->config->selectable_columns = array("value");
         $view->config->max_graph_elements = 24;
     } elseif ($view->isViewDataTableId('infoviz-treemap')) {
         $view->config->translations['value'] = "Temperature";
         $view->config->columns_to_display = array("label", "value");
         $view->config->selectable_columns = array("value");
         $view->config->show_evolution_values = 0;
     } else {
         // for default view datatable, eg HtmlTable
         $view->config->translations['value'] = 'Temperature in °C';
         $view->config->translations['label'] = 'Hour of day';
         $view->requestConfig->filter_sort_column = 'label';
         $view->requestConfig->filter_sort_order = 'asc';
         $view->requestConfig->filter_limit = 24;
         $view->config->columns_to_display = array('label', 'value');
         $view->config->y_axis_unit = '°C';
         // useful if the user requests the bar graph
         $view->config->show_exclude_low_population = false;
         $view->config->show_table_all_columns = false;
         $view->config->disable_row_evolution = true;
         $view->config->max_graph_elements = 24;
         $view->config->metrics_documentation = array('value' => 'Documentation for temperature metric');
     }
 }
Example #3
0
File: Get.php Project: piwik/piwik
 public function configureView(ViewDataTable $view)
 {
     if ($view->isViewDataTableId(Sparklines::ID)) {
         $view->requestConfig->apiMethodToRequestDataTable = 'VisitFrequency.get';
         $this->addSparklineColumns($view);
         $view->config->addTranslations($this->getSparklineTranslations());
         $numberFormatter = NumberFormatter::getInstance();
         $view->config->filters[] = function (DataTable $table) use($numberFormatter) {
             $firstRow = $table->getFirstRow();
             if ($firstRow) {
                 $value = $firstRow->getColumn('nb_visits_returning');
                 if (false !== $value) {
                     $firstRow->setColumn('nb_visits_returning', $numberFormatter->formatNumber($value));
                 }
                 $value = $firstRow->getColumn('nb_actions_returning');
                 if (false !== $value) {
                     $firstRow->setColumn('nb_actions_returning', $numberFormatter->formatNumber($value));
                 }
                 $value = $firstRow->getColumn('nb_actions_per_visit_returning');
                 if (false !== $value) {
                     $firstRow->setColumn('nb_actions_per_visit_returning', $numberFormatter->formatNumber($value, 1));
                 }
                 $value = $firstRow->getColumn('bounce_rate_returning');
                 if (false !== $value) {
                     $firstRow->setColumn('bounce_rate_returning', $numberFormatter->formatNumber($value, $precision = 1));
                 }
             }
         };
     }
 }
Example #4
0
 public function configureView(ViewDataTable $view)
 {
     $idSubtable = Common::getRequestVar('idSubtable', false);
     $labelColumnTitle = $this->name;
     switch ($idSubtable) {
         case Common::REFERRER_TYPE_SEARCH_ENGINE:
             $labelColumnTitle = Piwik::translate('Referrers_ColumnSearchEngine');
             break;
         case Common::REFERRER_TYPE_WEBSITE:
             $labelColumnTitle = Piwik::translate('Referrers_ColumnWebsite');
             break;
         case Common::REFERRER_TYPE_CAMPAIGN:
             $labelColumnTitle = Piwik::translate('Referrers_ColumnCampaign');
             break;
         default:
             break;
     }
     $view->config->show_search = false;
     $view->config->show_offset_information = false;
     $view->config->show_pagination_control = false;
     $view->config->show_limit_control = false;
     $view->config->show_exclude_low_population = false;
     $view->config->addTranslation('label', $labelColumnTitle);
     $view->requestConfig->filter_limit = 10;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_subtable_when_show_goals = true;
     }
 }
Example #5
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->show_exclude_low_population = false;
     $view->config->addTranslation('label', Piwik::translate('General_ColumnKeyword'));
     $view->requestConfig->filter_limit = 25;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_subtable_when_show_goals = true;
     }
 }
Example #6
0
 protected function getBasicDevicePluginsDisplayProperties(ViewDataTable $view)
 {
     $view->config->show_search = false;
     $view->config->show_exclude_low_population = false;
     $view->requestConfig->filter_limit = 5;
     if ($view->isViewDataTableId(Graph::ID)) {
         $view->config->max_graph_elements = 5;
     }
 }
Example #7
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->show_exclude_low_population = false;
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->requestConfig->filter_limit = 25;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_subtable_when_show_goals = true;
     }
 }
Example #8
0
 protected function addPresentationFilters(ViewDataTable $view, $addTotalSizeColumn = true, $addPercentColumn = false, $sizeColumns = array('data_size', 'index_size'))
 {
     // add total_size column
     if ($addTotalSizeColumn) {
         $getTotalTableSize = function ($dataSize, $indexSize) {
             return $dataSize + $indexSize;
         };
         $view->config->filters[] = array('ColumnCallbackAddColumn', array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), $isPriority = true);
         $sizeColumns[] = 'total_size';
     }
     $runPrettySizeFilterBeforeGeneric = false;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         // add summary row only if displaying a table
         $view->config->filters[] = array('AddSummaryRow', Piwik::translate('General_Total'));
         // add percentage column if desired
         if ($addPercentColumn && $addTotalSizeColumn) {
             $view->config->filters[] = array('ColumnCallbackAddColumnPercentage', array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, $shouldSkipRows = false, $getDivisorFromSummaryRow = true), $isPriority = false);
             $view->requestConfig->filter_sort_column = 'percent_total';
         }
     } else {
         if ($view->isViewDataTableId(Graph::ID)) {
             if ($addTotalSizeColumn) {
                 $view->config->columns_to_display = array('label', 'total_size');
                 // when displaying a graph, we force sizes to be shown as the same unit so axis labels
                 // will be readable. NOTE: The unit should depend on the smallest value of the data table,
                 // however there's no way to know this information, short of creating a custom filter. For
                 // now, just assume KB.
                 $fixedMemoryUnit = 'K';
                 $view->config->y_axis_unit = ' K';
                 $view->requestConfig->filter_sort_column = 'total_size';
                 $view->requestConfig->filter_sort_order = 'desc';
             } else {
                 $view->config->columns_to_display = array('label', 'row_count');
                 $view->config->y_axis_unit = ' ' . Piwik::translate('General_Rows');
                 $view->requestConfig->filter_sort_column = 'row_count';
                 $view->requestConfig->filter_sort_order = 'desc';
             }
             $view->config->selectable_rows = array();
         }
     }
     $formatter = new Formatter();
     $getPrettySize = array($formatter, 'getPrettySizeFromBytes');
     $params = !isset($fixedMemoryUnit) ? array() : array($fixedMemoryUnit);
     $view->config->filters[] = function ($dataTable) use($sizeColumns, $getPrettySize, $params) {
         $dataTable->filter('ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params));
     };
     // jqPlot will display   as, well, ' ', so don't replace the spaces when rendering as a graph
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $replaceSpaces = function ($value) {
             return str_replace(' ', ' ', $value);
         };
         $view->config->filters[] = array('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces));
     }
     $getPrettyNumber = array($formatter, 'getPrettyNumber');
     $view->config->filters[] = array('ColumnCallbackReplace', array('row_count', $getPrettyNumber));
 }
Example #9
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->addTranslations(array('label' => $this->dimension->getName()));
     $view->config->columns_to_display = array('label', 'nb_visits', 'nb_pages_per_search');
     $view->config->show_table_all_columns = false;
     $view->config->show_bar_chart = false;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_row_evolution = false;
     }
 }
Example #10
0
 public function configureViewDataTable(ViewDataTable $view)
 {
     if ($this->pluginName == $view->requestConfig->getApiModuleToRequest()) {
         if ($view->isRequestingSingleDataTable()) {
             // make sure custom visualizations are shown on actions reports
             $view->config->show_all_views_icons = true;
             $view->config->show_bar_chart = false;
             $view->config->show_pie_chart = false;
             $view->config->show_tag_cloud = false;
         }
     }
 }
Example #11
0
 public function configureView(ViewDataTable $view)
 {
     $referrers = new Referrers();
     $setGetAllHtmlPrefix = array($referrers, 'setGetAllHtmlPrefix');
     $view->config->show_exclude_low_population = false;
     $view->config->show_goals = true;
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->requestConfig->filter_limit = 20;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_row_actions = true;
     }
     $view->config->filters[] = array('MetadataCallbackAddMetadata', array('referer_type', 'html_label_prefix', $setGetAllHtmlPrefix));
 }
 /**
  * Here you can configure how your report should be displayed. For instance whether your report supports a search
  * etc. You can also change the default request config. For instance change how many rows are displayed by default.
  *
  * @param ViewDataTable $view
  */
 public function configureView(ViewDataTable $view)
 {
     $idDimension = Common::getRequestVar('idDimension', 0, 'int');
     if ($idDimension < 1) {
         return;
     }
     $isWidget = Common::getRequestVar('widget', 0, 'int');
     $module = Common::getRequestVar('module', '', 'string');
     if ($isWidget && $module !== 'Widgetize' && $view->isViewDataTableId(HtmlTable::ID)) {
         // we disable row evolution as it would not forward the idDimension when requesting the row evolution
         // this is a limitation in row evolution
         $view->config->disable_row_evolution = true;
     }
     $module = $view->requestConfig->getApiModuleToRequest();
     $method = $view->requestConfig->getApiMethodToRequest();
     $idReport = sprintf('%s_%s_idDimension--%d', $module, $method, $idDimension);
     if ($view->requestConfig->idSubtable) {
         $view->config->addTranslation('label', Piwik::translate('Actions_ColumnActionURL'));
     } elseif (!empty($this->dimension)) {
         $view->config->addTranslation('label', $this->dimension->getName());
     }
     $view->requestConfig->request_parameters_to_modify['idDimension'] = $idDimension;
     $view->requestConfig->request_parameters_to_modify['reportUniqueId'] = $idReport;
     $view->config->custom_parameters['scopeOfDimension'] = $this->scopeOfDimension;
     if ($this->scopeOfDimension === CustomDimensions::SCOPE_VISIT) {
         // Goal metrics for each custom dimension  of 'visit' scope is processed in Archiver via aggregateFromConversions
         $view->config->show_goals = true;
         $view->config->columns_to_display = array('label', 'nb_visits', 'nb_uniq_visitors', 'nb_users', 'nb_actions', 'nb_actions_per_visit', 'avg_time_on_site', 'bounce_rate');
         $view->config->filters[] = function (DataTable $table) use($view) {
             $userId = new UserId();
             if (!$userId->hasDataTableUsers($table)) {
                 $view->config->removeColumnToDisplay('nb_users');
             }
             if ($table->getRowsCount() > 0 && !$table->getFirstRow()->hasColumn('nb_uniq_visitors')) {
                 $view->config->removeColumnToDisplay('nb_uniq_visitors');
             }
         };
     } elseif ($this->scopeOfDimension === CustomDimensions::SCOPE_ACTION) {
         $view->config->columns_to_display = array('label', 'nb_hits', 'nb_visits', 'bounce_rate', 'avg_time_on_dimension', 'exit_rate', 'avg_time_generation');
         $formatter = new Metrics\Formatter();
         // add avg_generation_time tooltip
         $tooltipCallback = function ($hits, $min, $max) use($formatter) {
             if (!$hits) {
                 return false;
             }
             return Piwik::translate("Actions_AvgGenerationTimeTooltip", array($hits, "<br />", $formatter->getPrettyTimeFromSeconds($min, true), $formatter->getPrettyTimeFromSeconds($max, true)));
         };
         $view->config->filters[] = array('ColumnCallbackAddMetadata', array(array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'), 'avg_time_generation_tooltip', $tooltipCallback));
     }
     $view->config->show_table_all_columns = false;
 }
Example #13
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->show_exclude_low_population = false;
     $view->config->show_goals = true;
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->requestConfig->filter_limit = 10;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_subtable_when_show_goals = true;
     }
     $widget = Common::getRequestVar('widget', false);
     if (empty($widget)) {
         $view->config->show_footer_message = Piwik::translate('Referrers_SocialFooterMessage');
     }
 }
Example #14
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->addTranslation('value', 'times the diameter of Earth');
     if ($view->isViewDataTableId(PIE::ID)) {
         $view->config->columns_to_display = array('value');
         $view->config->selectable_columns = array('value');
         $view->config->show_footer_icons = false;
         $view->config->max_graph_elements = 10;
     } else {
         if ($view->isViewDataTableId(Cloud::ID)) {
             $view->config->columns_to_display = array('label', 'value');
             $view->config->show_footer = false;
         }
     }
 }
Example #15
0
File: Get.php Project: piwik/piwik
 public function configureView(ViewDataTable $view)
 {
     if ($view->isViewDataTableId(Sparklines::ID)) {
         /** @var Sparklines $view */
         $view->requestConfig->apiMethodToRequestDataTable = 'API.get';
         $this->addSparklineColumns($view);
         $view->config->addTranslations($this->getSparklineTranslations());
         $numberFormatter = NumberFormatter::getInstance();
         $view->config->filters[] = function (DataTable $table) use($view, $numberFormatter) {
             $firstRow = $table->getFirstRow();
             if ($firstRow->getColumn('nb_pageviews') + $firstRow->getColumn('nb_downloads') + $firstRow->getColumn('nb_outlinks') == 0 && $firstRow->getColumn('nb_actions') > 0) {
                 $view->config->removeSparklineMetric(array('nb_downloads', 'nb_uniq_downloads'));
                 $view->config->removeSparklineMetric(array('nb_outlinks', 'nb_uniq_outlinks'));
                 $view->config->removeSparklineMetric(array('nb_pageviews', 'nb_uniq_pageviews'));
                 $view->config->removeSparklineMetric(array('nb_searches', 'nb_keywords'));
             } else {
                 $view->config->removeSparklineMetric(array('nb_actions'));
             }
             $nbUsers = $firstRow->getColumn('nb_users');
             if (!is_numeric($nbUsers) || 0 >= $nbUsers) {
                 $view->config->replaceSparklineMetric(array('nb_users'), '');
             }
             $avgGenerationTime = $firstRow->getColumn('avg_time_generation');
             if (false === $avgGenerationTime) {
                 // fix avgGenerationTime is not formatted if value is false
                 /** @var Formatter $formatter */
                 $formatter = StaticContainer::get('Piwik\\Metrics\\Formatter');
                 $avgGenerationTime = $formatter->getPrettyTimeFromSeconds($avgGenerationTime, true);
                 $firstRow->setColumn('avg_time_generation', $avgGenerationTime);
             }
             $numberMetrics = array('nb_visits', 'nb_uniq_visitors', 'nb_uniq_visitors', 'nb_users', 'nb_actions', 'nb_pageviews', 'nb_uniq_pageviews', 'nb_searches', 'nb_keywords', 'nb_downloads', 'nb_uniq_downloads', 'nb_outlinks', 'nb_uniq_outlinks', 'max_actions');
             foreach ($numberMetrics as $metric) {
                 $value = $firstRow->getColumn($metric);
                 if (false !== $value) {
                     $firstRow->setColumn($metric, $numberFormatter->formatNumber($value));
                 }
             }
             $value = $firstRow->getColumn('bounce_rate');
             if (false !== $value) {
                 $firstRow->setColumn('bounce_rate', $numberFormatter->formatPercent($value, $precision = 1));
             }
             $value = $firstRow->getColumn('nb_actions_per_visit');
             if (false !== $value) {
                 $firstRow->setColumn('nb_actions_per_visit', $numberFormatter->formatNumber($value, $maxFraction = 1));
             }
         };
     }
 }
 public function configureView(ViewDataTable $view)
 {
     $view->requestConfig->filter_sort_column = 'label';
     $view->requestConfig->filter_sort_order = 'asc';
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->config->enable_sort = false;
     $view->config->show_exclude_low_population = false;
     $view->config->show_offset_information = false;
     $view->config->show_pagination_control = false;
     $view->config->show_limit_control = false;
     $view->config->show_search = false;
     $view->config->show_table_all_columns = false;
     $view->config->columns_to_display = array('label', 'nb_visits');
     if ($view->isViewDataTableId(Graph::ID)) {
         $view->config->show_series_picker = false;
         $view->config->selectable_columns = array();
         $view->config->max_graph_elements = 10;
     }
 }
Example #17
0
 /**
  * @param ViewDataTable $view
  */
 public function configureView(ViewDataTable $view)
 {
     $view->config->addTranslation('label', Piwik::translate('General_UserId'));
     $view->config->addTranslation('nb_visits_converted', Piwik::translate('General_VisitConvertedGoal'));
     /*
      * Hide most of the table footer actions, leaving only export icons and pagination
      */
     $view->config->columns_to_display = $this->metrics;
     $view->config->show_all_views_icons = false;
     $view->config->show_active_view_icon = false;
     $view->config->show_related_reports = false;
     $view->config->show_insights = false;
     $view->config->show_pivot_by_subtable = false;
     $view->config->show_flatten_table = false;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_row_evolution = false;
     }
     // exclude users with less then 2 visits, when low population filter is active
     $view->requestConfig->filter_excludelowpop_value = 2;
 }
Example #18
0
File: Base.php Project: piwik/piwik
 protected function addBaseDisplayProperties(ViewDataTable $view)
 {
     $view->config->datatable_js_type = 'ActionsDataTable';
     $view->config->search_recursive = true;
     $view->config->show_table_all_columns = false;
     $view->requestConfig->filter_limit = Actions::ACTIONS_REPORT_ROWS_DISPLAY;
     $view->config->show_all_views_icons = false;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->show_embedded_subtable = true;
     }
     if (Request::shouldLoadExpanded()) {
         if ($view->isViewDataTableId(HtmlTable::ID)) {
             $view->config->show_expanded = true;
         }
         $view->config->filters[] = function ($dataTable) {
             Actions::setDataTableRowLevels($dataTable);
         };
     }
     $view->config->filters[] = function ($dataTable) use($view) {
         if ($view->isViewDataTableId(HtmlTable::ID)) {
             $view->config->datatable_css_class = 'dataTableActions';
         }
     };
 }
Example #19
0
 public function configureViewForSiteSearchCategories(ViewDataTable $view)
 {
     $view->config->addTranslations(array('label' => Piwik::translate('Actions_ColumnSearchCategory'), 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), 'nb_pages_per_search' => Piwik::translate('Actions_ColumnPagesPerSearch')));
     $view->config->columns_to_display = array('label', 'nb_visits', 'nb_pages_per_search');
     $view->config->show_table_all_columns = false;
     $view->config->show_bar_chart = false;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_row_evolution = false;
     }
 }
Example #20
0
 protected function configureViewForByDayOfWeek(ViewDataTable $view)
 {
     $view->requestConfig->filter_limit = 7;
     $view->config->enable_sort = false;
     $view->config->show_footer_message = Piwik::translate('General_ReportGeneratedFrom', self::getDateRangeForFooterMessage());
     $view->config->addTranslation('label', Piwik::translate('VisitTime_DayOfWeek'));
     if ($view->isViewDataTableId(Graph::ID)) {
         $view->config->max_graph_elements = false;
         $view->config->show_all_ticks = true;
     }
 }
Example #21
0
File: Get.php Project: piwik/piwik
 public function configureView(ViewDataTable $view)
 {
     $idGoal = Common::getRequestVar('idGoal', 0, 'string');
     $idSite = $this->getIdSite();
     if ($view->isViewDataTableId(Sparklines::ID)) {
         /** @var Sparklines $view */
         $isEcommerceEnabled = $this->isEcommerceEnabled($idSite);
         $onlySummary = Common::getRequestVar('only_summary', 0, 'int');
         if ($onlySummary && !empty($idGoal)) {
             if (is_numeric($idGoal)) {
                 $view->config->title_attributes = array('piwik-goal-page-link' => $idGoal);
             }
             // in Goals overview summary we show proper title for a goal
             $goal = $this->getGoal($idGoal);
             if (!empty($goal['name'])) {
                 $view->config->title = Piwik::translate('Goals_GoalX', "'" . $goal['name'] . "'");
             }
         } else {
             $view->config->title = '';
         }
         $numberFormatter = NumberFormatter::getInstance();
         $view->config->filters[] = function (DataTable $table) use($numberFormatter, $idSite) {
             $firstRow = $table->getFirstRow();
             if ($firstRow) {
                 $revenue = $firstRow->getColumn('revenue');
                 $currencySymbol = Site::getCurrencySymbolFor($idSite);
                 $revenue = $numberFormatter->formatCurrency($revenue, $currencySymbol, GoalManager::REVENUE_PRECISION);
                 $firstRow->setColumn('revenue', $revenue);
                 $conversionRate = $firstRow->getColumn('conversion_rate');
                 if (false !== $conversionRate) {
                     $firstRow->setColumn('conversion_rate', $numberFormatter->formatPercent($conversionRate, $precision = 1));
                 }
                 $conversions = $firstRow->getColumn('nb_conversions');
                 if (false !== $conversions) {
                     $firstRow->setColumn('nb_conversions', $numberFormatter->formatNumber($conversions));
                 }
                 $visitsConverted = $firstRow->getColumn('nb_visits_converted');
                 if (false !== $visitsConverted) {
                     $firstRow->setColumn('nb_visits_converted', $numberFormatter->formatNumber($visitsConverted));
                 }
             }
         };
         $view->config->addTranslations(array('nb_visits' => Piwik::translate('VisitsSummary_NbVisitsDescription'), 'nb_conversions' => Piwik::translate('Goals_ConversionsDescription'), 'nb_visits_converted' => Piwik::translate('General_NVisits'), 'conversion_rate' => Piwik::translate('Goals_OverallConversionRate'), 'revenue' => Piwik::translate('Goals_OverallRevenue')));
         $allowMultiple = Common::getRequestVar('allow_multiple', 0, 'int');
         if ($allowMultiple) {
             $view->config->addSparklineMetric(array('nb_conversions', 'nb_visits_converted'), $order = 10);
         } else {
             $view->config->addSparklineMetric(array('nb_conversions'), $order = 10);
         }
         $view->config->addSparklineMetric(array('conversion_rate'), $order = 20);
         if (empty($idGoal)) {
             // goals overview sparklines below evolution graph
             if ($isEcommerceEnabled) {
                 // this would be ideally done in Ecommerce plugin but then it is hard to keep same order
                 $view->config->addSparklineMetric(array('revenue'), $order = 30);
             }
         } else {
             if ($onlySummary) {
                 // in Goals Overview we list an overview for each goal....
                 $view->config->addTranslation('conversion_rate', Piwik::translate('Goals_ConversionRate'));
             } elseif ($isEcommerceEnabled) {
                 // in Goals detail page...
                 $view->config->addSparklineMetric(array('revenue'), $order = 30);
             }
         }
     } else {
         if ($view->isViewDataTableId(Evolution::ID)) {
             if (!empty($idSite) && Piwik::isUserHasAdminAccess($idSite)) {
                 $view->config->title_edit_entity_url = 'index.php' . Url::getCurrentQueryStringWithParametersModified(array('module' => 'Goals', 'action' => 'manage', 'forceView' => null, 'viewDataTable' => null, 'showtitle' => null, 'random' => null));
             }
             $goal = $this->getGoal($idGoal);
             if (!empty($goal['name'])) {
                 $view->config->title = Piwik::translate('Goals_GoalX', "'" . $goal['name'] . "'");
                 if (!empty($goal['description'])) {
                     $view->config->description = $goal['description'];
                 }
             } else {
                 $view->config->title = Piwik::translate('General_EvolutionOverPeriod');
             }
             if (empty($view->config->columns_to_display)) {
                 $view->config->columns_to_display = array('nb_conversions');
             }
         }
     }
 }
Example #22
0
 public function configureViewDataTable(ViewDataTable $view)
 {
     if ($view->requestConfig->getApiModuleToRequest() != 'Events') {
         return;
     }
     // eg. 'Events.getCategory'
     $apiMethod = $view->requestConfig->getApiMethodToRequest();
     $secondaryDimension = $this->getSecondaryDimensionFromRequest();
     $view->config->subtable_controller_action = API::getInstance()->getActionToLoadSubtables($apiMethod, $secondaryDimension);
     $pivotBy = Common::getRequestVar('pivotBy', false);
     if (empty($pivotBy)) {
         $view->config->columns_to_display = array('label', 'nb_events', 'sum_event_value');
     }
     $view->config->show_flatten_table = true;
     $view->requestConfig->filter_sort_column = 'nb_events';
     if ($view->isViewDataTableId(AllColumns::ID)) {
         $view->config->filters[] = function (DataTable $table) use($view) {
             $columsToDisplay = array('label');
             $columns = $table->getColumns();
             if (in_array('nb_visits', $columns)) {
                 $columsToDisplay[] = 'nb_visits';
             }
             if (in_array('nb_uniq_visitors', $columns)) {
                 $columsToDisplay[] = 'nb_uniq_visitors';
             }
             $view->config->columns_to_display = array_merge($columsToDisplay, array('nb_events', 'sum_event_value', 'avg_event_value', 'min_event_value', 'max_event_value'));
             if (!in_array($view->requestConfig->filter_sort_column, $view->config->columns_to_display)) {
                 $view->requestConfig->filter_sort_column = 'nb_events';
             }
         };
         $view->config->show_pivot_by_subtable = false;
     }
     $labelTranslation = $this->getColumnTranslation($apiMethod);
     $view->config->addTranslation('label', $labelTranslation);
     $view->config->addTranslations($this->getMetricTranslations());
     $this->addRelatedReports($view, $secondaryDimension);
     $this->addTooltipEventValue($view);
     $subtableReport = ReportsProvider::factory('Events', $view->config->subtable_controller_action);
     $view->config->pivot_by_dimension = $subtableReport->getDimension()->getId();
     $view->config->pivot_by_column = 'nb_events';
 }
Example #23
0
 public final function __construct($controllerAction, $apiMethodToRequestDataTable, $params = array())
 {
     $templateFile = static::TEMPLATE_FILE;
     if (empty($templateFile)) {
         throw new \Exception('You have not defined a constant named TEMPLATE_FILE in your visualization class.');
     }
     $this->metricsFormatter = new HtmlFormatter();
     parent::__construct($controllerAction, $apiMethodToRequestDataTable, $params);
     $this->report = Report::factory($this->requestConfig->getApiModuleToRequest(), $this->requestConfig->getApiMethodToRequest());
 }
Example #24
0
 private function configureViewForGetSocials(ViewDataTable $view)
 {
     $view->config->subtable_controller_action = 'getUrlsForSocial';
     $view->config->show_exclude_low_population = false;
     $view->config->show_goals = true;
     $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnSocial'));
     $view->requestConfig->filter_limit = 10;
     if ($view->isViewDataTableId(HtmlTable::ID)) {
         $view->config->disable_subtable_when_show_goals = true;
     }
     $widget = Common::getRequestVar('widget', false);
     if (empty($widget)) {
         $view->config->show_footer_message = Piwik::translate('Referrers_SocialFooterMessage');
     }
 }
Example #25
0
 public final function __construct($controllerAction, $apiMethodToRequestDataTable, $params = array())
 {
     $templateFile = static::TEMPLATE_FILE;
     if (empty($templateFile)) {
         throw new \Exception('You have not defined a constant named TEMPLATE_FILE in your visualization class.');
     }
     parent::__construct($controllerAction, $apiMethodToRequestDataTable, $params);
 }
Example #26
0
 private function configureViewForGetNumberOfVisitsPerPage(ViewDataTable $view)
 {
     $view->requestConfig->filter_sort_column = 'label';
     $view->requestConfig->filter_sort_order = 'asc';
     $view->config->addTranslation('label', Piwik::translate('VisitorInterest_ColumnVisitDuration'));
     $view->config->enable_sort = false;
     $view->config->show_exclude_low_population = false;
     $view->config->show_offset_information = false;
     $view->config->show_pagination_control = false;
     $view->config->show_limit_control = false;
     $view->config->show_search = false;
     $view->config->show_table_all_columns = false;
     $view->config->columns_to_display = array('label', 'nb_visits');
     if ($view->isViewDataTableId(Graph::ID)) {
         $view->config->show_series_picker = false;
         $view->config->selectable_columns = array();
         $view->config->max_graph_elements = 10;
     }
 }