diff --git a/core/Plugin/Visualization.php b/core/Plugin/Visualization.php index c953f641453..ae73d4b769e 100644 --- a/core/Plugin/Visualization.php +++ b/core/Plugin/Visualization.php @@ -61,7 +61,7 @@ protected function buildView() $this->beforeLoadDataTable(); - $this->loadDataTableFromAPI(array('disable_generic_filters' => 1)); + $this->loadDataTableFromAPI(array('disable_generic_filters' => 1, 'disable_queued_filters' => 1)); $this->postDataTableLoadedFromAPI(); $requestPropertiesAfterLoadDataTable = $this->requestConfig->getProperties(); @@ -194,7 +194,7 @@ private function applyFilters() $this->beforeGenericFiltersAreAppliedToLoadedDataTable(); - if (!$this->config->areGenericFiltersDisabled()) { + if (!$this->requestConfig->areGenericFiltersDisabled()) { $this->applyGenericFilters(); } @@ -207,7 +207,7 @@ private function applyFilters() // Finally, apply datatable filters that were queued (should be 'presentation' filters that // do not affect the number of rows) - if (!$this->config->areQueuedFiltersDisabled()) { + if (!$this->requestConfig->areQueuedFiltersDisabled()) { $this->dataTable->applyQueuedFilters(); } } diff --git a/core/ViewDataTable/Config.php b/core/ViewDataTable/Config.php index 233f9f21c8e..7e4119ed9e0 100644 --- a/core/ViewDataTable/Config.php +++ b/core/ViewDataTable/Config.php @@ -38,8 +38,6 @@ class Config */ public $overridableProperties = array( 'show_goals', - 'disable_generic_filters', - 'disable_queued_filters', 'show_exclude_low_population', 'show_flatten_table', 'show_table', @@ -235,24 +233,6 @@ class Config */ public $custom_parameters = array(); - /** - * Whether to run generic filters on the DataTable before rendering or not. - * - * @see Piwik_API_DataTableGenericFilter - * - * Default value: false - */ - public $disable_generic_filters = false; - - /** - * Whether to run ViewDataTable's list of queued filters or not. - * - * NOTE: Priority queued filters are always run. - * - * Default value: false - */ - public $disable_queued_filters = false; - /** * Controls whether the limit dropdown (which allows users to change the number of data shown) * is always shown or not. @@ -496,35 +476,6 @@ public function getProperties() return get_object_vars($this); } - /** - * Returns true if queued filters have been disabled, false if otherwise. - * - * @return bool - */ - public function areQueuedFiltersDisabled() - { - return isset($this->disable_queued_filters) && $this->disable_queued_filters; - } - - /** - * Returns true if generic filters have been disabled, false if otherwise. - * - * @return bool - */ - public function areGenericFiltersDisabled() - { - // if disable_generic_filters query param is set to '1', generic filters are disabled - if (Common::getRequestVar('disable_generic_filters', '0', 'string') == 1) { - return true; - } - - if (isset($this->disable_generic_filters) && true === $this->disable_generic_filters) { - return true; - } - - return false; - } - public function setDefaultColumnsToDisplay($columns, $hasNbVisits, $hasNbUniqVisitors) { if ($hasNbVisits || $hasNbUniqVisitors) { diff --git a/core/ViewDataTable/RequestConfig.php b/core/ViewDataTable/RequestConfig.php index c92b0a3ef70..2e9a83092bf 100644 --- a/core/ViewDataTable/RequestConfig.php +++ b/core/ViewDataTable/RequestConfig.php @@ -10,6 +10,7 @@ */ namespace Piwik\ViewDataTable; +use Piwik\Common; /** * Renders a sparkline image given a PHP data array. @@ -43,7 +44,9 @@ class RequestConfig 'filter_pattern', 'filter_column', 'filter_excludelowpop', - 'filter_excludelowpop_value' + 'filter_excludelowpop_value', + 'disable_generic_filters', + 'disable_queued_filters' ); /** @@ -119,6 +122,24 @@ class RequestConfig */ public $request_parameters_to_modify = array(); + /** + * Whether to run generic filters on the DataTable before rendering or not. + * + * @see Piwik_API_DataTableGenericFilter + * + * Default value: false + */ + public $disable_generic_filters = false; + + /** + * Whether to run ViewDataTable's list of queued filters or not. + * + * NOTE: Priority queued filters are always run. + * + * Default value: false + */ + public $disable_queued_filters = false; + public $apiMethodToRequestDataTable = ''; /** @@ -159,6 +180,35 @@ public function setDefaultSort($columnsToDisplay, $hasNbUniqVisitors) $this->filter_sort_order = 'desc'; } + /** + * Returns true if queued filters have been disabled, false if otherwise. + * + * @return bool + */ + public function areQueuedFiltersDisabled() + { + return isset($this->disable_queued_filters) && $this->disable_queued_filters; + } + + /** + * Returns true if generic filters have been disabled, false if otherwise. + * + * @return bool + */ + public function areGenericFiltersDisabled() + { + // if disable_generic_filters query param is set to '1', generic filters are disabled + if (Common::getRequestVar('disable_generic_filters', '0', 'string') == 1) { + return true; + } + + if (isset($this->disable_generic_filters) && true === $this->disable_generic_filters) { + return true; + } + + return false; + } + public function getApiModuleToRequest() { list($module, $method) = explode('.', $this->apiMethodToRequestDataTable); diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index c059ebc89e7..06bd38fd1f0 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -25,12 +25,22 @@ public function dataTables() $controllerAction = $this->pluginName . '.' . __FUNCTION__; $apiAction = 'ExampleUI.getTemperatures'; - /** - * this is an example how you can make a custom visualization reusable. - */ - $table = new CustomDataTable(); + $view = Factory::build('table', $apiAction, $controllerAction); - echo $table->render('Temperature in °C', 'Hour of day', $apiAction, $controllerAction); + $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'); + + echo $view->render(); } public function evolutionGraph() diff --git a/plugins/ExampleUI/CustomDataTable.php b/plugins/ExampleUI/CustomDataTable.php deleted file mode 100644 index c7009d7c815..00000000000 --- a/plugins/ExampleUI/CustomDataTable.php +++ /dev/null @@ -1,38 +0,0 @@ -config->translations['value'] = $value; - $view->config->translations['label'] = $label; - $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; - - return $view->render(); - } - -} \ No newline at end of file diff --git a/plugins/Live/Live.php b/plugins/Live/Live.php index fd73ccadf13..e1640cb353e 100644 --- a/plugins/Live/Live.php +++ b/plugins/Live/Live.php @@ -35,7 +35,6 @@ public function getListHooksRegistered() 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'WidgetsList.addWidgets' => 'addWidget', 'Menu.Reporting.addItems' => 'addMenu', - 'ViewDataTable.configure' => 'configureViewDataTable', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'ViewDataTable.getDefaultType' => 'getDefaultTypeViewDataTable' ); @@ -76,59 +75,8 @@ public function getClientSideTranslationKeys(&$translationKeys) $translationKeys[] = "Live_PageRefreshed"; } - public function configureViewDataTable(ViewDataTable $view) - { - switch ($view->requestConfig->apiMethodToRequestDataTable) { - case 'Live.getLastVisitsDetails': - $this->configureViewForGetLastVisitsDetails($view); - break; - } - } - public function getDefaultTypeViewDataTable(&$defaultViewTypes) { $defaultViewTypes['Live.getLastVisitsDetails'] = VisitorLog::ID; } - - private function configureViewForGetLastVisitsDetails(ViewDataTable $view) - { - $view->config->disable_generic_filters = true; - $view->config->enable_sort = false; - $view->config->show_search = false; - $view->config->show_exclude_low_population = false; - $view->config->show_offset_information = false; - $view->config->show_all_views_icons = false; - $view->config->show_table_all_columns = false; - $view->config->show_export_as_rss_feed = false; - - $view->requestConfig->filter_sort_column = 'idVisit'; - $view->requestConfig->filter_sort_order = 'asc'; - $view->requestConfig->filter_limit = 20; - - $view->config->documentation = Piwik::translate('Live_VisitorLogDocumentation', array('
', '
')); - $view->config->custom_parameters = array( - // set a very high row count so that the next link in the footer of the data table is always shown - 'totalRows' => 10000000, - - 'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'), - 'pageUrlNotDefined' => Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL')) - ); - - $view->config->footer_icons = array( - array( - 'class' => 'tableAllColumnsSwitch', - 'buttons' => array( - array( - 'id' => 'Piwik\\Plugins\\Live\\VisitorLog', - 'title' => Piwik::translate('Live_LinkVisitorLog'), - 'icon' => 'plugins/Zeitgeist/images/table.png' - ) - ) - ) - ); - - if ($view->isViewDataTableId(HtmlTable::ID)) { - $view->config->disable_row_actions = true; - } - } } \ No newline at end of file diff --git a/plugins/Live/VisitorLog.php b/plugins/Live/VisitorLog.php index 4fd5ffd5aa9..c886b3c2015 100644 --- a/plugins/Live/VisitorLog.php +++ b/plugins/Live/VisitorLog.php @@ -10,6 +10,8 @@ */ namespace Piwik\Plugins\Live; +use Piwik\Common; +use Piwik\Piwik; use Piwik\View; use Piwik\Plugin\Visualization; @@ -29,6 +31,11 @@ public function beforeLoadDataTable() 'filter_sort_column', 'filter_sort_order', )); + + $this->requestConfig->filter_sort_column = 'idVisit'; + $this->requestConfig->filter_sort_order = 'asc'; + $this->requestConfig->filter_limit = 20; + $this->requestConfig->disable_generic_filters = true; } /** @@ -37,5 +44,34 @@ public function beforeLoadDataTable() public function beforeRender() { $this->config->datatable_js_type = 'VisitorLog'; + $this->config->enable_sort = false; + $this->config->show_search = false; + $this->config->show_exclude_low_population = false; + $this->config->show_offset_information = false; + $this->config->show_all_views_icons = false; + $this->config->show_table_all_columns = false; + $this->config->show_export_as_rss_feed = false; + + $this->config->documentation = Piwik::translate('Live_VisitorLogDocumentation', array('
', '
')); + $this->config->custom_parameters = array( + // set a very high row count so that the next link in the footer of the data table is always shown + 'totalRows' => 10000000, + + 'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'), + 'pageUrlNotDefined' => Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL')) + ); + + $this->config->footer_icons = array( + array( + 'class' => 'tableAllColumnsSwitch', + 'buttons' => array( + array( + 'id' => 'Piwik\\Plugins\\Live\\VisitorLog', + 'title' => Piwik::translate('Live_LinkVisitorLog'), + 'icon' => 'plugins/Zeitgeist/images/table.png' + ) + ) + ) + ); } } \ No newline at end of file