diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-10-18 03:32:40 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-10-18 03:32:40 +0400 |
commit | 198e5ed07d0d51b37d377aba052142014120a743 (patch) | |
tree | dbcfefa3d229795359c67322020da1237f660a70 | |
parent | 2413dcdfe88b16edc96c9ee535c33d787cd88896 (diff) |
refactored hook getReportDisplayProperties. Reports/Plugins can now directly change the viewDataTable and there is support for auto completion now
-rw-r--r-- | core/Plugin/ViewDataTable.php | 103 | ||||
-rw-r--r-- | core/Plugin/Visualization.php | 5 | ||||
-rw-r--r-- | core/ViewDataTable.php | 75 | ||||
-rw-r--r-- | core/ViewDataTable/Config.php | 19 | ||||
-rw-r--r-- | plugins/Actions/Actions.php | 472 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Controller.php | 2 | ||||
-rw-r--r-- | plugins/CustomVariables/CustomVariables.php | 66 | ||||
-rw-r--r-- | plugins/DBStats/DBStats.php | 284 | ||||
-rw-r--r-- | plugins/DevicesDetection/DevicesDetection.php | 133 | ||||
-rw-r--r-- | plugins/Goals/Goals.php | 172 | ||||
-rw-r--r-- | plugins/Live/Live.php | 82 | ||||
-rw-r--r-- | plugins/Provider/Provider.php | 33 | ||||
-rw-r--r-- | plugins/Referrers/Referrers.php | 293 | ||||
-rw-r--r-- | plugins/UserCountry/UserCountry.php | 134 | ||||
-rw-r--r-- | plugins/UserSettings/UserSettings.php | 251 | ||||
-rw-r--r-- | plugins/VisitTime/VisitTime.php | 122 | ||||
-rw-r--r-- | plugins/VisitorInterest/VisitorInterest.php | 160 |
17 files changed, 1192 insertions, 1214 deletions
diff --git a/core/Plugin/ViewDataTable.php b/core/Plugin/ViewDataTable.php index e2545091c0..f3c7350775 100644 --- a/core/Plugin/ViewDataTable.php +++ b/core/Plugin/ViewDataTable.php @@ -24,8 +24,8 @@ use Piwik\Site; use Piwik\View; use Piwik\View\ViewInterface; use Piwik\ViewDataTable\Config as VizConfig; +use Piwik\ViewDataTable\Request as ViewDataTableRequest; use Piwik\ViewDataTable\RequestConfig as VizRequest; -use \Piwik\ViewDataTable\Request as ViewDataTableRequest; /** * This class is used to load (from the API) and customize the output of a given DataTable. @@ -90,7 +90,7 @@ abstract class ViewDataTable implements ViewInterface /** * Default constructor. */ - public function __construct($controllerAction, $apiMethodToRequestDataTable, $defaultReportProperties) + public function __construct($controllerAction, $apiMethodToRequestDataTable) { list($controllerName, $controllerAction) = explode('.', $controllerAction); @@ -101,15 +101,30 @@ abstract class ViewDataTable implements ViewInterface $this->request = new ViewDataTableRequest($this->requestConfig); - $this->setViewProperties($defaultReportProperties); - $this->requestConfig->idSubtable = Common::getRequestVar('idSubtable', false, 'int'); - - $this->config->show_footer_icons = (false == $this->requestConfig->idSubtable); $this->config->self_url = Request::getBaseReportUrl($controllerName, $controllerAction); $this->requestConfig->apiMethodToRequestDataTable = $apiMethodToRequestDataTable; + /** + * This event is triggered to gather the report display properties for each available report. If you define + * your own report, you want to subscribe to this event to define how your report shall be displayed in the + * Piwik UI. + * + * public function configureViewDataTable(ViewDataTable $view) + * { + * switch ($view->requestConfig->apiMethodToRequestDataTable) { + * case 'VisitTime.getVisitInformationPerServerTime': + * $view->config->enable_sort = true; + * $view->requestConfig->filter_limit = 10; + * break; + * } + * } + */ + Piwik::postEvent('ViewDataTable.configure', array($this)); + + $this->config->show_footer_icons = (false == $this->requestConfig->idSubtable); + // the exclude low population threshold value is sometimes obtained by requesting data. // to avoid issuing unecessary requests when display properties are determined by metadata, // we allow it to be a closure. @@ -167,9 +182,9 @@ abstract class ViewDataTable implements ViewInterface public function isViewDataTableId($viewDataTableId) { - $myId = static::getViewDataTableId(); + $myIds = static::getIdsWithInheritance(get_called_class()); - return $myId == $viewDataTableId; + return in_array($viewDataTableId, $myIds); } /** @@ -199,78 +214,6 @@ abstract class ViewDataTable implements ViewInterface $this->dataTable = $dataTable; } - private function setViewProperties($values) - { - foreach ($values as $name => $value) { - $this->setViewProperty($name, $value); - } - } - - /** - * Sets a view property by name. This function handles special view properties - * like 'translations' & 'related_reports' that store arrays. - * - * @param string $name - * @param mixed $value For array properties, $value can be a comma separated string. - * @throws \Exception - */ - protected function setViewProperty($name, $value) - { - if (isset($this->requestConfig->$name) - && is_array($this->requestConfig->$name) - && is_string($value) - ) { - $value = Piwik::getArrayFromApiParameter($value); - } - - if (isset($this->config->$name) - && is_array($this->config->$name) - && is_string($value) - ) { - $value = Piwik::getArrayFromApiParameter($value); - } - - if ($name == 'translations' - || $name == 'filters' - ) { - $this->config->$name = array_merge($this->config->$name, $value); - } else if ($name == 'related_reports') { // TODO: should process after (in overrideViewProperties) - $this->config->addRelatedReports($value); - } else if ($name == 'visualization_properties') { - $this->setVisualizationPropertiesFromMetadata($value); - } elseif (property_exists($this->requestConfig, $name)) { - $this->requestConfig->$name = $value; - } else if (property_exists($this->config, $name)) { - $this->config->$name = $value; - } else { - $report = $this->config->controllerName . '.' . $this->config->controllerAction; - throw new \Exception("Invalid view property '$name' specified in view property metadata for '$report'."); - } - } - - /** - * Sets visualization properties using data in a visualization's default property values - * array. - */ - protected function setVisualizationPropertiesFromMetadata($properties) - { - if (!is_array($properties)) { - Log::debug('Cannot set properties from metadata, $properties is not an array'); - return null; - } - - // TODO parent class should not know anything about children - $visualizationIds = static::getIdsWithInheritance(get_class($this)); - - foreach ($visualizationIds as $visualizationId) { - if (empty($properties[$visualizationId])) { - continue; - } - - $this->setViewProperties($properties[$visualizationId]); - } - } - /** * Returns the viewDataTable IDs of a visualization's class lineage. * diff --git a/core/Plugin/Visualization.php b/core/Plugin/Visualization.php index a0a46d8c06..0c4cb03b5b 100644 --- a/core/Plugin/Visualization.php +++ b/core/Plugin/Visualization.php @@ -37,11 +37,10 @@ use Piwik\View; class Visualization extends ViewDataTable { const TEMPLATE_FILE = ''; - const SPECIFIC_PROPERTIES = 'visualization_properties'; private $templateVars = array(); - final public function __construct($controllerAction, $apiMethodToRequestDataTable, $defaultReportProperties) + final public function __construct($controllerAction, $apiMethodToRequestDataTable) { $templateFile = static::TEMPLATE_FILE; @@ -49,7 +48,7 @@ class Visualization extends ViewDataTable throw new \Exception('You have not defined a constant named TEMPLATE_FILE in your visualization class.'); } - parent::__construct($controllerAction, $apiMethodToRequestDataTable, $defaultReportProperties); + parent::__construct($controllerAction, $apiMethodToRequestDataTable); } protected function init() diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index e77b19f0b2..473be55c92 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -52,18 +52,11 @@ class ViewDataTable { /** - * Cache for getAllReportDisplayProperties result. - * - * @var array - */ - private static $reportPropertiesCache = null; - - /** * Cache for getDefaultViewTypeForReports result. * * @var array */ - private static $defaultViewType = null; + private static $defaultViewTypes = null; /** * Returns a Piwik_ViewDataTable_* object. @@ -86,8 +79,7 @@ class ViewDataTable $controllerAction = $apiAction; } - $defaultViewType = self::getDefaultViewTypeForReport($apiAction); - $defaultReportProperties = static::getDefaultPropertiesForReport($apiAction); + $defaultViewType = self::getDefaultViewTypeForReport($apiAction); if (!$forceDefault && !empty($defaultViewType)) { $defaultType = $defaultViewType; @@ -98,11 +90,11 @@ class ViewDataTable $visualizations = static::getAvailableVisualizations(); if (array_key_exists($type, $visualizations)) { - return new $visualizations[$type]($controllerAction, $apiAction, $defaultReportProperties); + return new $visualizations[$type]($controllerAction, $apiAction); } if (class_exists($type)) { - return new $type($controllerAction, $apiAction, $defaultReportProperties); + return new $type($controllerAction, $apiAction); } throw new \Exception(sprintf('Visuzalization type %s not found', $type)); @@ -115,6 +107,7 @@ class ViewDataTable * @return array Array mapping visualization IDs with their associated visualization classes. * @throws \Exception If a visualization class does not exist or if a duplicate visualization ID * is found. + * @return array */ public static function getAvailableVisualizations() { @@ -200,29 +193,12 @@ class ViewDataTable } /** - * Returns the defaut view properties for a report, if any. - * - * Plugins can associate callbacks with the Visualization.getReportDisplayProperties - * event to set the default properties of reports. - * - * @param string $apiAction - * @return array - */ - private static function getDefaultPropertiesForReport($apiAction) - { - $reportDisplayProperties = self::getAllReportDisplayProperties(); - return isset($reportDisplayProperties[$apiAction]) ? $reportDisplayProperties[$apiAction] : array(); - } - - /** * Returns the default viewDataTable ID to use when determining which visualization to use. - * - * @param string $apiAction */ private static function getDefaultViewTypeForReport($apiAction) { $defaultViewTypes = self::getDefaultViewTypeForReports(); - return isset($defaultViewTypes[$apiAction]) ? $defaultViewTypes[$apiAction] : array(); + return isset($defaultViewTypes[$apiAction]) ? $defaultViewTypes[$apiAction] : false; } /** @@ -231,8 +207,8 @@ class ViewDataTable */ private static function getDefaultViewTypeForReports() { - if (null === self::$defaultViewType) { - self::$defaultViewType = array(); + if (null === self::$defaultViewTypes) { + self::$defaultViewTypes = array(); /** * This event is triggered to gather the default view types for each available report. By default a table * is used. If you define your own report, you may want to subscribe to this event to define another @@ -249,40 +225,9 @@ class ViewDataTable * } * ``` */ - Piwik::postEvent('Visualization.getDefaultViewTypeForReports', array(&self::$defaultViewType)); - } - - return self::$defaultViewType; - } - - /** - * Returns the list of display properties for all available reports. - * - * @return array - */ - private static function getAllReportDisplayProperties() - { - if (null === self::$reportPropertiesCache) { - self::$reportPropertiesCache = array(); - /** - * This event is triggered to gather the report display properties for each available report. If you define - * your own report, you want to subscribe to this event to define how your report shall be displayed in the - * Piwik UI. - * - * Example: - * ``` - * public function getReportDisplayProperties(&$properties) - * { - * $properties['Provider.getProvider'] = array( - * 'translations' => array('label' => Piwik::translate('Provider_ColumnProvider')), - * 'filter_limit' => 5 - * ) - * } - * ``` - */ - Piwik::postEvent('Visualization.getReportDisplayProperties', array(&self::$reportPropertiesCache)); + Piwik::postEvent('Visualization.getDefaultViewTypeForReports', array(&self::$defaultViewTypes)); } - return self::$reportPropertiesCache; + return self::$defaultViewTypes; } }
\ No newline at end of file diff --git a/core/ViewDataTable/Config.php b/core/ViewDataTable/Config.php index d82bbfb2c6..0a93c22b0d 100644 --- a/core/ViewDataTable/Config.php +++ b/core/ViewDataTable/Config.php @@ -552,8 +552,10 @@ class Config $this->columns_to_display = array_filter($columnsToDisplay); } - private function addRelatedReport($module, $action, $title, $queryParams = array()) + public function addRelatedReport($relatedReport, $title, $queryParams = array()) { + list($module, $action) = explode('.', $relatedReport); + // don't add the related report if it references this report if ($this->controllerName == $module && $this->controllerAction == $action) { return; @@ -567,8 +569,19 @@ class Config public function addRelatedReports($relatedReports) { foreach ($relatedReports as $report => $title) { - list($module, $action) = explode('.', $report); - $this->addRelatedReport($module, $action, $title); + $this->addRelatedReport($report, $title); + } + } + + public function addTranslation($key, $translation) + { + $this->translations[$key] = $translation; + } + + public function addTranslations($translations) + { + foreach ($translations as $key => $translation) { + $this->addTranslation($key, $translation); } } diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index 049e8df0b0..3f7d484afa 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -17,11 +17,13 @@ use Piwik\Db; use Piwik\Menu\MenuMain; use Piwik\MetricsFormatter; use Piwik\Piwik; +use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\SegmentExpression; use Piwik\Site; use Piwik\Tracker\Action; -use Piwik\ViewDataTable; +use Piwik\ViewDataTable\Request as ViewDataTableRequest; use Piwik\WidgetsList; +use \Piwik\Plugin\ViewDataTable; /** * Actions plugin @@ -56,15 +58,15 @@ class Actions extends \Piwik\Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessor.Day.compute' => 'archiveDay', - 'ArchiveProcessor.Period.compute' => 'archivePeriod', - 'WidgetsList.addWidgets' => 'addWidgets', - 'Menu.Reporting.addItems' => 'addMenus', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', - 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', - 'AssetManager.getJavaScriptFiles' => 'getJsFiles' + 'ArchiveProcessor.Day.compute' => 'archiveDay', + 'ArchiveProcessor.Period.compute' => 'archivePeriod', + 'WidgetsList.addWidgets' => 'addWidgets', + 'Menu.Reporting.addItems' => 'addMenus', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.configure' => 'configureViewDataTable', + 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'AssetManager.getJavaScriptFiles' => 'getJsFiles' ); return $hooks; } @@ -643,51 +645,83 @@ class Actions extends \Piwik\Plugin } } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['Actions.getPageUrls'] = $this->getDisplayPropertiesForPageUrls(); - $properties['Actions.getEntryPageUrls'] = $this->getDisplayPropertiesForEntryPageUrls(); - $properties['Actions.getExitPageUrls'] = $this->getDisplayPropertiesForExitPageUrls(); - $properties['Actions.getSiteSearchKeywords'] = $this->getDisplayPropertiesForSiteSearchKeywords(); - $properties['Actions.getSiteSearchNoResultKeywords'] = $this->getDisplayPropertiesForSiteSearchNoResultKeywords(); - $properties['Actions.getSiteSearchCategories'] = $this->getDisplayPropertiesForSiteSearchCategories(); - $properties['Actions.getPageUrlsFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(false); - $properties['Actions.getPageTitlesFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(true); - $properties['Actions.getPageTitles'] = $this->getDisplayPropertiesForGetPageTitles(); - $properties['Actions.getEntryPageTitles'] = $this->getDisplayPropertiesForGetEntryPageTitles(); - $properties['Actions.getExitPageTitles'] = $this->getDisplayPropertiesForGetExitPageTitles(); - $properties['Actions.getDownloads'] = $this->getDisplayPropertiesForGetDownloads(); - $properties['Actions.getOutlinks'] = $this->getDisplayPropertiesForGetOutlinks(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'Actions.getPageUrls': + $this->configureViewForPageUrls($view); + break; + case 'Actions.getEntryPageUrls': + $this->configureViewForEntryPageUrls($view); + break; + case 'Actions.getExitPageUrls': + $this->configureViewForExitPageUrls($view); + break; + case 'Actions.getSiteSearchKeywords': + $this->configureViewForSiteSearchKeywords($view); + break; + case 'Actions.getSiteSearchNoResultKeywords': + $this->configureViewForSiteSearchNoResultKeywords($view); + break; + case 'Actions.getSiteSearchCategories': + $this->configureViewForSiteSearchCategories($view); + break; + case 'Actions.getPageUrlsFollowingSiteSearch': + $this->configureViewForGetPageUrlsOrTitlesFollowingSiteSearch($view, false); + break; + case 'Actions.getPageTitlesFollowingSiteSearch': + $this->configureViewForGetPageUrlsOrTitlesFollowingSiteSearch($view, true); + break; + case 'Actions.getPageTitles': + $this->configureViewForGetPageTitles($view); + break; + case 'Actions.getEntryPageTitles': + $this->configureViewForGetEntryPageTitles($view); + break; + case 'Actions.getExitPageTitles': + $this->configureViewForGetExitPageTitles($view); + break; + case 'Actions.getDownloads': + $this->configureViewForGetDownloads($view); + break; + case 'Actions.getOutlinks': + $this->configureViewForGetOutlinks($view); + break; + } } - private function addBaseDisplayProperties(&$result) + private function addBaseDisplayProperties(ViewDataTable $view) { - $result['datatable_js_type'] = 'ActionsDataTable'; - $result['visualization_properties']['table']['show_embedded_subtable'] = true; - $result['search_recursive'] = true; - $result['show_all_views_icons'] = false; - $result['show_table_all_columns'] = false; - $result['filter_limit'] = self::ACTIONS_REPORT_ROWS_DISPLAY; + $view->config->datatable_js_type = 'ActionsDataTable'; + $view->config->search_recursive = true; + $view->config->show_all_views_icons = false; + $view->config->show_table_all_columns = false; + $view->requestConfig->filter_limit = self::ACTIONS_REPORT_ROWS_DISPLAY; + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->show_embedded_subtable = true; + } // if the flat parameter is not provided, make sure it is set to 0 in the URL, // so users can see that they can set it to 1 (see #3365) - $result['custom_parameters'] = array('flat' => 0); + $view->config->custom_parameters = array('flat' => 0); - if (ViewDataTable\Request::shouldLoadExpanded()) { - $result['visualization_properties']['table']['show_expanded'] = true; + if (ViewDataTableRequest::shouldLoadExpanded()) { + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->show_expanded = true; + } - $result['filters'][] = function ($dataTable) { + $view->config->filters[] = function ($dataTable) { Actions::setDataTableRowLevels($dataTable); }; } - $result['filters'][] = function ($dataTable, $view) { - if ('table' == $view->getViewDataTableId()) { + $view->config->filters[] = function ($dataTable) use ($view) { + if ($view->isViewDataTableId(HtmlTable::ID)) { $view->config->datatable_css_class = 'dataTableActions'; } }; - - return $result; } /** @@ -706,11 +740,11 @@ class Actions extends \Piwik\Plugin } } - private function addExcludeLowPopDisplayProperties(&$result) + private function addExcludeLowPopDisplayProperties(ViewDataTable $view) { if (Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') != '0') { - $result['filter_excludelowpop'] = 'nb_hits'; - $result['filter_excludelowpop_value'] = function () { + $view->requestConfig->filter_excludelowpop = 'nb_hits'; + $view->requestConfig->filter_excludelowpop_value = function () { // computing minimum value to exclude (2 percent of the total number of actions) $visitsInfo = \Piwik\Plugins\VisitsSummary\Controller::getVisitsSummary()->getFirstRow(); $nbActions = $visitsInfo->getColumn('nb_actions'); @@ -723,27 +757,26 @@ class Actions extends \Piwik\Plugin } } - private function addPageDisplayProperties(&$result) + private function addPageDisplayProperties(ViewDataTable $view) { - // add common translations - $result['translations'] += array( + $view->config->addTranslations(array( 'nb_hits' => Piwik::translate('General_ColumnPageviews'), 'nb_visits' => Piwik::translate('General_ColumnUniquePageviews'), 'avg_time_on_page' => Piwik::translate('General_ColumnAverageTimeOnPage'), 'bounce_rate' => Piwik::translate('General_ColumnBounceRate'), 'exit_rate' => Piwik::translate('General_ColumnExitRate'), 'avg_time_generation' => Piwik::translate('General_ColumnAverageGenerationTime'), - ); + )); // prettify avg_time_on_page column $getPrettyTimeFromSeconds = '\Piwik\MetricsFormatter::getPrettyTimeFromSeconds'; - $result['filters'][] = array('ColumnCallbackReplace', array('avg_time_on_page', $getPrettyTimeFromSeconds)); + $view->config->filters[] = array('ColumnCallbackReplace', array('avg_time_on_page', $getPrettyTimeFromSeconds)); // prettify avg_time_generation column $avgTimeCallback = function ($time) { return $time ? MetricsFormatter::getPrettyTimeFromSeconds($time, true, true, false) : "-"; }; - $result['filters'][] = array('ColumnCallbackReplace', array('avg_time_generation', $avgTimeCallback)); + $view->config->filters[] = array('ColumnCallbackReplace', array('avg_time_generation', $avgTimeCallback)); // add avg_generation_time tooltip $tooltipCallback = function ($hits, $min, $max) { @@ -758,7 +791,7 @@ class Actions extends \Piwik\Plugin MetricsFormatter::getPrettyTimeFromSeconds($max) )); }; - $result['filters'][] = array('ColumnCallbackAddMetadata', + $view->config->filters[] = array('ColumnCallbackAddMetadata', array( array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'), 'avg_time_generation_tooltip', @@ -766,135 +799,117 @@ class Actions extends \Piwik\Plugin ) ); - $this->addExcludeLowPopDisplayProperties($result); + $this->addExcludeLowPopDisplayProperties($view); } - public function getDisplayPropertiesForPageUrls() + public function configureViewForPageUrls(ViewDataTable $view) { - $result = array( - 'translations' => array('label' => Piwik::translate('Actions_ColumnPageURL')), - 'columns_to_display' => array('label', 'nb_hits', 'nb_visits', 'bounce_rate', - 'avg_time_on_page', 'exit_rate', 'avg_time_generation'), - ); + $view->config->addTranslation('label', Piwik::translate('Actions_ColumnPageURL')); + $view->config->columns_to_display = array('label', 'nb_hits', 'nb_visits', 'bounce_rate', + 'avg_time_on_page', 'exit_rate', 'avg_time_generation'); - $this->addPageDisplayProperties($result); - $this->addBaseDisplayProperties($result); - - return $result; + $this->addPageDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForEntryPageUrls() + public function configureViewForEntryPageUrls(ViewDataTable $view) { // link to the page, not just the report, but only if not a widget - $widget = Common::getRequestVar('widget', false); - $reportUrl = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', - 'action' => $widget === false ? 'indexEntryPageUrls' : 'getEntryPageUrls' - )); - - $result = array( - 'translations' => array('label' => Piwik::translate('Actions_ColumnEntryPageURL'), - 'entry_bounce_count' => Piwik::translate('General_ColumnBounces'), - 'entry_nb_visits' => Piwik::translate('General_ColumnEntrances')), - 'columns_to_display' => array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'), - 'filter_sort_column' => 'entry_nb_visits', - 'filter_sort_order' => 'desc', - 'title' => Piwik::translate('Actions_SubmenuPagesEntry'), - 'related_reports' => array( - 'Actions.getEntryPageTitles' => Piwik::translate('Actions_EntryPageTitles') - ), - 'self_url' => $reportUrl + $widget = Common::getRequestVar('widget', false); + + $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array( + 'module' => 'Actions', + 'action' => $widget === false ? 'indexEntryPageUrls' : 'getEntryPageUrls' + )); + + $view->config->addTranslations(array( + 'label' => Piwik::translate('Actions_ColumnEntryPageURL'), + 'entry_bounce_count' => Piwik::translate('General_ColumnBounces'), + 'entry_nb_visits' => Piwik::translate('General_ColumnEntrances')) ); - $this->addPageDisplayProperties($result); - $this->addBaseDisplayProperties($result); + $view->config->title = Piwik::translate('Actions_SubmenuPagesEntry'); + $view->config->addRelatedReport('Actions.getEntryPageTitles', Piwik::translate('Actions_EntryPageTitles')); + $view->config->columns_to_display = array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'); + $view->requestConfig->filter_sort_column = 'entry_nb_visits'; + $view->requestConfig->filter_sort_order = 'desc'; - return $result; + $this->addPageDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForExitPageUrls() + public function configureViewForExitPageUrls(ViewDataTable $view) { // link to the page, not just the report, but only if not a widget - $widget = Common::getRequestVar('widget', false); - $reportUrl = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', - 'action' => $widget === false ? 'indexExitPageUrls' : 'getExitPageUrls' - )); - - $result = array( - 'translations' => array('label' => Piwik::translate('Actions_ColumnExitPageURL'), - 'exit_nb_visits' => Piwik::translate('General_ColumnExits')), - 'columns_to_display' => array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'), - 'filter_sort_column' => 'exit_nb_visits', - 'filter_sort_order' => 'desc', - 'title' => Piwik::translate('Actions_SubmenuPagesExit'), - 'related_reports' => array( - 'Actions.getExitPageTitles' => Piwik::translate('Actions_ExitPageTitles') - ), - 'self_url' => $reportUrl, + $widget = Common::getRequestVar('widget', false); + + $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array( + 'module' => 'Actions', + 'action' => $widget === false ? 'indexExitPageUrls' : 'getExitPageUrls' + )); + + $view->config->addTranslations(array( + 'label' => Piwik::translate('Actions_ColumnExitPageURL'), + 'exit_nb_visits' => Piwik::translate('General_ColumnExits')) ); - $this->addPageDisplayProperties($result); - $this->addBaseDisplayProperties($result); + $view->config->title = Piwik::translate('Actions_SubmenuPagesExit'); + $view->config->addRelatedReport('Actions.getExitPageTitles', Piwik::translate('Actions_ExitPageTitles')); + + $view->config->columns_to_display = array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'); + $view->requestConfig->filter_sort_column = 'exit_nb_visits'; + $view->requestConfig->filter_sort_order = 'desc'; - return $result; + $this->addPageDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - private function addSiteSearchDisplayProperties(&$result) + private function addSiteSearchDisplayProperties(ViewDataTable $view) { - $result['translations'] += array( + $view->config->addTranslations(array( 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), 'exit_rate' => str_replace("% ", "% ", Piwik::translate('Actions_ColumnSearchExits')), 'nb_pages_per_search' => Piwik::translate('Actions_ColumnPagesPerSearch') - ); - $result['show_bar_chart'] = false; - $result['show_table_all_columns'] = false; + )); + + $view->config->show_bar_chart = false; + $view->config->show_table_all_columns = false; } - public function getDisplayPropertiesForSiteSearchKeywords() + public function configureViewForSiteSearchKeywords(ViewDataTable $view) { - $result = array( - 'translations' => array('label' => Piwik::translate('General_ColumnKeyword')), - 'columns_to_display' => array('label', 'nb_visits', 'nb_pages_per_search', 'exit_rate'), - ); - - $this->addSiteSearchDisplayProperties($result); + $view->config->addTranslation('label', Piwik::translate('General_ColumnKeyword')); + $view->config->columns_to_display = array('label', 'nb_visits', 'nb_pages_per_search', 'exit_rate'); - return $result; + $this->addSiteSearchDisplayProperties($view); } - public function getDisplayPropertiesForSiteSearchNoResultKeywords() + public function configureViewForSiteSearchNoResultKeywords(ViewDataTable $view) { - $result = array( - 'translations' => array('label', Piwik::translate('Actions_ColumnNoResultKeyword')), - 'columns_to_display' => array('label', 'nb_visits', 'exit_rate') - ); - - $this->addSiteSearchDisplayProperties($result); + $view->config->addTranslation('label', Piwik::translate('Actions_ColumnNoResultKeyword')); + $view->config->columns_to_display = array('label', 'nb_visits', 'exit_rate'); - return $result; + $this->addSiteSearchDisplayProperties($view); } - public function getDisplayPropertiesForSiteSearchCategories() + public function configureViewForSiteSearchCategories(ViewDataTable $view) { - return array( - 'translations' => array( - 'label' => Piwik::translate('Actions_ColumnSearchCategory'), - 'nb_visits' => Piwik::translate('Actions_ColumnSearches'), - 'nb_pages_per_search' => Piwik::translate('Actions_ColumnPagesPerSearch') - ), - 'columns_to_display' => array('label', 'nb_visits', 'nb_pages_per_search'), - 'show_table_all_columns' => false, - 'show_bar_chart' => false, - 'visualization_properties' => array( - 'table' => array( - 'disable_row_evolution' => false, - ) - ) - ); + $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; + } } - public function getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch($isTitle) + public function configureViewForGetPageUrlsOrTitlesFollowingSiteSearch(ViewDataTable $view, $isTitle) { $title = $isTitle ? Piwik::translate('Actions_WidgetPageTitlesFollowingSearch') : Piwik::translate('Actions_WidgetPageUrlsFollowingSearch'); @@ -904,135 +919,118 @@ class Actions extends \Piwik\Plugin 'Actions.getPageUrlsFollowingSiteSearch' => Piwik::translate('Actions_WidgetPageUrlsFollowingSearch'), ); - $result = array( - 'translations' => array( - 'label' => Piwik::translate('General_ColumnDestinationPage'), - 'nb_hits_following_search' => Piwik::translate('General_ColumnViewedAfterSearch'), - 'nb_hits' => Piwik::translate('General_ColumnTotalPageviews') - ), - 'columns_to_display' => array('label', 'nb_hits_following_search', 'nb_hits'), - 'filter_sort_column' => 'nb_hits_following_search', - 'filter_sort_order' => 'desc', - 'show_exclude_low_population' => false, - 'title' => $title, - 'related_reports' => $relatedReports - ); - - $this->addExcludeLowPopDisplayProperties($result); - $this->addBaseDisplayProperties($result); - - return $result; + $view->config->addRelatedReports($relatedReports); + $view->config->addTranslations(array( + 'label' => Piwik::translate('General_ColumnDestinationPage'), + 'nb_hits_following_search' => Piwik::translate('General_ColumnViewedAfterSearch'), + 'nb_hits' => Piwik::translate('General_ColumnTotalPageviews') + )); + + $view->config->title = $title; + $view->config->columns_to_display = array('label', 'nb_hits_following_search', 'nb_hits'); + $view->config->show_exclude_low_population = false; + $view->requestConfig->filter_sort_column = 'nb_hits_following_search'; + $view->requestConfig->filter_sort_order = 'desc'; + + $this->addExcludeLowPopDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForGetPageTitles() + public function configureViewForGetPageTitles(ViewDataTable $view) { // link to the page, not just the report, but only if not a widget $widget = Common::getRequestVar('widget', false); - $reportUrl = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', - 'action' => $widget === false ? 'indexPageTitles' : 'getPageTitles' - )); - - $result = array( - 'translations' => array('label' => Piwik::translate('Actions_ColumnPageName')), - 'columns_to_display' => array('label', 'nb_hits', 'nb_visits', 'bounce_rate', - 'avg_time_on_page', 'exit_rate', 'avg_time_generation'), - 'title' => Piwik::translate('Actions_SubmenuPageTitles'), - 'related_reports' => array( - 'Actions.getEntryPageTitles' => Piwik::translate('Actions_EntryPageTitles'), - 'Actions.getExitPageTitles' => Piwik::translate('Actions_ExitPageTitles'), - ), - 'self_url' => $reportUrl - ); - $this->addPageDisplayProperties($result); - $this->addBaseDisplayProperties($result); + $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array( + 'module' => 'Actions', + 'action' => $widget === false ? 'indexPageTitles' : 'getPageTitles' + )); + + $view->config->title = Piwik::translate('Actions_SubmenuPageTitles'); + $view->config->addRelatedReports(array( + 'Actions.getEntryPageTitles' => Piwik::translate('Actions_EntryPageTitles'), + 'Actions.getExitPageTitles' => Piwik::translate('Actions_ExitPageTitles'), + )); - return $result; + $view->config->addTranslation('label', Piwik::translate('Actions_ColumnPageName')); + $view->config->columns_to_display = array('label', 'nb_hits', 'nb_visits', 'bounce_rate', + 'avg_time_on_page', 'exit_rate', 'avg_time_generation'); + + $this->addPageDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForGetEntryPageTitles() + public function configureViewForGetEntryPageTitles(ViewDataTable $view) { $entryPageUrlAction = Common::getRequestVar('widget', false) === false ? 'indexEntryPageUrls' : 'getEntryPageUrls'; - $result = array( - 'translations' => array( - 'label' => Piwik::translate('Actions_ColumnEntryPageTitle'), - 'entry_bounce_count' => Piwik::translate('General_ColumnBounces'), - 'entry_nb_visits' => Piwik::translate('General_ColumnEntrances'), - ), - 'columns_to_display' => array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'), - 'title' => Piwik::translate('Actions_EntryPageTitles'), - 'related_reports' => array( - 'Actions.getPageTitles' => Piwik::translate('Actions_SubmenuPageTitles'), - "Actions.$entryPageUrlAction" => Piwik::translate('Actions_SubmenuPagesEntry') - ), - 'filter_sort_column' => 'entry_nb_visits' - ); + $view->config->addTranslations(array( + 'label' => Piwik::translate('Actions_ColumnEntryPageTitle'), + 'entry_bounce_count' => Piwik::translate('General_ColumnBounces'), + 'entry_nb_visits' => Piwik::translate('General_ColumnEntrances'), + )); + $view->config->addRelatedReports(array( + 'Actions.getPageTitles' => Piwik::translate('Actions_SubmenuPageTitles'), + "Actions.$entryPageUrlAction" => Piwik::translate('Actions_SubmenuPagesEntry') + )); + + $view->config->columns_to_display = array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'); + $view->config->title = Piwik::translate('Actions_EntryPageTitles'); - $this->addPageDisplayProperties($result); - $this->addBaseDisplayProperties($result); + $view->requestConfig->filter_sort_column = 'entry_nb_visits'; - return $result; + $this->addPageDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForGetExitPageTitles() + public function configureViewForGetExitPageTitles(ViewDataTable $view) { $exitPageUrlAction = Common::getRequestVar('widget', false) === false ? 'indexExitPageUrls' : 'getExitPageUrls'; - $result = array( - 'translations' => array( - 'label' => Piwik::translate('Actions_ColumnExitPageTitle'), - 'exit_nb_visits' => Piwik::translate('General_ColumnExits'), - ), - 'columns_to_display' => array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'), - 'title' => Piwik::translate('Actions_ExitPageTitles'), - 'related_reports' => array( - 'Actions.getPageTitles' => Piwik::translate('Actions_SubmenuPageTitles'), - "Actions.$exitPageUrlAction" => Piwik::translate('Actions_SubmenuPagesExit'), - ), - ); + $view->config->addTranslations(array( + 'label' => Piwik::translate('Actions_ColumnExitPageTitle'), + 'exit_nb_visits' => Piwik::translate('General_ColumnExits'), + )); + $view->config->addRelatedReports(array( + 'Actions.getPageTitles' => Piwik::translate('Actions_SubmenuPageTitles'), + "Actions.$exitPageUrlAction" => Piwik::translate('Actions_SubmenuPagesExit'), + )); - $this->addPageDisplayProperties($result); - $this->addBaseDisplayProperties($result); + $view->config->title = Piwik::translate('Actions_ExitPageTitles'); + $view->config->columns_to_display = array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'); - return $result; + $this->addPageDisplayProperties($view); + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForGetDownloads() + public function configureViewForGetDownloads(ViewDataTable $view) { - $result = array( - 'translations' => array( - 'label' => Piwik::translate('Actions_ColumnDownloadURL'), - 'nb_visits' => Piwik::translate('Actions_ColumnUniqueDownloads'), - 'nb_hits' => Piwik::translate('General_Downloads'), - ), - 'columns_to_display' => array('label', 'nb_visits', 'nb_hits'), - 'show_exclude_low_population' => false - ); + $view->config->addTranslations(array( + 'label' => Piwik::translate('Actions_ColumnDownloadURL'), + 'nb_visits' => Piwik::translate('Actions_ColumnUniqueDownloads'), + 'nb_hits' => Piwik::translate('General_Downloads'), + )); - $this->addBaseDisplayProperties($result); + $view->config->columns_to_display = array('label', 'nb_visits', 'nb_hits'); + $view->config->show_exclude_low_population = false; - return $result; + $this->addBaseDisplayProperties($view); } - public function getDisplayPropertiesForGetOutlinks() + public function configureViewForGetOutlinks(ViewDataTable $view) { - $result = array( - 'translations' => array( - 'label' => Piwik::translate('Actions_ColumnClickedURL'), - 'nb_visits' => Piwik::translate('Actions_ColumnUniqueClicks'), - 'nb_hits' => Piwik::translate('Actions_ColumnClicks'), - ), - 'columns_to_display' => array('label', 'nb_visits', 'nb_hits'), - 'show_exclude_low_population' => false - ); + $view->config->addTranslations(array( + 'label' => Piwik::translate('Actions_ColumnClickedURL'), + 'nb_visits' => Piwik::translate('Actions_ColumnUniqueClicks'), + 'nb_hits' => Piwik::translate('Actions_ColumnClicks'), + )); - $this->addBaseDisplayProperties($result); + $view->config->columns_to_display = array('label', 'nb_visits', 'nb_hits'); + $view->config->show_exclude_low_population = false; - return $result; + $this->addBaseDisplayProperties($view); } } diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index 0c74de393e..a7c080ec16 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -177,7 +177,7 @@ class Controller extends Plugin\ControllerAdmin { Piwik::checkUserIsSuperUser(); - $activated = Common::getRequestVar('activated', false, 'integer', $_GET); + $activated = Common::getRequestVar('activated', false, 'integer', $_GET); $pluginName = Common::getRequestVar('pluginName', '', 'string'); $view = $this->configureView('@CorePluginsAdmin/' . $template); diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php index 763ee09634..63c85655e3 100644 --- a/plugins/CustomVariables/CustomVariables.php +++ b/plugins/CustomVariables/CustomVariables.php @@ -13,6 +13,7 @@ namespace Piwik\Plugins\CustomVariables; use Piwik\ArchiveProcessor; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\Tracker; use Piwik\WidgetsList; @@ -34,14 +35,14 @@ class CustomVariables extends \Piwik\Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessor.Day.compute' => 'archiveDay', - 'ArchiveProcessor.Period.compute' => 'archivePeriod', - 'WidgetsList.addWidgets' => 'addWidgets', - 'Menu.Reporting.addItems' => 'addMenus', - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ArchiveProcessor.Day.compute' => 'archiveDay', + 'ArchiveProcessor.Period.compute' => 'archivePeriod', + 'WidgetsList.addWidgets' => 'addWidgets', + 'Menu.Reporting.addItems' => 'addMenus', + 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.configure' => 'configureViewDataTable', ); return $hooks; } @@ -152,39 +153,40 @@ class CustomVariables extends \Piwik\Plugin } } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['CustomVariables.getCustomVariables'] = $this->getDisplayPropertiesForGetCustomVariables(); - $properties['CustomVariables.getCustomVariablesValuesFromNameId'] = - $this->getDisplayPropertiesForGetCustomVariablesValuesFromNameId(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'CustomVariables.getCustomVariables': + $this->configureViewForGetCustomVariables($view); + break; + case 'CustomVariables.getCustomVariablesValuesFromNameId': + $this->configureViewForGetCustomVariablesValuesFromNameId($view); + break; + } } - private function getDisplayPropertiesForGetCustomVariables() + private function configureViewForGetCustomVariables(ViewDataTable $view) { $footerMessage = Piwik::translate('CustomVariables_TrackingHelp', array('<a target="_blank" href="http://piwik.org/docs/custom-variables/">', '</a>')); - return array( - 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), - 'filter_sort_column' => 'nb_actions', - 'filter_sort_order' => 'desc', - 'show_goals' => true, - 'subtable_controller_action' => 'getCustomVariablesValuesFromNameId', - 'translations' => array('label' => Piwik::translate('CustomVariables_ColumnCustomVariableName')), - 'show_footer_message' => $footerMessage - ); + $view->config->columns_to_display = array('label', 'nb_actions', 'nb_visits'); + $view->config->show_goals = true; + $view->config->subtable_controller_action = 'getCustomVariablesValuesFromNameId'; + $view->config->show_footer_message = $footerMessage; + $view->config->addTranslation('label', Piwik::translate('CustomVariables_ColumnCustomVariableName')); + $view->requestConfig->filter_sort_column = 'nb_actions'; + $view->requestConfig->filter_sort_order = 'desc'; } - private function getDisplayPropertiesForGetCustomVariablesValuesFromNameId() + private function configureViewForGetCustomVariablesValuesFromNameId(ViewDataTable $view) { - return array( - 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), - 'filter_sort_column' => 'nb_actions', - 'filter_sort_order' => 'desc', - 'show_goals' => true, - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('CustomVariables_ColumnCustomVariableValue')) - ); + $view->config->columns_to_display = array('label', 'nb_actions', 'nb_visits'); + $view->config->show_goals = true; + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('CustomVariables_ColumnCustomVariableValue')); + $view->requestConfig->filter_sort_column = 'nb_actions'; + $view->requestConfig->filter_sort_order = 'desc'; } } diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index 493cdfbd2c..52535defda 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -16,10 +16,12 @@ use Piwik\Date; use Piwik\Menu\MenuAdmin; use Piwik\Option; use Piwik\Piwik; +use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; use Piwik\ScheduledTask; use Piwik\ScheduledTime\Weekly; +use \Piwik\Plugin\ViewDataTable; /** * @@ -38,7 +40,7 @@ class DBStats extends \Piwik\Plugin 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'Menu.Admin.addItems' => 'addMenu', 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ViewDataTable.configure' => 'configureViewDataTable', 'Visualization.getDefaultViewTypeForReports' => 'getDefaultViewTypeForReports' ); } @@ -104,36 +106,50 @@ class DBStats extends \Piwik\Plugin $defaultViewTypes['DBStats.getAdminDataSummary'] = HtmlTable::ID; } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['DBStats.getDatabaseUsageSummary'] = $this->getDisplayPropertiesForGetDatabaseUsageSummary('DBStats.getDatabaseUsageSummary'); - $properties['DBStats.getTrackerDataSummary'] = $this->getDisplayPropertiesForGetTrackerDataSummary('DBStats.getTrackerDataSummary'); - $properties['DBStats.getMetricDataSummary'] = $this->getDisplayPropertiesForGetMetricDataSummary('DBStats.getMetricDataSummary'); - $properties['DBStats.getMetricDataSummaryByYear'] = $this->getDisplayPropertiesForGetMetricDataSummaryByYear('DBStats.getMetricDataSummaryByYear'); - $properties['DBStats.getReportDataSummary'] = $this->getDisplayPropertiesForGetReportDataSummary('DBStats.getReportDataSummary'); - $properties['DBStats.getReportDataSummaryByYear'] = $this->getDisplayPropertiesForGetReportDataSummaryByYear('DBStats.getReportDataSummaryByYear'); - $properties['DBStats.getIndividualReportsSummary'] = $this->getDisplayPropertiesForGetIndividualReportsSummary('DBStats.getIndividualReportsSummary'); - $properties['DBStats.getIndividualMetricsSummary'] = $this->getDisplayPropertiesForGetIndividualMetricsSummary('DBStats.getIndividualMetricsSummary'); - $properties['DBStats.getAdminDataSummary'] = $this->getDisplayPropertiesForGetAdminDataSummary('DBStats.getAdminDataSummary'); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'DBStats.getDatabaseUsageSummar': + $this->configureViewForGetDatabaseUsageSummary($view); + break; + case 'DBStats.getTrackerDataSummary': + $this->configureViewForGetTrackerDataSummary($view); + break; + case 'DBStats.getMetricDataSummary': + $this->configureViewForGetMetricDataSummary($view); + break; + case 'DBStats.getMetricDataSummaryByYear': + $this->configureViewForGetMetricDataSummaryByYear($view); + break; + case 'DBStats.getReportDataSummary': + $this->configureViewForGetReportDataSummary($view); + break; + case 'DBStats.getReportDataSummaryByYear': + $this->configureViewForGetReportDataSummaryByYear($view); + break; + case 'DBStats.getIndividualReportsSummary': + $this->configureViewForGetIndividualReportsSummary($view); + break; + case 'DBStats.getIndividualMetricsSummary': + $this->configureViewForGetIndividualMetricsSummary($view); + break; + case 'DBStats.getAdminDataSummary': + $this->configureViewForGetAdminDataSummary($view); + break; + } } - private function getDefaultViewTypeForApiAction($apiAction) + private function configureViewForGetDatabaseUsageSummary(ViewDataTable $view) { - $defaultTypes = array(); - $this->getDefaultViewTypeForReports($defaultTypes); - - return $defaultTypes[$apiAction]; - } + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view, $addTotalSizeColumn = true, $addPercentColumn = true); - private function getDisplayPropertiesForGetDatabaseUsageSummary($apiAction) - { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction, $addTotalSizeColumn = true, $addPercentColumn = true); + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; - $result['show_offset_information'] = false; - $result['show_pagination_control'] = false; - $result['visualization_properties']['graph']['show_all_ticks'] = true; + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->show_all_ticks = true; + } // translate the labels themselves $valueToTranslationStr = array( @@ -149,143 +165,122 @@ class DBStats extends \Piwik\Plugin : $value; }; - $result['filters'][] = array('ColumnCallbackReplace', array('label', $translateSummaryLabel), $isPriority = true); - - return $result; + $view->config->filters[] = array('ColumnCallbackReplace', array('label', $translateSummaryLabel), $isPriority = true); } - private function getDisplayPropertiesForGetTrackerDataSummary($apiAction) + private function configureViewForGetTrackerDataSummary(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction); - - $result['filter_sort_order'] = 'asc'; - $result['show_offset_information'] = false; - $result['show_pagination_control'] = false; + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view); - return $result; + $view->requestConfig->filter_sort_order = 'asc'; + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; } - private function getDisplayPropertiesForGetMetricDataSummary($apiAction) + private function configureViewForGetMetricDataSummary(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction); + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view); - $result['title'] = Piwik::translate('DBStats_MetricTables'); - $result['related_reports'] = array( + $view->config->title = Piwik::translate('DBStats_MetricTables'); + $view->config->addRelatedReports(array( 'DBStats.getMetricDataSummaryByYear' => Piwik::translate('DBStats_MetricDataByYear') - ); - - return $result; + )); } - private function getDisplayPropertiesForGetMetricDataSummaryByYear($apiAction) + private function configureViewForGetMetricDataSummaryByYear(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction); + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view); - $result['translations']['label'] = Piwik::translate('CoreHome_PeriodYear'); - $result['title'] = Piwik::translate('DBStats_MetricDataByYear'); - $result['related_reports'] = array( + $view->config->title = Piwik::translate('DBStats_MetricDataByYear'); + $view->config->addTranslation('label', Piwik::translate('CoreHome_PeriodYear')); + $view->config->addRelatedReports(array( 'DBStats.getMetricDataSummary' => Piwik::translate('DBStats_MetricTables') - ); - - return $result; + )); } - private function getDisplayPropertiesForGetReportDataSummary($apiAction) + private function configureViewForGetReportDataSummary(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction); + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view); - $result['title'] = Piwik::translate('DBStats_ReportTables'); - $result['related_reports'] = array( + $view->config->title = Piwik::translate('DBStats_ReportTables'); + $view->config->addRelatedReports(array( 'DBStats.getReportDataSummaryByYear' => Piwik::translate('DBStats_ReportDataByYear') - ); - - return $result; + )); } - private function getDisplayPropertiesForGetReportDataSummaryByYear($apiAction) + private function configureViewForGetReportDataSummaryByYear(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction); + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view); - $result['translations']['label'] = Piwik::translate('CoreHome_PeriodYear'); - $result['title'] = Piwik::translate('DBStats_ReportDataByYear'); - $result['related_reports'] = array( + $view->config->title = Piwik::translate('DBStats_ReportDataByYear'); + $view->config->addTranslation('label', Piwik::translate('CoreHome_PeriodYear')); + $view->config->addRelatedReports(array( 'DBStats.getReportDataSummary' => Piwik::translate('DBStats_ReportTables') - ); - - return $result; + )); } - private function getDisplayPropertiesForGetIndividualReportsSummary($apiAction) + private function configureViewForGetIndividualReportsSummary(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $viewDataTable = $this->addPresentationFilters($result, $apiAction, $addTotalSizeColumn = false, $addPercentColumn = false, - $sizeColumns = array('estimated_size')); + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view, $addTotalSizeColumn = false, $addPercentColumn = false, + $sizeColumns = array('estimated_size')); - $result['filter_sort_order'] = 'asc'; - $result['translations']['label'] = Piwik::translate('General_Report'); + $view->requestConfig->filter_sort_order = 'asc'; + $view->config->addTranslation('label', Piwik::translate('General_Report')); // this report table has some extra columns that shouldn't be shown - if ($viewDataTable == 'table') { - $result['columns_to_display'] = array('label', 'row_count', 'estimated_size'); + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->columns_to_display = array('label', 'row_count', 'estimated_size'); } - $this->setIndividualSummaryFooterMessage($result); - - return $result; + $this->setIndividualSummaryFooterMessage($view); } - private function getDisplayPropertiesForGetIndividualMetricsSummary($apiAction) + private function configureViewForGetIndividualMetricsSummary(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction, $addTotalSizeColumn = false, $addPercentColumn = false, + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view, $addTotalSizeColumn = false, $addPercentColumn = false, $sizeColumns = array('estimated_size')); - $result['filter_sort_order'] = 'asc'; - $result['translations']['label'] = Piwik::translate('General_Metric'); + $view->requestConfig->filter_sort_order = 'asc'; + $view->config->addTranslation('label', Piwik::translate('General_Metric')); - $this->setIndividualSummaryFooterMessage($result); - - return $result; + $this->setIndividualSummaryFooterMessage($view); } - private function getDisplayPropertiesForGetAdminDataSummary($apiAction) + private function configureViewForGetAdminDataSummary(ViewDataTable $view) { - $result = array(); - $this->addBaseDisplayProperties($result); - $this->addPresentationFilters($result, $apiAction); - - $result['filter_sort_order'] = 'asc'; - $result['show_offset_information'] = false; - $result['show_pagination_control'] = false; + $this->addBaseDisplayProperties($view); + $this->addPresentationFilters($view); - return $result; + $view->requestConfig->filter_sort_order = 'asc'; + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; } - private function addBaseDisplayProperties(&$properties) + private function addBaseDisplayProperties(ViewDataTable $view) { - $properties['filter_sort_column'] = 'label'; - $properties['filter_sort_order'] = 'desc'; - $properties['filter_limit'] = 25; - $properties['show_search'] = false; - $properties['show_exclude_low_population'] = false; - $properties['show_tag_cloud'] = false; - $properties['show_table_all_columns'] = false; - $properties['visualization_properties']['table']['keep_summary_row'] = true; - $properties['visualization_properties']['table']['disable_row_evolution'] = true; - $properties['visualization_properties']['table']['highlight_summary_row'] = true; - $properties['translations'] = array( + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'desc'; + $view->requestConfig->filter_limit = 25; + + $view->config->show_exclude_low_population = false; + $view->config->show_table_all_columns = false; + $view->config->show_tag_cloud = false; + $view->config->show_search = false; + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->keep_summary_row = true; + $view->config->disable_row_evolution = true; + $view->config->highlight_summary_row = true; + } + + $view->config->addTranslations(array( 'label' => Piwik::translate('DBStats_Table'), 'year' => Piwik::translate('CoreHome_PeriodYear'), 'data_size' => Piwik::translate('DBStats_DataSize'), @@ -294,10 +289,10 @@ class DBStats extends \Piwik\Plugin 'row_count' => Piwik::translate('DBStats_RowCount'), 'percent_total' => '% ' . Piwik::translate('DBStats_DBSize'), 'estimated_size' => Piwik::translate('DBStats_EstimatedSize') - ); + )); } - private function addPresentationFilters(&$properties, $apiAction, $addTotalSizeColumn = true, $addPercentColumn = false, + private function addPresentationFilters(ViewDataTable $view, $addTotalSizeColumn = true, $addPercentColumn = false, $sizeColumns = array('data_size', 'index_size')) { // add total_size column @@ -306,7 +301,7 @@ class DBStats extends \Piwik\Plugin return $dataSize + $indexSize; }; - $properties['filters'][] = array('ColumnCallbackAddColumn', + $view->config->filters[] = array('ColumnCallbackAddColumn', array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), $isPriority = true); $sizeColumns[] = 'total_size'; @@ -314,79 +309,74 @@ class DBStats extends \Piwik\Plugin $runPrettySizeFilterBeforeGeneric = false; - $defaultViewType = $this->getDefaultViewTypeForApiAction($apiAction); - $viewDataTable = empty($defaultViewType) ? 'table' : $defaultViewType; - $viewDataTable = Common::getRequestVar('viewDataTable', $viewDataTable); + if ($view->isViewDataTableId(HtmlTable::ID)) { - if ($viewDataTable == 'table') { // add summary row only if displaying a table - $properties['filters'][] = array( + $view->config->filters[] = array( 'AddSummaryRow', array(0, Piwik::translate('General_Total'), 'label', false), $isPriority = true); // add percentage column if desired if ($addPercentColumn && $addTotalSizeColumn ) { - $properties['filters'][] = array('ColumnCallbackAddColumnPercentage', + $view->config->filters[] = array('ColumnCallbackAddColumnPercentage', array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, $shouldSkipRows = false, $getDivisorFromSummaryRow = true), $isPriority = true ); - $properties['filter_sort_column'] = 'percent_total'; + $view->requestConfig->filter_sort_column = 'percent_total'; } - } else if (strpos($viewDataTable, 'graph') === 0) { + + } else if ($view->isViewDataTableId(Graph::ID)) { if ($addTotalSizeColumn) { - $properties['columns_to_display'] = array('label', 'total_size'); + $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'; - $properties['y_axis_unit'] = ' K'; - - $properties['filter_sort_column'] = 'total_size'; - $properties['filter_sort_order'] = 'desc'; + $view->config->y_axis_unit = ' K'; + $view->requestConfig->filter_sort_column = 'total_size'; + $view->requestConfig->filter_sort_order = 'desc'; $runPrettySizeFilterBeforeGeneric = true; } else { - $properties['columns_to_display'] = array('label', 'row_count'); - $properties['y_axis_unit'] = ' ' . Piwik::translate('General_Rows'); + $view->config->columns_to_display = array('label', 'row_count'); + $view->config->y_axis_unit = ' ' . Piwik::translate('General_Rows'); - $properties['filter_sort_column'] = 'row_count'; - $properties['filter_sort_order'] = 'desc'; + $view->requestConfig->filter_sort_column = 'row_count'; + $view->requestConfig->filter_sort_order = 'desc'; } } $getPrettySize = array('\Piwik\MetricsFormatter', 'getPrettySizeFromBytes'); - $params = !isset($fixedMemoryUnit) ? array() : array($fixedMemoryUnit); - $properties['filters'][] = array( - 'ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric); + $params = !isset($fixedMemoryUnit) ? array() : array($fixedMemoryUnit); + + $view->config->filters[] = array('ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric); // jqPlot will display as, well, ' ', so don't replace the spaces when rendering as a graph - if ($viewDataTable == 'table') { + if ($view->isViewDataTableId(HtmlTable::ID)) { $replaceSpaces = function ($value) { return str_replace(' ', ' ', $value); }; - $properties['filters'][] = array('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces)); + $view->config->filters[] = array('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces)); } $getPrettyNumber = array('\Piwik\MetricsFormatter', 'getPrettyNumber'); - $properties['filters'][] = array('ColumnCallbackReplace', array('row_count', $getPrettyNumber)); - - return $viewDataTable; + $view->config->filters[] = array('ColumnCallbackReplace', array('row_count', $getPrettyNumber)); } /** * Sets the footer message for the Individual...Summary reports. */ - private function setIndividualSummaryFooterMessage($result) + private function setIndividualSummaryFooterMessage(ViewDataTable $view) { $lastGenerated = self::getDateOfLastCachingRun(); if ($lastGenerated !== false) { - $result['show_footer_message'] = Piwik::translate('Mobile_LastUpdated', $lastGenerated); + $view->config->show_footer_message = Piwik::translate('Mobile_LastUpdated', $lastGenerated); } } } diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php index 1fdbb01613..0fb275341e 100644 --- a/plugins/DevicesDetection/DevicesDetection.php +++ b/plugins/DevicesDetection/DevicesDetection.php @@ -19,6 +19,7 @@ use Piwik\Config; use Piwik\Db; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\WidgetsList; use UserAgentParserEnhanced; @@ -90,14 +91,14 @@ class DevicesDetection extends \Piwik\Plugin public function getListHooksRegistered() { return array( - 'ArchiveProcessor.Day.compute' => 'archiveDay', - 'ArchiveProcessor.Period.compute' => 'archivePeriod', - 'Menu.Reporting.addItems' => 'addMenu', - 'Tracker.newVisitorInformation' => 'parseMobileVisitData', - 'WidgetsList.addWidgets' => 'addWidgets', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ArchiveProcessor.Day.compute' => 'archiveDay', + 'ArchiveProcessor.Period.compute' => 'archivePeriod', + 'Menu.Reporting.addItems' => 'addMenu', + 'Tracker.newVisitorInformation' => 'parseMobileVisitData', + 'WidgetsList.addWidgets' => 'addWidgets', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.configure' => 'configureViewDataTable', ); } @@ -293,85 +294,87 @@ class DevicesDetection extends \Piwik\Plugin MenuMain::getInstance()->add('General_Visitors', 'DevicesDetection_submenu', array('module' => 'DevicesDetection', 'action' => 'index')); } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['DevicesDetection.getType'] = $this->getDisplayPropertiesForGetType(); - $properties['DevicesDetection.getBrand'] = $this->getDisplayPropertiesForGetBrand(); - $properties['DevicesDetection.getModel'] = $this->getDisplayPropertiesForGetModel(); - $properties['DevicesDetection.getOsFamilies'] = $this->getDisplayPropertiesForGetOsFamilies(); - $properties['DevicesDetection.getOsVersions'] = $this->getDisplayPropertiesForGetOsVersions(); - $properties['DevicesDetection.getBrowserFamilies'] = $this->getDisplayPropertiesForGetBrowserFamilies(); - $properties['DevicesDetection.getBrowserVersions'] = $this->getDisplayPropertiesForGetBrowserVersions(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'DevicesDetection.getType': + $this->configureViewForGetType($view); + break; + case 'DevicesDetection.getBrand': + $this->configureViewForGetBrand($view); + break; + case 'DevicesDetection.getModel': + $this->configureViewForGetModel($view); + break; + case 'DevicesDetection.getOsFamilies': + $this->configureViewForGetOsFamilies($view); + break; + case 'DevicesDetection.getOsVersions': + $this->configureViewForGetOsVersions($view); + break; + case 'DevicesDetection.getBrowserFamilies': + $this->configureViewForGetBrowserFamilies($view); + break; + case 'DevicesDetection.getBrowserVersions': + $this->configureViewForGetBrowserVersions($view); + break; + } } - private function getDisplayPropertiesForGetType() + private function configureViewForGetType(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelTypes")) - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelTypes")); } - private function getDisplayPropertiesForGetBrand() + private function configureViewForGetBrand(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelBrands")) - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelBrands")); } - private function getDisplayPropertiesForGetModel() + private function configureViewForGetModel(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelModels")) - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelModels")); } - private function getDisplayPropertiesForGetOsFamilies() + private function configureViewForGetOsFamilies(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelSystemFamily")), - 'title' => Piwik::translate('DevicesDetection_OperatingSystemFamilies'), - 'related_reports' => $this->getOsRelatedReports() - ); + $view->config->title = Piwik::translate('DevicesDetection_OperatingSystemFamilies'); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelSystemFamily")); + $view->config->addRelatedReports($this->getOsRelatedReports()); } - private function getDisplayPropertiesForGetOsVersions() + private function configureViewForGetOsVersions(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelSystemVersion")), - 'title' => Piwik::translate('DevicesDetection_OperatingSystemVersions'), - 'related_reports' => $this->getOsRelatedReports() - ); + $view->config->title = Piwik::translate('DevicesDetection_OperatingSystemVersions'); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelSystemVersion")); + $view->config->addRelatedReports($this->getOsRelatedReports()); } - private function getDisplayPropertiesForGetBrowserFamilies() + private function configureViewForGetBrowserFamilies(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelBrowserFamily")), - 'title' => Piwik::translate('DevicesDetection_BrowsersFamily'), - 'related_reports' => $this->getBrowserRelatedReports() - ); + $view->config->title = Piwik::translate('DevicesDetection_BrowsersFamily'); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelBrowserFamily")); + $view->config->addRelatedReports($this->getBrowserRelatedReports()); } - private function getDisplayPropertiesForGetBrowserVersions() + private function configureViewForGetBrowserVersions(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate("DevicesDetection_dataTableLabelBrowserVersion")), - 'related_reports' => $this->getBrowserRelatedReports() - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelBrowserVersion")); + $view->config->addRelatedReports($this->getBrowserRelatedReports()); } private function getOsRelatedReports() diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 33bd3b4354..31db9f742e 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -16,6 +16,7 @@ use Piwik\Common; use Piwik\Db; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\Site; use Piwik\Tracker\GoalManager; use Piwik\Translate; @@ -88,20 +89,20 @@ class Goals extends \Piwik\Plugin public function getListHooksRegistered() { $hooks = array( - 'AssetManager.getJavaScriptFiles' => 'getJsFiles', - 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', - 'Site.getSiteAttributes' => 'fetchGoalsFromDb', - 'ArchiveProcessor.Day.compute' => 'archiveDay', - 'ArchiveProcessor.Period.compute' => 'archivePeriod', - 'API.getReportMetadata.end' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'WidgetsList.addWidgets' => 'addWidgets', - 'Menu.Reporting.addItems' => 'addMenus', - 'SitesManager.deleteSite.end' => 'deleteSiteGoals', - 'Goals.getReportsWithGoalMetrics' => 'getActualReportsWithGoalMetrics', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', - 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', - 'Visualization.addVisualizations' => 'getAvailableDataTableVisualizations' + 'AssetManager.getJavaScriptFiles' => 'getJsFiles', + 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'Site.getSiteAttributes' => 'fetchGoalsFromDb', + 'ArchiveProcessor.Day.compute' => 'archiveDay', + 'ArchiveProcessor.Period.compute' => 'archivePeriod', + 'API.getReportMetadata.end' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'WidgetsList.addWidgets' => 'addWidgets', + 'Menu.Reporting.addItems' => 'addMenus', + 'SitesManager.deleteSite.end' => 'deleteSiteGoals', + 'Goals.getReportsWithGoalMetrics' => 'getActualReportsWithGoalMetrics', + 'ViewDataTable.configure' => 'configureViewDataTable', + 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', + 'Visualization.addVisualizations' => 'getAvailableDataTableVisualizations' ); return $hooks; } @@ -524,71 +525,83 @@ class Goals extends \Piwik\Plugin } } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['Goals.getItemsSku'] = $this->getDisplayPropertiesForGetItemsSku(); - $properties['Goals.getItemsName'] = $this->getDisplayPropertiesForGetItemsName(); - $properties['Goals.getItemsCategory'] = $this->getDisplayPropertiesForGetItemsCategory(); - $properties['Goals.getVisitsUntilConversion'] = $this->getDisplayPropertiesForGetVisitsUntilConversion(); - $properties['Goals.getDaysToConversion'] = $this->getDisplayPropertiesForGetDaysToConversion(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'Goals.getItemsSku': + $this->configureViewForGetItemsSku($view); + break; + case 'Goals.getItemsName': + $this->configureViewForGetItemsName($view); + break; + case 'Goals.getItemsCategory': + $this->configureViewForGetItemsCategory($view); + break; + case 'Goals.getVisitsUntilConversion': + $this->configureViewForGetVisitsUntilConversion($view); + break; + case 'Goals.getDaysToConversion': + $this->configureViewForGetDaysToConversion($view); + break; + } } - private function getDisplayPropertiesForGetItemsSku() + private function configureViewForGetItemsSku(ViewDataTable $view) { - return $this->getDisplayPropertiesForItemsReport(Piwik::translate('Goals_ProductSKU')); + return $this->configureViewForItemsReport($view, Piwik::translate('Goals_ProductSKU')); } - private function getDisplayPropertiesForGetItemsName() + private function configureViewForGetItemsName(ViewDataTable $view) { - return $this->getDisplayPropertiesForItemsReport(Piwik::translate('Goals_ProductName')); + return $this->configureViewForItemsReport($view, Piwik::translate('Goals_ProductName')); } - private function getDisplayPropertiesForGetItemsCategory() + private function configureViewForGetItemsCategory(ViewDataTable $view) { - return $this->getDisplayPropertiesForItemsReport(Piwik::translate('Goals_ProductCategory')); + return $this->configureViewForItemsReport($view, Piwik::translate('Goals_ProductCategory')); } - private function getDisplayPropertiesForGetVisitsUntilConversion() + private function configureViewForGetVisitsUntilConversion(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'show_table_all_columns' => false, - 'columns_to_display' => array('label', 'nb_conversions'), - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array( - 'label' => Piwik::translate('Goals_VisitsUntilConv'), - 'nb_conversions' => Piwik::translate('Goals_ColumnConversions'), - ), - 'filter_limit' => count(Archiver::$visitCountRanges), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_all_views_icons' => false - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->show_table_all_columns = false; + $view->config->columns_to_display = array('label', 'nb_conversions'); + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + $view->config->show_all_views_icons = false; + + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->requestConfig->filter_limit = count(Archiver::$visitCountRanges); + + $view->config->addTranslations(array( + 'label' => Piwik::translate('Goals_VisitsUntilConv'), + 'nb_conversions' => Piwik::translate('Goals_ColumnConversions'), + )); } - private function getDisplayPropertiesForGetDaysToConversion() + private function configureViewForGetDaysToConversion(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'show_table_all_columns' => false, - 'columns_to_display' => array('label', 'nb_conversions'), - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array( - 'label' => Piwik::translate('Goals_DaysToConv'), - 'nb_conversions' => Piwik::translate('Goals_ColumnConversions'), - ), - 'filter_limit' => count(Archiver::$daysToConvRanges), - 'show_all_views_icons' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->show_table_all_columns = false; + $view->config->show_all_views_icons = false; + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + $view->config->columns_to_display = array('label', 'nb_conversions'); + + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->requestConfig->filter_limit = count(Archiver::$daysToConvRanges); + + $view->config->addTranslations(array( + 'label' => Piwik::translate('Goals_DaysToConv'), + 'nb_conversions' => Piwik::translate('Goals_ColumnConversions'), + )); } - private function getDisplayPropertiesForItemsReport($label) + private function configureViewForItemsReport(ViewDataTable $view, $label) { $idSite = Common::getRequestVar('idSite'); @@ -596,18 +609,17 @@ class Goals extends \Piwik\Plugin $prettifyMoneyColumns = array( 'ColumnCallbackReplace', array($moneyColumns, '\Piwik\MetricsFormatter::getPrettyMoney', array($idSite))); - $result = array( - 'show_ecommerce' => true, - 'show_all_views_icons' => false, - 'show_table' => false, - 'show_exclude_low_population' => false, - 'show_table_all_columns' => false, - 'filter_limit' => 10, - 'translations' => array('label' => $label), - 'filter_sort_column' => 'revenue', - 'filter_sort_order' => 'desc', - 'filters' => array($prettifyMoneyColumns) - ); + $view->config->show_ecommerce = true; + $view->config->show_table = false; + $view->config->show_all_views_icons = false; + $view->config->show_exclude_low_population = false; + $view->config->show_table_all_columns = false; + $view->config->addTranslation('label', $label); + $view->config->filters[] = $prettifyMoneyColumns; + + $view->requestConfig->filter_limit = 10; + $view->requestConfig->filter_sort_column = 'revenue'; + $view->requestConfig->filter_sort_order = 'desc'; // set columns/translations which differ based on viewDataTable TODO: shouldn't have to do this check... amount of reports should be dynamic, but metadata should be static $columns = Goals::getProductReportColumns(); @@ -621,15 +633,17 @@ class Goals extends \Piwik\Plugin unset($columns['orders']); unset($columns['conversion_rate']); - $result['request_parameters_to_modify'] = array('abandonedCarts' => '1'); + $view->requestConfig->request_parameters_to_modify['abandonedCarts'] = '1'; } - $result['translations'] = array_merge(array('label' => $label), $columns); - $result['columns_to_display'] = array_keys($result['translations']); + $translations = array_merge(array('label' => $label), $columns); + + $view->config->addTranslations($translations); + $view->config->columns_to_display = array_keys($translations); // set metrics documentation in normal ecommerce report if (!$abandonedCart) { - $result['metrics_documentation'] = array( + $view->config->metrics_documentation = array( 'revenue' => Piwik::translate('Goals_ColumnRevenueDocumentation', Piwik::translate('Goals_DocumentationRevenueGeneratedByProductSales')), 'quantity' => Piwik::translate('Goals_ColumnQuantityDocumentation', $label), @@ -641,10 +655,8 @@ class Goals extends \Piwik\Plugin ); } - $result['custom_parameters']['viewDataTable'] = + $view->config->custom_parameters['viewDataTable'] = $abandonedCart ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART : Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER; - - return $result; } diff --git a/plugins/Live/Live.php b/plugins/Live/Live.php index 8ce54aad8b..53e735114e 100644 --- a/plugins/Live/Live.php +++ b/plugins/Live/Live.php @@ -14,6 +14,8 @@ namespace Piwik\Plugins\Live; use Piwik\Common; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\WidgetsList; /** @@ -33,7 +35,7 @@ class Live extends \Piwik\Plugin 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'WidgetsList.addWidgets' => 'addWidget', 'Menu.Reporting.addItems' => 'addMenu', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ViewDataTable.configure' => 'configureViewDataTable', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'Visualization.getDefaultViewTypeForReports' => 'getDefaultViewTypeForReports' ); @@ -74,9 +76,13 @@ class Live extends \Piwik\Plugin $translationKeys[] = "Live_PageRefreshed"; } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['Live.getLastVisitsDetails'] = $this->getDisplayPropertiesForGetLastVisitsDetails(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'Live.getLastVisitsDetails': + $this->configureViewForGetLastVisitsDetails($view); + break; + } } public function getDefaultViewTypeForReports(&$defaultViewTypes) @@ -84,45 +90,45 @@ class Live extends \Piwik\Plugin $defaultViewTypes['Live.getLastVisitsDetails'] = VisitorLog::ID; } - private function getDisplayPropertiesForGetLastVisitsDetails() + private function configureViewForGetLastVisitsDetails(ViewDataTable $view) { - return array( - 'disable_generic_filters' => true, - 'enable_sort' => false, - 'filter_sort_column' => 'idVisit', - 'filter_sort_order' => 'asc', - 'show_search' => false, - 'filter_limit' => 20, - 'show_offset_information' => false, - 'show_exclude_low_population' => false, - 'show_all_views_icons' => false, - 'show_table_all_columns' => false, - 'show_export_as_rss_feed' => false, - 'documentation' => Piwik::translate('Live_VisitorLogDocumentation', array('<br />', '<br />')), - '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')) - ), - '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' - ) + $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('<br />', '<br />')); + $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' ) ) - ), - 'visualization_properties' => array( - 'table' => array( - 'disable_row_actions' => true, - ) ) ); + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->disable_row_actions = true; + } } }
\ No newline at end of file diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index 41dc2e6fff..8537b8527f 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -19,6 +19,7 @@ use Piwik\FrontController; use Piwik\IP; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\WidgetsList; /** @@ -33,14 +34,14 @@ class Provider extends \Piwik\Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessor.Day.compute' => 'archiveDay', - 'ArchiveProcessor.Period.compute' => 'archivePeriod', - 'Tracker.newVisitorInformation' => 'logProviderInfo', - 'WidgetsList.addWidgets' => 'addWidget', - 'Menu.Reporting.addItems' => 'addMenu', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ArchiveProcessor.Day.compute' => 'archiveDay', + 'ArchiveProcessor.Period.compute' => 'archivePeriod', + 'Tracker.newVisitorInformation' => 'logProviderInfo', + 'WidgetsList.addWidgets' => 'addWidget', + 'Menu.Reporting.addItems' => 'addMenu', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.configure' => 'configureViewDataTable', ); return $hooks; } @@ -235,16 +236,18 @@ class Provider extends \Piwik\Plugin } } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['Provider.getProvider'] = $this->getDisplayPropertiesForGetProvider(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'Provider.getProvider': + $this->configureViewForGetProvider($view); + break; + } } - private function getDisplayPropertiesForGetProvider() + private function configureViewForGetProvider(ViewDataTable $view) { - return array( - 'translations' => array('label' => Piwik::translate('Provider_ColumnProvider')), - 'filter_limit' => 5 - ); + $view->requestConfig->filter_limit = 5; + $view->config->addTranslation('label', Piwik::translate('Provider_ColumnProvider')); } } diff --git a/plugins/Referrers/Referrers.php b/plugins/Referrers/Referrers.php index 25c3ffaf04..099c0b1075 100644 --- a/plugins/Referrers/Referrers.php +++ b/plugins/Referrers/Referrers.php @@ -14,7 +14,9 @@ use Piwik\ArchiveProcessor; use Piwik\Common; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable\AllColumns; +use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; use Piwik\SettingsPiwik; use Piwik\WidgetsList; @@ -42,7 +44,7 @@ class Referrers extends \Piwik\Plugin 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', 'API.getReportMetadata' => 'getReportMetadata', 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ViewDataTable.configure' => 'configureViewDataTable', 'Visualization.getDefaultViewTypeForReports' => 'getDefaultViewTypeForReports' ); return $hooks; @@ -304,26 +306,53 @@ class Referrers extends \Piwik\Plugin $defaultViewTypes['Referrers.getSocials'] = Pie::ID; } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['Referrers.getReferrerType'] = $this->getDisplayPropertiesForGetReferrerType(); - $properties['Referrers.getAll'] = $this->getDisplayPropertiesForGetAll(); - $properties['Referrers.getKeywords'] = $this->getDisplayPropertiesForGetKeywords(); - $properties['Referrers.getSearchEnginesFromKeywordId'] = $this->getDisplayPropertiesForGetSearchEnginesFromKeywordId(); - $properties['Referrers.getSearchEngines'] = $this->getDisplayPropertiesForGetSearchEngines(); - $properties['Referrers.getKeywordsFromSearchEngineId'] = $this->getDisplayPropertiesForGetKeywordsFromSearchEngineId(); - $properties['Referrers.getWebsites'] = $this->getDisplayPropertiesForGetWebsites(); - $properties['Referrers.getSocials'] = $this->getDisplayPropertiesForGetSocials(); - $properties['Referrers.getUrlsForSocial'] = $this->getDisplayPropertiesForGetUrlsForSocial(); - $properties['Referrers.getCampaigns'] = $this->getDisplayPropertiesForGetCampaigns(); - $properties['Referrers.getKeywordsFromCampaignId'] = $this->getDisplayPropertiesForGetKeywordsFromCampaignId(); - $properties['Referrers.getUrlsFromWebsiteId'] = $this->getDisplayPropertiesForGetUrlsFromWebsiteId(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'Referrers.getReferrerType': + $this->configureViewForGetReferrerType($view); + break; + case 'Referrers.getAll': + $this->configureViewForGetAll($view); + break; + case 'Referrers.getKeywords': + $this->configureViewForGetKeywords($view); + break; + case 'Referrers.getSearchEnginesFromKeywordId': + $this->configureViewForGetSearchEnginesFromKeywordId($view); + break; + case 'Referrers.getSearchEngines': + $this->configureViewForGetSearchEngines($view); + break; + case 'Referrers.getKeywordsFromSearchEngineId': + $this->configureViewForGetKeywordsFromSearchEngineId($view); + break; + case 'Referrers.getWebsites': + $this->configureViewForGetWebsites($view); + break; + case 'Referrers.getSocials': + $this->configureViewForGetSocials($view); + break; + case 'Referrers.getUrlsForSocial': + $this->configureViewForGetUrlsForSocial($view); + break; + case 'Referrers.getCampaigns': + $this->configureViewForGetCampaigns($view); + break; + case 'Referrers.getKeywordsFromCampaignId': + $this->configureViewForGetKeywordsFromCampaignId($view); + break; + case 'Referrers.getUrlsFromWebsiteId': + $this->configureViewForGetUrlsFromWebsiteId($view); + break; + } } - private function getDisplayPropertiesForGetReferrerType() + private function configureViewForGetReferrerType(ViewDataTable $view) { - $idSubtable = Common::getRequestVar('idSubtable', false); + $idSubtable = Common::getRequestVar('idSubtable', false); $labelColumnTitle = Piwik::translate('Referrers_Type'); + switch ($idSubtable) { case Common::REFERRER_TYPE_SEARCH_ENGINE: $labelColumnTitle = Piwik::translate('Referrers_ColumnSearchEngine'); @@ -338,180 +367,154 @@ class Referrers extends \Piwik\Plugin break; } - return array( - 'show_search' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 10, - 'translations' => array('label' => $labelColumnTitle), - 'visualization_properties' => array( - 'table' => array( - 'disable_subtable_when_show_goals' => true, - ) - ), - ); + $view->config->show_search = false; + $view->config->show_goals = true; + $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; + } } - private function getDisplayPropertiesForGetAll() + private function configureViewForGetAll(ViewDataTable $view) { $setGetAllHtmlPrefix = array($this, 'setGetAllHtmlPrefix'); - return array( - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('Referrers_Referrer')), - 'show_goals' => true, - 'filter_limit' => 20, - 'visualization_properties' => array( - 'table' => array( - 'disable_row_actions' => true - ) - ), - 'filters' => array( - array('MetadataCallbackAddMetadata', array('referer_type', 'html_label_prefix', $setGetAllHtmlPrefix)) - ) - ); + + $view->config->show_exclude_low_population = false; + $view->config->show_goals = true; + $view->config->addTranslation('label', Piwik::translate('Referrers_Referrer')); + + $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)); } - private function getDisplayPropertiesForGetKeywords() + private function configureViewForGetKeywords(ViewDataTable $view) { - return array( - 'subtable_controller_action' => 'getSearchEnginesFromKeywordId', - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('General_ColumnKeyword')), - 'show_goals' => true, - 'filter_limit' => 25, - 'visualization_properties' => array( - 'table' => array( - 'disable_subtable_when_show_goals' => true, - ) - ), - ); + $view->config->subtable_controller_action = 'getSearchEnginesFromKeywordId'; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('General_ColumnKeyword')); + $view->config->show_goals = true; + + $view->requestConfig->filter_limit = 25; + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->disable_subtable_when_show_goals = true; + } } - private function getDisplayPropertiesForGetSearchEnginesFromKeywordId() + private function configureViewForGetSearchEnginesFromKeywordId(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnSearchEngine')) - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnSearchEngine')); } - private function getDisplayPropertiesForGetSearchEngines() + private function configureViewForGetSearchEngines(ViewDataTable $view) { - return array( - 'subtable_controller_action' => 'getKeywordsFromSearchEngineId', - 'show_search' => false, - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 25, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnSearchEngine')), - 'visualization_properties' => array( - 'table' => array( - 'disable_subtable_when_show_goals' => true, - ) - ), - ); + $view->config->subtable_controller_action = 'getKeywordsFromSearchEngineId'; + $view->config->show_exclude_low_population = false; + $view->config->show_search = false; + $view->config->show_goals = true; + $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnSearchEngine')); + + $view->requestConfig->filter_limit = 25; + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->disable_subtable_when_show_goals = true; + } } - private function getDisplayPropertiesForGetKeywordsFromSearchEngineId() + private function configureViewForGetKeywordsFromSearchEngineId(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('General_ColumnKeyword')) - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('General_ColumnKeyword')); } - private function getDisplayPropertiesForGetWebsites() + private function configureViewForGetWebsites(ViewDataTable $view) { - return array( - 'subtable_controller_action' => 'getUrlsFromWebsiteId', - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 25, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnWebsite')), - 'visualization_properties' => array( - 'table' => array( - 'disable_subtable_when_show_goals' => true, - ) - ), - ); + $view->config->subtable_controller_action = 'getUrlsFromWebsiteId'; + $view->config->show_exclude_low_population = false; + $view->config->show_goals = true; + $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnWebsite')); + + $view->requestConfig->filter_limit = 25; + + if ($view->isViewDataTableId(HtmlTable::ID)) { + $view->config->disable_subtable_when_show_goals = true; + } } - private function getDisplayPropertiesForGetSocials() + private function configureViewForGetSocials(ViewDataTable $view) { - $result = array( - 'subtable_controller_action' => 'getUrlsForSocial', - 'show_exclude_low_population' => false, - 'filter_limit' => 10, - 'show_goals' => true, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnSocial')), - 'visualization_properties' => array( - 'table' => array( - 'disable_subtable_when_show_goals' => true, - ) - ), - ); + $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)) { - $result['show_footer_message'] = Piwik::translate('Referrers_SocialFooterMessage'); + $view->config->show_footer_message = Piwik::translate('Referrers_SocialFooterMessage'); } - - return $result; } - private function getDisplayPropertiesForGetUrlsForSocial() + private function configureViewForGetUrlsForSocial(ViewDataTable $view) { - return array( - 'show_exclude_low_population' => false, - 'filter_limit' => 10, - 'show_goals' => true, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnWebsitePage')) - ); + $view->config->show_goals = true; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnWebsitePage')); + + $view->requestConfig->filter_limit = 10; } - private function getDisplayPropertiesForGetCampaigns() + private function configureViewForGetCampaigns(ViewDataTable $view) { - $result = array( - 'subtable_controller_action' => 'getKeywordsFromCampaignId', - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 25, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnCampaign')), - ); + $view->config->show_goals = true; + $view->config->subtable_controller_action = 'getKeywordsFromCampaignId'; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnCampaign')); + + $view->requestConfig->filter_limit = 25; if (Common::getRequestVar('viewDataTable', false) != 'graphEvolution') { - $result['show_footer_message'] = Piwik::translate('Referrers_CampaignFooterHelp', + $view->config->show_footer_message = Piwik::translate('Referrers_CampaignFooterHelp', array('<a target="_blank" href="http://piwik.org/docs/tracking-campaigns/">', '</a> - <a target="_blank" href="http://piwik.org/docs/tracking-campaigns/url-builder/">', '</a>') ); } - - return $result; } - private function getDisplayPropertiesForGetKeywordsFromCampaignId() + private function configureViewForGetKeywordsFromCampaignId(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('General_ColumnKeyword')) - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('General_ColumnKeyword')); } - private function getDisplayPropertiesForGetUrlsFromWebsiteId() + private function configureViewForGetUrlsFromWebsiteId(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik::translate('Referrers_ColumnWebsitePage')), - 'tooltip_metadata_name' => 'url' - ); + $view->config->show_search = false; + $view->config->show_exclude_low_population = false; + $view->config->tooltip_metadata_name = 'url'; + $view->config->addTranslation('label', Piwik::translate('Referrers_ColumnWebsitePage')); } /** diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index 84c54f5d73..64bd49c3b2 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -16,6 +16,7 @@ use Piwik\IP; use Piwik\Menu\MenuAdmin; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider; use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; @@ -40,21 +41,21 @@ class UserCountry extends \Piwik\Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessor.Day.compute' => 'archiveDay', - 'ArchiveProcessor.Period.compute' => 'archivePeriod', - 'WidgetsList.addWidgets' => 'addWidgets', - 'Menu.Reporting.addItems' => 'addMenu', - 'Menu.Admin.addItems' => 'addAdminMenu', - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', - 'AssetManager.getJavaScriptFiles' => 'getJsFiles', - 'Tracker.newVisitorInformation' => 'getVisitorLocation', - 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', - 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', - 'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral' + 'ArchiveProcessor.Day.compute' => 'archiveDay', + 'ArchiveProcessor.Period.compute' => 'archivePeriod', + 'WidgetsList.addWidgets' => 'addWidgets', + 'Menu.Reporting.addItems' => 'addMenu', + 'Menu.Admin.addItems' => 'addAdminMenu', + 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'AssetManager.getJavaScriptFiles' => 'getJsFiles', + 'Tracker.newVisitorInformation' => 'getVisitorLocation', + 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', + 'ViewDataTable.configure' => 'configureViewDataTable', + 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', + 'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral' ); return $hooks; } @@ -363,23 +364,32 @@ class UserCountry extends \Piwik\Plugin 'bind' => '-'); // HACK: SegmentExpression requires a $bind, even if there's nothing to bind } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['UserCountry.getCountry'] = $this->getDisplayPropertiesForGetCountry(); - $properties['UserCountry.getContinent'] = $this->getDisplayPropertiesForGetContinent(); - $properties['UserCountry.getRegion'] = $this->getDisplayPropertiesForGetRegion(); - $properties['UserCountry.getCity'] = $this->getDisplayPropertiesForGetCity(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'UserCountry.getCountry': + $this->configureViewForGetCountry($view); + break; + case 'UserCountry.getContinent': + $this->configureViewForGetContinent($view); + break; + case 'UserCountry.getRegion': + $this->configureViewForGetRegion($view); + break; + case 'UserCountry.getCity': + $this->configureViewForGetCity($view); + break; + } } - private function getDisplayPropertiesForGetCountry() + private function configureViewForGetCountry(ViewDataTable $view) { - $result = array( - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 5, - 'translations' => array('label' => Piwik::translate('UserCountry_Country')), - 'documentation' => Piwik::translate('UserCountry_getCountryDocumentation') - ); + $view->config->show_goals = true; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('UserCountry_Country')); + $view->config->documentation = Piwik::translate('UserCountry_getCountryDocumentation'); + + $view->requestConfig->filter_limit = 5; if (LocationProvider::getCurrentProviderId() == DefaultProvider::ID) { // if we're using the default location provider, add a note explaining how it works @@ -387,52 +397,44 @@ class UserCountry extends \Piwik\Plugin . Piwik::translate('UserCountry_DefaultLocationProviderExplanation', array('<a target="_blank" href="http://piwik.org/docs/geo-locate/">', '</a>')); - $result['show_footer_message'] = $footerMessage; + $view->config->show_footer_message = $footerMessage; } - - return $result; } - private function getDisplayPropertiesForGetContinent() + private function configureViewForGetContinent(ViewDataTable $view) { - return array( - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'show_search' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'translations' => array('label' => Piwik::translate('UserCountry_Continent')), - 'documentation' => Piwik::translate('UserCountry_getContinentDocumentation') - ); + $view->config->show_exclude_low_population = false; + $view->config->show_goals = true; + $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->documentation = Piwik::translate('UserCountry_getContinentDocumentation'); + $view->config->addTranslation('label', Piwik::translate('UserCountry_Continent')); } - private function getDisplayPropertiesForGetRegion() + private function configureViewForGetRegion(ViewDataTable $view) { - $result = array( - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 5, - 'translations' => array('label' => Piwik::translate('UserCountry_Region')), - 'documentation' => Piwik::translate('UserCountry_getRegionDocumentation') . '<br/>' - . $this->getGeoIPReportDocSuffix() - ); - $this->checkIfNoDataForGeoIpReport($result); - return $result; + $view->config->show_exclude_low_population = false; + $view->config->show_goals = true; + $view->config->documentation = Piwik::translate('UserCountry_getRegionDocumentation') . '<br/>' . $this->getGeoIPReportDocSuffix(); + $view->config->addTranslation('label', Piwik::translate('UserCountry_Region')); + + $view->requestConfig->filter_limit = 5; + + $this->checkIfNoDataForGeoIpReport($view); } - private function getDisplayPropertiesForGetCity() + private function configureViewForGetCity(ViewDataTable $view) { - $result = array( - 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 5, - 'translations' => array('label' => Piwik::translate('UserCountry_City')), - 'documentation' => Piwik::translate('UserCountry_getCityDocumentation') . '<br/>' - . $this->getGeoIPReportDocSuffix() - ); - $this->checkIfNoDataForGeoIpReport($result); - return $result; + $view->config->show_exclude_low_population = false; + $view->config->show_goals = true; + $view->config->documentation = Piwik::translate('UserCountry_getCityDocumentation') . '<br/>' . $this->getGeoIPReportDocSuffix(); + $view->config->addTranslation('label', Piwik::translate('UserCountry_City')); + + $view->requestConfig->filter_limit = 5; + + $this->checkIfNoDataForGeoIpReport($view); } private function getGeoIPReportDocSuffix() @@ -449,10 +451,10 @@ class UserCountry extends \Piwik\Plugin * Checks if a datatable for a view is empty and if so, displays a message in the footer * telling users to configure GeoIP. */ - private function checkIfNoDataForGeoIpReport(&$properties) + private function checkIfNoDataForGeoIpReport(ViewDataTable $view) { $self = $this; - $properties['filters'][] = function ($dataTable, $view) use ($self) { + $view->config->filters[] = function ($dataTable) use ($self, $view) { // if there's only one row whose label is 'Unknown', display a message saying there's no data if ($dataTable->getRowsCount() == 1 && $dataTable->getFirstRow()->getColumn('label') == Piwik::translate('General_Unknown') diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php index 08a8f6c1ef..2f0124952e 100644 --- a/plugins/UserSettings/UserSettings.php +++ b/plugins/UserSettings/UserSettings.php @@ -13,6 +13,9 @@ namespace Piwik\Plugins\UserSettings; use Piwik\ArchiveProcessor; use Piwik\Menu\MenuMain; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; +use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; use Piwik\WidgetsList; @@ -172,7 +175,7 @@ class UserSettings extends \Piwik\Plugin 'Menu.Reporting.addItems' => 'addMenu', 'API.getReportMetadata' => 'getReportMetadata', 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ViewDataTable.configure' => 'configureViewDataTable', 'Visualization.getDefaultViewTypeForReports' => 'getDefaultViewTypeForReports' ); return $hooks; @@ -183,138 +186,168 @@ class UserSettings extends \Piwik\Plugin $defaultViewTypes['UserSettings.getBrowserType'] = Pie::ID; } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['UserSettings.getResolution'] = $this->getDisplayPropertiesForGetResolution(); - $properties['UserSettings.getConfiguration'] = $this->getDisplayPropertiesForGetConfiguration(); - $properties['UserSettings.getOS'] = $this->getDisplayPropertiesForGetOS(); - $properties['UserSettings.getOSFamily'] = $this->getDisplayPropertiesForGetOSFamily(); - $properties['UserSettings.getBrowserVersion'] = $this->getDisplayPropertiesForGetBrowserVersion(); - $properties['UserSettings.getBrowser'] = $this->getDisplayPropertiesForGetBrowser(); - $properties['UserSettings.getBrowserType'] = $this->getDisplayPropertiesForGetBrowserType(); - $properties['UserSettings.getWideScreen'] = $this->getDisplayPropertiesForGetWideScreen(); - $properties['UserSettings.getMobileVsDesktop'] = $this->getDisplayPropertiesForGetMobileVsDesktop(); - $properties['UserSettings.getPlugin'] = $this->getDisplayPropertiesForGetPlugin(); - $properties['UserSettings.getLanguage'] = $this->getDisplayPropertiesForGetLanguage(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'UserSettings.getResolution': + $this->configureViewForGetResolution($view); + break; + case 'UserSettings.getConfiguration': + $this->configureViewForGetConfiguration($view); + break; + case 'UserSettings.getOS': + $this->configureViewForGetOS($view); + break; + case 'UserSettings.getOSFamily': + $this->configureViewForGetOSFamily($view); + break; + case 'UserSettings.getBrowserVersion': + $this->configureViewForGetBrowserVersion($view); + break; + case 'UserSettings.getBrowser': + $this->configureViewForGetBrowser($view); + break; + case 'UserSettings.getBrowserType': + $this->configureViewForGetBrowserType($view); + break; + case 'UserSettings.getWideScreen': + $this->configureViewForGetWideScreen($view); + break; + case 'UserSettings.getMobileVsDesktop': + $this->configureViewForGetMobileVsDesktop($view); + break; + case 'UserSettings.getPlugin': + $this->configureViewForGetPlugin($view); + break; + case 'UserSettings.getLanguage': + $this->configureViewForGetLanguage($view); + break; + } } - private function getDisplayPropertiesForGetResolution() + private function configureViewForGetResolution(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnResolution')) - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnResolution')); } - private function getDisplayPropertiesForGetConfiguration() + private function configureViewForGetConfiguration(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'filter_limit' => 3, - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnConfiguration')) - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnConfiguration')); + + $view->requestConfig->filter_limit = 3; } - private function getDisplayPropertiesForGetOS() + private function configureViewForGetOS(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnOperatingSystem')), - 'title' => Piwik::translate('UserSettings_OperatingSystems'), - 'related_reports' => $this->getOsRelatedReports() - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->title = Piwik::translate('UserSettings_OperatingSystems'); + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnOperatingSystem')); + $view->config->addRelatedReports($this->getOsRelatedReports()); } - private function getDisplayPropertiesForGetOSFamily() + private function configureViewForGetOSFamily(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_OperatingSystemFamily')), - 'title' => Piwik::translate('UserSettings_OperatingSystemFamily'), - 'related_reports' => $this->getOsRelatedReports() - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->title = Piwik::translate('UserSettings_OperatingSystemFamily'); + $view->config->addTranslation('label', Piwik::translate('UserSettings_OperatingSystemFamily')); + $view->config->addRelatedReports($this->getOsRelatedReports()); } - private function getDisplayPropertiesForGetBrowserVersion() + private function configureViewForGetBrowserVersion(ViewDataTable $view) { - $result = array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnBrowserVersion')), - 'title' => Piwik::translate('UserSettings_ColumnBrowserVersion'), - 'related_reports' => $this->getBrowserRelatedReports() - )); - $result['visualization_properties']['graph']['max_graph_elements'] = 7; - return $result; + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->title = Piwik::translate('UserSettings_ColumnBrowserVersion'); + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnBrowserVersion')); + $view->config->addRelatedReports($this->getBrowserRelatedReports()); + + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->max_graph_elements = 7; + } } - private function getDisplayPropertiesForGetBrowser() + private function configureViewForGetBrowser(ViewDataTable $view) { - $result = array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnBrowser')), - 'title' => Piwik::translate('UserSettings_Browsers'), - 'related_reports' => $this->getBrowserRelatedReports() - )); - $result['visualization_properties']['graph']['max_graph_elements'] = 7; - return $result; + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->title = Piwik::translate('UserSettings_Browsers'); + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnBrowser')); + $view->config->addRelatedReports($this->getBrowserRelatedReports()); + + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->max_graph_elements = 7; + } } - private function getDisplayPropertiesForGetBrowserType() + private function configureViewForGetBrowserType(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnBrowserFamily')), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnBrowserFamily')); + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + $view->config->show_limit_control = false; } - private function getDisplayPropertiesForGetWideScreen() + private function configureViewForGetWideScreen(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_ColumnTypeOfScreen')), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'title' => Piwik::translate('UserSettings_ColumnTypeOfScreen'), - 'related_reports' => $this->getWideScreenDeviceTypeRelatedReports() - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->title = Piwik::translate('UserSettings_ColumnTypeOfScreen'); + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + $view->config->show_limit_control = false; + $view->config->addTranslation('label', Piwik::translate('UserSettings_ColumnTypeOfScreen')); + $view->config->addRelatedReports($this->getWideScreenDeviceTypeRelatedReports()); } - private function getDisplayPropertiesForGetMobileVsDesktop() + private function configureViewForGetMobileVsDesktop(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array('label' => Piwik::translate('UserSettings_MobileVsDesktop')), - 'title' => Piwik::translate('UserSettings_MobileVsDesktop'), - 'related_reports' => $this->getWideScreenDeviceTypeRelatedReports() - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->title = Piwik::translate('UserSettings_MobileVsDesktop'); + $view->config->addTranslation('label', Piwik::translate('UserSettings_MobileVsDesktop')); + $view->config->addRelatedReports($this->getWideScreenDeviceTypeRelatedReports()); } - private function getDisplayPropertiesForGetPlugin() + private function configureViewForGetPlugin(ViewDataTable $view) { - return array_merge($this->getBasicUserSettingsDisplayProperties(), array( - 'translations' => array( - 'label' => Piwik::translate('General_Plugin'), - 'nb_visits_percentage' => - str_replace(' ', ' ', Piwik::translate('General_ColumnPercentageVisits')) - ), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'show_all_views_icons' => false, - 'show_table_all_columns' => false, - 'columns_to_display' => array('label', 'nb_visits_percentage', 'nb_visits'), - 'filter_sort_column' => 'nb_visits_percentage', - 'filter_sort_order' => 'desc', - 'filter_limit' => 10, - 'show_footer_message' => Piwik::translate('UserSettings_PluginDetectionDoesNotWorkInIE'), - )); + $this->getBasicUserSettingsDisplayProperties($view); + + $view->config->addTranslations(array( + 'label' => Piwik::translate('General_Plugin'), + 'nb_visits_percentage' => + str_replace(' ', ' ', Piwik::translate('General_ColumnPercentageVisits')) + )); + + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + $view->config->show_limit_control = false; + $view->config->show_all_views_icons = false; + $view->config->show_table_all_columns = false; + $view->config->columns_to_display = array('label', 'nb_visits_percentage', 'nb_visits'); + $view->config->show_footer_message = Piwik::translate('UserSettings_PluginDetectionDoesNotWorkInIE'); + + $view->requestConfig->filter_sort_column = 'nb_visits_percentage'; + $view->requestConfig->filter_sort_order = 'desc'; + $view->requestConfig->filter_limit = 10; } - private function getDisplayPropertiesForGetLanguage() + private function configureViewForGetLanguage(ViewDataTable $view) { - return array( - 'translations' => array('label' => Piwik::translate('General_Language')), - 'filter_sort_column' => 'nb_visits', - 'filter_sort_order' => 'desc', - 'show_search' => false, - 'columns_to_display' => array('label', 'nb_visits'), - 'show_exclude_low_population' => false, - ); + $view->config->show_search = false; + $view->config->columns_to_display = array('label', 'nb_visits'); + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('General_Language')); + + $view->requestConfig->filter_sort_column = 'nb_visits'; + $view->requestConfig->filter_sort_order = 'desc'; } private function getWideScreenDeviceTypeRelatedReports() @@ -341,18 +374,16 @@ class UserSettings extends \Piwik\Plugin ); } - private function getBasicUserSettingsDisplayProperties() + private function getBasicUserSettingsDisplayProperties(ViewDataTable $view) { - return array( - 'show_search' => false, - 'show_exclude_low_population' => false, - 'filter_limit' => 5, - 'visualization_properties' => array( - 'graph' => array( - 'max_graph_elements' => 5 - ) - ) - ); + $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; + } } /** diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index 22130bb948..0f4ad71b28 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -17,6 +17,8 @@ use Piwik\Common; use Piwik\Menu\MenuMain; use Piwik\Period; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Bar; use Piwik\Site; use Piwik\WidgetsList; @@ -40,7 +42,7 @@ class VisitTime extends \Piwik\Plugin 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', 'API.getReportMetadata' => 'getReportMetadata', 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ViewDataTable.configure' => 'configureViewDataTable', 'Visualization.getDefaultViewTypeForReports' => 'getDefaultViewTypeForReports' ); return $hooks; @@ -131,60 +133,66 @@ class VisitTime extends \Piwik\Plugin $defaultViewTypes['VisitTime.getByDayOfWeek'] = Bar::ID; } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $commonProperties = array( - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'show_search' => false, - 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false - ); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'VisitTime.getVisitInformationPerServerTime': + $this->setBasicConfigViewProperties($view); + $this->configureViewForVisitInformationPerServerTime($view); + break; + case 'VisitTime.getVisitInformationPerLocalTime': + $this->setBasicConfigViewProperties($view); + $this->configureViewForVisitInformationPerLocalTime($view); + break; + case 'VisitTime.getByDayOfWeek': + $this->setBasicConfigViewProperties($view); + $this->configureViewForByDayOfWeek($view); + break; + } + } - $properties['VisitTime.getVisitInformationPerServerTime'] = array_merge($commonProperties, array( - 'filter_limit' => 24, - 'show_goals' => true, - 'translations' => array('label' => Piwik::translate('VisitTime_ColumnServerTime')), - 'request_parameters_to_modify' => array('hideFutureHoursWhenToday' => 1), - 'visualization_properties' => array( - 'graph' => array( - 'max_graph_elements' => false, - ) - ) - )); - - $properties['VisitTime.getVisitInformationPerLocalTime'] = array_merge($commonProperties, array( - 'filter_limit' => 24, - 'title' => Piwik::translate('VisitTime_ColumnLocalTime'), - 'translations' => array('label' => Piwik::translate('VisitTime_LocalTime')), - 'visualization_properties' => array( - 'graph' => array( - 'max_graph_elements' => false, - ) - ) - )); - - $properties['VisitTime.getByDayOfWeek'] = array_merge($commonProperties, array( - 'filter_limit' => 7, - 'enable_sort' => false, - 'show_footer_message' => - Piwik::translate('General_ReportGeneratedFrom', self::getDateRangeForFooterMessage()), - 'translations' => array('label' => Piwik::translate('VisitTime_DayOfWeek')), - 'visualization_properties' => array( - 'graph' => array( - 'show_all_ticks' => true, - 'max_graph_elements' => false, - ) - ) - )); + protected function configureViewForVisitInformationPerServerTime(ViewDataTable $view) + { + $view->requestConfig->filter_limit = 24; + $view->requestConfig->request_parameters_to_modify['hideFutureHoursWhenToday'] = 1; + + $view->config->show_goals = true; + $view->config->addTranslation('label', Piwik::translate('VisitTime_ColumnServerTime')); + + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->max_graph_elements = false; + } + } + + protected function configureViewForVisitInformationPerLocalTime(ViewDataTable $view) + { + $view->requestConfig->filter_limit = 24; + + $view->config->title = Piwik::translate('VisitTime_ColumnLocalTime'); + $view->config->addTranslation('label', Piwik::translate('VisitTime_LocalTime')); + + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->max_graph_elements = false; + } // add the visits by day of week as a related report, if the current period is not 'day' if (Common::getRequestVar('period', 'day') != 'day') { - $properties['VisitTime.getVisitInformationPerLocalTime']['related_reports'] = array( - 'VisitTime.getByDayOfWeek' => Piwik::translate('VisitTime_VisitsByDayOfWeek') - ); + $view->config->addRelatedReport('VisitTime.getByDayOfWeek', Piwik::translate('VisitTime_VisitsByDayOfWeek')); + } + + } + + 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; } } @@ -228,4 +236,18 @@ class VisitTime extends \Piwik\Plugin } return $dateRange; } + + /** + * @param ViewDataTable $view + */ + private function setBasicConfigViewProperties(ViewDataTable $view) + { + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->config->show_search = false; + $view->config->show_limit_control = false; + $view->config->show_exclude_low_population = false; + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + } }
\ No newline at end of file diff --git a/plugins/VisitorInterest/VisitorInterest.php b/plugins/VisitorInterest/VisitorInterest.php index ca009b8fd9..ccfe90c03a 100644 --- a/plugins/VisitorInterest/VisitorInterest.php +++ b/plugins/VisitorInterest/VisitorInterest.php @@ -16,7 +16,9 @@ use Piwik\FrontController; use Piwik\Menu\MenuMain; use Piwik\Metrics; use Piwik\Piwik; +use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\Cloud; +use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; use Piwik\WidgetsList; /** @@ -36,7 +38,7 @@ class VisitorInterest extends \Piwik\Plugin 'WidgetsList.addWidgets' => 'addWidgets', 'Menu.Reporting.addItems' => 'addMenu', 'API.getReportMetadata' => 'getReportMetadata', - 'Visualization.getReportDisplayProperties' => 'getReportDisplayProperties', + 'ViewDataTable.configure' => 'configureViewDataTable', 'Visualization.getDefaultViewTypeForReports' => 'getDefaultViewTypeForReports' ); return $hooks; @@ -159,95 +161,99 @@ class VisitorInterest extends \Piwik\Plugin $defaultViewTypes['VisitorInterest.getNumberOfVisitsPerPage'] = Cloud::ID; } - public function getReportDisplayProperties(&$properties) + public function configureViewDataTable(ViewDataTable $view) { - $properties['VisitorInterest.getNumberOfVisitsPerVisitDuration'] = - $this->getDisplayPropertiesForGetNumberOfVisitsPerVisitDuration(); - $properties['VisitorInterest.getNumberOfVisitsPerPage'] = - $this->getDisplayPropertiesForGetNumberOfVisitsPerPage(); - $properties['VisitorInterest.getNumberOfVisitsByVisitCount'] = - $this->getDisplayPropertiesForGetNumberOfVisitsByVisitCount(); - $properties['VisitorInterest.getNumberOfVisitsByDaysSinceLast'] = - $this->getDisplayPropertiesForGetNumberOfVisitsByDaysSinceLast(); + switch ($view->requestConfig->apiMethodToRequestDataTable) { + case 'VisitorInterest.getNumberOfVisitsPerVisitDuration': + $this->configureViewForGetNumberOfVisitsPerVisitDuration($view); + break; + case 'VisitorInterest.getNumberOfVisitsPerPage': + $this->configureViewForGetNumberOfVisitsPerPage($view); + break; + case 'VisitorInterest.getNumberOfVisitsByVisitCount': + $this->configureViewForGetNumberOfVisitsByVisitCount($view); + break; + case 'VisitorInterest.getNumberOfVisitsByDaysSinceLast': + $this->configureViewForGetNumberOfVisitsByDaysSinceLast($view); + break; + } } - private function getDisplayPropertiesForGetNumberOfVisitsPerVisitDuration() + private function configureViewForGetNumberOfVisitsPerVisitDuration(ViewDataTable $view) { - return array( - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array('label' => Piwik::translate('VisitorInterest_ColumnVisitDuration')), - 'enable_sort' => false, - 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'show_search' => false, - 'show_table_all_columns' => false, - 'visualization_properties' => array( - 'graph' => array( - 'max_graph_elements' => 10 - ) - ) - ); + $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; + + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->max_graph_elements = 10; + } } - private function getDisplayPropertiesForGetNumberOfVisitsPerPage() + private function configureViewForGetNumberOfVisitsPerPage(ViewDataTable $view) { - return array( - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array('label' => Piwik::translate('VisitorInterest_ColumnPagesPerVisit')), - 'enable_sort' => false, - 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'show_search' => false, - 'show_table_all_columns' => false, - 'visualization_properties' => array( - 'graph' => array( - 'max_graph_elements' => 10 - ) - ) - ); + $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; + + if ($view->isViewDataTableId(Graph::ID)) { + $view->config->max_graph_elements = 10; + } } - private function getDisplayPropertiesForGetNumberOfVisitsByVisitCount() + private function configureViewForGetNumberOfVisitsByVisitCount(ViewDataTable $view) { - return array( - 'columns_to_display' => array('label', 'nb_visits', 'nb_visits_percentage'), - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array('label' => Piwik::translate('VisitorInterest_VisitNum'), - 'nb_visits_percentage' => Metrics::getPercentVisitColumn()), - 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'filter_limit' => 15, - 'show_search' => false, - 'enable_sort' => false, - 'show_table_all_columns' => false, - 'show_all_views_icons' => false, + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->requestConfig->filter_limit = 15; + + $view->config->addTranslations(array( + 'label' => Piwik::translate('VisitorInterest_VisitNum'), + 'nb_visits_percentage' => Metrics::getPercentVisitColumn()) ); + + $view->config->columns_to_display = array('label', 'nb_visits', 'nb_visits_percentage'); + $view->config->show_exclude_low_population = false; + + $view->config->enable_sort = 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->show_all_views_icons = false; } - private function getDisplayPropertiesForGetNumberOfVisitsByDaysSinceLast() + private function configureViewForGetNumberOfVisitsByDaysSinceLast(ViewDataTable $view) { - return array( - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array('label' => Piwik::translate('General_DaysSinceLastVisit')), - 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_limit_control' => false, - 'show_all_views_icons' => false, - 'filter_limit' => 15, - 'show_search' => false, - 'enable_sort' => false, - 'show_table_all_columns' => false - ); + $view->requestConfig->filter_sort_column = 'label'; + $view->requestConfig->filter_sort_order = 'asc'; + $view->requestConfig->filter_limit = 15; + + $view->config->show_search = false; + $view->config->enable_sort = false; + $view->config->show_offset_information = false; + $view->config->show_pagination_control = false; + $view->config->show_limit_control = false; + $view->config->show_all_views_icons = false; + $view->config->show_table_all_columns = false; + $view->config->show_exclude_low_population = false; + $view->config->addTranslation('label', Piwik::translate('General_DaysSinceLastVisit')); } }
\ No newline at end of file |