diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-07-12 10:31:39 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-07-12 10:31:39 +0400 |
commit | 01057779046dd67923bd34d123628ab60ed263bc (patch) | |
tree | 94353df4f7848f2de63f3eeb0c9eeed2020965c8 /plugins/Actions | |
parent | 98e6c9b8874ffc8c18570ed4cc062cc5f0eb80c0 (diff) |
Refs #4040, #4041, move all ViewDataTable properties to the viewProperties array and allow these properties to be specified through new display metadata. Converted the Actions, Goals, UserSettings and VisitTime controllers.
Notes:
- Includes refactoring of ExcludeLowPopulation filter.
Diffstat (limited to 'plugins/Actions')
-rw-r--r-- | plugins/Actions/API.php | 19 | ||||
-rw-r--r-- | plugins/Actions/Actions.php | 415 | ||||
-rw-r--r-- | plugins/Actions/Controller.php | 454 |
3 files changed, 451 insertions, 437 deletions
diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index 8eec6d2d1b..6d0b2898b5 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -38,25 +38,6 @@ class Piwik_Actions_API return self::$instance; } - - /** - * Backward compatibility. Fallsback to getPageTitles() instead. - * @deprecated Deprecated since Piwik 0.5 - * @ignore - * - * @param int $idSite - * @param string $period - * @param $date - * @param bool $segment - * @param bool $expanded - * @param bool|int $idSubtable - * @return Piwik_DataTable|Piwik_DataTable_Array - */ - public function getActions($idSite, $period, $date, $segment = false, $expanded = false, $idSubtable = false) - { - return $this->getPageTitles($idSite, $period, $date, $segment, $expanded, $idSubtable); - } - /** * Returns the list of metrics (pages, downloads, outlinks) * diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index fdae02efd0..efbbbb4f91 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -18,6 +18,22 @@ */ class Piwik_Actions extends Piwik_Plugin { + const ACTIONS_REPORT_ROWS_DISPLAY = 100; + + private $columnTranslations; + + public function __construct() + { + $this->columnTranslations = 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'), + ); + } + public function getInformation() { $info = array( @@ -32,16 +48,17 @@ class Piwik_Actions extends Piwik_Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenus', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenus', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } - + public function getSegmentsMetadata(&$segments) { $sqlFilter = array($this, 'getIdActionFromSegment'); @@ -605,5 +622,389 @@ class Piwik_Actions extends Piwik_Plugin throw new Exception(" The segment $segmentName has an unexpected value."); } } + + public function getReportDisplayProperties(&$properties, $apiAction) + { + $reportViewProperties = array( + 'Actions.getPageUrls' => $this->getDisplayPropertiesForPageUrls(), + 'Actions.getEntryPageUrls' => $this->getDisplayPropertiesForEntryPageUrls(), + 'Actions.getExitPageUrls' => $this->getDisplayPropertiesForExitPageUrls(), + 'Actions.getSiteSearchKeywords' => $this->getDisplayPropertiesForSiteSearchKeywords(), + 'Actions.getSiteSearchNoResultKeywords' => $this->getDisplayPropertiesForSiteSearchNoResultKeywords(), + 'Actions.getSiteSearchCategories' => $this->getDisplayPropertiesForSiteSearchCategories(), + 'Actions.getPageUrlsFollowingSiteSearch' => $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(false), + 'Actions.getPageTitlesFollowingSiteSearch' => $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(true), + 'Actions.getPageTitles' => $this->getDisplayPropertiesForGetPageTitles(), + 'Actions.getEntryPageTitles' => $this->getDisplayPropertiesForGetEntryPageTitles(), + 'Actions.getExitPageTitles' => $this->getDisplayPropertiesForGetExitPageTitles(), + 'Actions.getDownloads' => $this->getDisplayPropertiesForGetDownloads(), + 'Actions.getOutlinks' => $this->getDisplayPropertiesForGetOutlinks(), + ); + + if (isset($reportViewProperties[$apiAction])) { + $properties = $reportViewProperties[$apiAction]; + } + } + + private function addBaseDisplayProperties(&$result) + { + $result['datatable_css_class'] = 'dataTableActions'; + $result['datatable_js_type'] = 'actionDataTable'; + $result['subtable_template'] = '@CoreHome/_dataTableActions_subDataTable.twig'; + $result['search_recursive'] = true; + $result['show_all_views_icons'] = false; + $result['show_table_all_columns'] = false; + $result['filter_limit'] = self::ACTIONS_REPORT_ROWS_DISPLAY; + + // 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); + + if (Piwik_ViewDataTable::shouldLoadExpanded()) { + $result['show_expanded'] = true; + + $result['filters'][] = function ($dataTable) { + Piwik_Actions::setDataTableRowLevels($dataTable); + }; + } + + return $result; + } + + public static function setDataTableRowLevels($dataTable, $level = 0) + { + foreach ($dataTable->getRows() as $row) { + $row->setMetadata('css_class', 'level'.$level); + + $subtable = $row->getSubtable(); + if ($subtable) { + self::setDataTableRowLevels($subtable, $level + 1); + } + } + } + + private function addExcludeLowPopDisplayProperties(&$result) + { + if (Piwik_Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') != '0') { + $result['filter_excludelowpop'] = 'nb_hits'; + $result['filter_excludelowpop_value'] = function () { + // computing minimum value to exclude (2 percent of the total number of actions) + $visitsInfo = Piwik_VisitsSummary_Controller::getVisitsSummary()->getFirstRow(); + $nbActions = $visitsInfo->getColumn('nb_actions'); + $nbActionsLowPopulationThreshold = floor(0.02 * $nbActions); + + // we remove 1 to make sure some actions/downloads are displayed in the case we have a very few of them + // and each of them has 1 or 2 hits... + return min($visitsInfo->getColumn('max_actions') - 1, $nbActionsLowPopulationThreshold - 1); + }; + } + } + + private function addPageDisplayProperties(&$result) + { + // add common translations + $result['translations'] += 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 = array('Piwik', 'getPrettyTimeFromSeconds'); + $result['filters'][] = array('ColumnCallbackReplace', array('avg_time_on_page', $getPrettyTimeFromSeconds)); + + // prettify avg_time_generation column + $avgTimeCallback = function ($time) { + return $time ? Piwik::getPrettyTimeFromSeconds($time, true, true, false) : "-"; + }; + $result['filters'][] = array('ColumnCallbackReplace', array('avg_time_generation', $avgTimeCallback)); + + // add avg_generation_time tooltip + $tooltipCallback = function ($hits, $min, $max) { + if (!$hits) { + return false; + } + + return Piwik_Translate("Actions_AvgGenerationTimeTooltip", array( + $hits, + "<br />", + Piwik::getPrettyTimeFromSeconds($min), + Piwik::getPrettyTimeFromSeconds($max) + )); + }; + $result['filters'][] = array('ColumnCallbackAddMetadata', + array( + array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'), + 'avg_time_generation_tooltip', + $tooltipCallback + ) + ); + + $this->addExcludeLowPopDisplayProperties($result); + } + + public function getDisplayPropertiesForPageUrls() + { + $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'), + ); + + $this->addPageDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForEntryPageUrls() + { + // link to the page, not just the report, but only if not a widget + $widget = Piwik_Common::getRequestVar('widget', false); + $reportUrl = Piwik_API_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'), + 'relatedReports' => array( + 'Actions.getEntryPageTitles' => Piwik_Translate('Actions_EntryPageTitles') + ), + 'self_url' => $reportUrl + ); + + $this->addPageDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForExitPageUrls() + { + // link to the page, not just the report, but only if not a widget + $widget = Piwik_Common::getRequestVar('widget', false); + $reportUrl = Piwik_API_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'), + 'relatedReports' => array( + 'Actions.getExitPageTitles' => Piwik_Translate('Actions_ExitPageTitles') + ), + 'self_url' => $reportUrl, + ); + + $this->addPageDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + private function addSiteSearchDisplayProperties(&$result) + { + $result['translations'] += 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; + } + + public function getDisplayPropertiesForSiteSearchKeywords() + { + $result = array( + 'translations' => array('label' => Piwik_Translate('Actions_ColumnSearchKeyword')), + 'columns_to_display' => array('label', 'nb_visits', 'nb_pages_per_search', 'exit_rate'), + ); + + $this->addSiteSearchDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForSiteSearchNoResultKeywords() + { + $result = array( + 'translations' => array('label', Piwik_Translate('Actions_ColumnNoResultKeyword')), + 'columns_to_display' => array('label', 'nb_visits', 'exit_rate') + ); + + $this->addSiteSearchDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForSiteSearchCategories() + { + 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, + 'disable_row_evolution' => false, + ); + } + + public function getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch($isTitle) + { + $title = $isTitle ? Piwik_Translate('Actions_WidgetPageTitlesFollowingSearch') + : Piwik_Translate('Actions_WidgetPageUrlsFollowingSearch'); + + $relatedReports = array( + 'Actions.getPageTitlesFollowingSiteSearch' => Piwik_Translate('Actions_WidgetPageTitlesFollowingSearch'), + '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, + 'relatedReports' => $relatedReports + ); + + $this->addExcludeLowPopDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForGetPageTitles() + { + // link to the page, not just the report, but only if not a widget + $widget = Piwik_Common::getRequestVar('widget', false); + $reportUrl = Piwik_API_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'), + 'relatedReports' => array( + 'Actions.getEntryPageTitles' => Piwik_Translate('Actions_EntryPageTitles'), + 'Actions.getExitPageTitles' => Piwik_Translate('Actions_ExitPageTitles'), + ), + 'self_url' => $reportUrl + ); + + $this->addPageDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForGetEntryPageTitles() + { + $entryPageUrlAction = + Piwik_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'), + 'relatedReports' => array( + 'Actions.getPageTitles' => Piwik_Translate('Actions_SubmenuPageTitles'), + "Actions.$entryPageUrlAction" => Piwik_Translate('Actions_SubmenuPagesEntry') + ), + ); + + $this->addPageDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForGetExitPageTitles() + { + $exitPageUrlAction = + Piwik_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'), + 'relatedReports' => array( + 'Actions.getPageTitles' => Piwik_Translate('Actions_SubmenuPageTitles'), + "Actions.$exitPageUrlAction" => Piwik_Translate('Actions_SubmenuPagesExit'), + ), + ); + + $this->addPageDisplayProperties($result); + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForGetDownloads() + { + $result = array( + 'translations' => array( + 'label' => Piwik_Translate('Actions_ColumnDownloadURL'), + 'nb_visits' => Piwik_Translate('Actions_ColumnUniqueDownloads'), + 'nb_hits' => Piwik_Translate('Actions_ColumnDownloads'), + ), + 'columns_to_display' => array('label', 'nb_visits', 'nb_hits'), + 'show_exclude_low_population' => false + ); + + $this->addBaseDisplayProperties($result); + + return $result; + } + + public function getDisplayPropertiesForGetOutlinks() + { + $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 + ); + + $this->addBaseDisplayProperties($result); + + return $result; + } } diff --git a/plugins/Actions/Controller.php b/plugins/Actions/Controller.php index 16473b60e0..f7597825e5 100644 --- a/plugins/Actions/Controller.php +++ b/plugins/Actions/Controller.php @@ -16,22 +16,10 @@ */ class Piwik_Actions_Controller extends Piwik_Controller { - const ACTIONS_REPORT_ROWS_DISPLAY = 100; - - protected function getPageUrlsView($currentAction, $controllerActionSubtable, $apiAction) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, $currentAction, $apiAction, $controllerActionSubtable); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnPageURL')); - return $view; - } - - /** - * PAGES - * @param bool $fetch - * @return string - */ - + // + // Actions that render whole pages + // + public function indexPageUrls($fetch = false) { return Piwik_View::singleReport( @@ -39,24 +27,6 @@ class Piwik_Actions_Controller extends Piwik_Controller $this->getPageUrls(true), $fetch); } - public function getPageUrls($fetch = false) - { - $view = $this->getPageUrlsView(__FUNCTION__, 'getPageUrls', 'Actions.getPageUrls'); - $this->configureViewPages($view); - $this->configureViewActions($view); - return $this->renderView($view, $fetch); - } - - protected function configureViewPages($view) - { - $view->setColumnsToDisplay(array('label', 'nb_hits', 'nb_visits', 'bounce_rate', 'avg_time_on_page', 'exit_rate', 'avg_time_generation')); - } - - /** - * ENTRY PAGES - * @param bool $fetch - * @return string|void - */ public function indexEntryPageUrls($fetch = false) { return Piwik_View::singleReport( @@ -64,30 +34,6 @@ class Piwik_Actions_Controller extends Piwik_Controller $this->getEntryPageUrls(true), $fetch); } - public function getEntryPageUrls($fetch = false) - { - $view = $this->getPageUrlsView(__FUNCTION__, 'getEntryPageUrls', 'Actions.getEntryPageUrls'); - $this->configureViewEntryPageUrls($view); - $this->configureViewActions($view); - return $this->renderView($view, $fetch); - } - - protected function configureViewEntryPageUrls($view) - { - $view->setSortedColumn('entry_nb_visits'); - $view->setColumnsToDisplay(array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate')); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnEntryPageURL')); - $view->setColumnTranslation('entry_bounce_count', Piwik_Translate('General_ColumnBounces')); - $view->setColumnTranslation('entry_nb_visits', Piwik_Translate('General_ColumnEntrances')); - $view->addRelatedReports(Piwik_Translate('Actions_SubmenuPagesEntry'), array( - 'Actions.getEntryPageTitles' => Piwik_Translate('Actions_EntryPageTitles') - )); - $view->setReportUrl('Actions', $this->getEntryPageUrlActionForLink()); - } - - /* - * EXIT PAGES - */ public function indexExitPageUrls($fetch = false) { return Piwik_View::singleReport( @@ -95,29 +41,6 @@ class Piwik_Actions_Controller extends Piwik_Controller $this->getExitPageUrls(true), $fetch); } - public function getExitPageUrls($fetch = false) - { - $view = $this->getPageUrlsView(__FUNCTION__, 'getExitPageUrls', 'Actions.getExitPageUrls'); - $this->configureViewExitPageUrls($view); - $this->configureViewActions($view); - return $this->renderView($view, $fetch); - } - - protected function configureViewExitPageUrls($view) - { - $view->setSortedColumn('exit_nb_visits'); - $view->setColumnsToDisplay(array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate')); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnExitPageURL')); - $view->setColumnTranslation('exit_nb_visits', Piwik_Translate('General_ColumnExits')); - $view->addRelatedReports(Piwik_Translate('Actions_SubmenuPagesExit'), array( - 'Actions.getExitPageTitles' => Piwik_Translate('Actions_ExitPageTitles') - )); - $view->setReportUrl('Actions', $this->getExitPageUrlActionForLink()); - } - - /* - * SITE SEARCH - */ public function indexSiteSearch() { $view = new Piwik_View('@Actions/indexSiteSearch'); @@ -134,87 +57,6 @@ class Piwik_Actions_Controller extends Piwik_Controller echo $view->render(); } - public function getSiteSearchKeywords($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getSiteSearchKeywords'); - $this->configureViewSiteSearchKeywords($view); - return $this->renderView($view, $fetch); - } - - public function getSiteSearchNoResultKeywords($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getSiteSearchNoResultKeywords'); - $this->configureViewSiteSearchKeywords($view); - $view->setColumnsToDisplay(array('label', 'nb_visits', 'exit_rate')); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnNoResultKeyword')); - return $this->renderView($view, $fetch); - } - - public function configureViewSiteSearchKeywords(Piwik_ViewDataTable $view) - { - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnSearchKeyword')); - $view->setColumnsToDisplay(array('label', 'nb_visits', 'nb_pages_per_search', 'exit_rate')); - $view->setColumnTranslation('nb_visits', Piwik_Translate('Actions_ColumnSearches')); - $view->setColumnTranslation('exit_rate', str_replace("% ", "% ", Piwik_Translate('Actions_ColumnSearchExits'))); - $view->setColumnTranslation('nb_pages_per_search', Piwik_Translate('Actions_ColumnPagesPerSearch')); - $view->disableShowBarChart(); - $view->disableShowAllColumns(); - } - - public function getSiteSearchCategories($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getSiteSearchCategories'); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnSearchCategory')); - $view->setColumnTranslation('nb_visits', Piwik_Translate('Actions_ColumnSearches')); - $view->setColumnsToDisplay(array('label', 'nb_visits', 'nb_pages_per_search')); - $view->setColumnTranslation('nb_pages_per_search', Piwik_Translate('Actions_ColumnPagesPerSearch')); - $view->disableShowAllColumns(); - $view->disableShowBarChart(); - $view->disableRowEvolution(); - return $this->renderView($view, $fetch); - } - - - public function getPageUrlsFollowingSiteSearch($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getPageUrlsFollowingSiteSearch', 'getPageUrlsFollowingSiteSearch'); - $view->addRelatedReports(Piwik_Translate('Actions_WidgetPageUrlsFollowingSearch'), array( - 'Actions.getPageTitlesFollowingSiteSearch' => Piwik_Translate('Actions_WidgetPageTitlesFollowingSearch'), - )); - $view = $this->configureViewPagesFollowingSiteSearch($view); - return $this->renderView($view, $fetch); - } - - public function getPageTitlesFollowingSiteSearch($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getPageTitlesFollowingSiteSearch', 'getPageTitlesFollowingSiteSearch'); - $view->addRelatedReports(Piwik_Translate('Actions_WidgetPageTitlesFollowingSearch'), array( - 'Actions.getPageUrlsFollowingSiteSearch' => Piwik_Translate('Actions_WidgetPageUrlsFollowingSearch'), - )); - $view = $this->configureViewPagesFollowingSiteSearch($view); - return $this->renderView($view, $fetch); - } - - public function configureViewPagesFollowingSiteSearch($view) - { - $view->setColumnsToDisplay(array('label', 'nb_hits_following_search', 'nb_hits')); - $view->setColumnTranslation('nb_hits_following_search', Piwik_Translate('General_ColumnViewedAfterSearch')); - $view->setColumnTranslation('label', Piwik_Translate('General_ColumnDestinationPage')); - $view->setSortedColumn('nb_hits_following_search'); - $view->setColumnTranslation('nb_hits', Piwik_Translate('General_ColumnTotalPageviews')); - $view->disableExcludeLowPopulation(); - $view = $this->configureViewActions($view, $doSetTranslations = false); - return $view; - } - - /* - * PAGE TITLES - */ public function indexPageTitles($fetch = false) { return Piwik_View::singleReport( @@ -222,93 +64,6 @@ class Piwik_Actions_Controller extends Piwik_Controller $this->getPageTitles(true), $fetch); } - public function getPageTitles($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Actions.getPageTitles', - 'getPageTitlesSubDataTable'); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnPageName')); - $view->addRelatedReports(Piwik_Translate('Actions_SubmenuPageTitles'), array( - 'Actions.getEntryPageTitles' => Piwik_Translate('Actions_EntryPageTitles'), - 'Actions.getExitPageTitles' => Piwik_Translate('Actions_ExitPageTitles'), - )); - $view->setReportUrl('Actions', $this->getPageTitlesActionForLink()); - $this->configureViewPages($view); - $this->configureViewActions($view); - return $this->renderView($view, $fetch); - } - - public function getPageTitlesSubDataTable($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Actions.getPageTitles', - 'getPageTitlesSubDataTable'); - $this->configureViewPages($view); - $this->configureViewActions($view); - return $this->renderView($view, $fetch); - } - - /** - * Echos or returns a report displaying analytics data for every unique entry - * page title. - * - * @param bool $fetch True to return the view as a string, false to echo it. - * @return string - */ - public function getEntryPageTitles($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getEntryPageTitles', __FUNCTION__); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnEntryPageTitle')); - $view->setColumnTranslation('entry_bounce_count', Piwik_Translate('General_ColumnBounces')); - $view->setColumnTranslation('entry_nb_visits', Piwik_Translate('General_ColumnEntrances')); - $view->setColumnsToDisplay(array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate')); - - $entryPageUrlAction = $this->getEntryPageUrlActionForLink(); - $view->addRelatedReports(Piwik_Translate('Actions_EntryPageTitles'), array( - 'Actions.getPageTitles' => Piwik_Translate('Actions_SubmenuPageTitles'), - "Actions.$entryPageUrlAction" => Piwik_Translate('Actions_SubmenuPagesEntry'), - )); - - $this->configureViewActions($view); - - return $this->renderView($view, $fetch); - } - - /** - * Echos or returns a report displaying analytics data for every unique exit - * page title. - * - * @param bool $fetch True to return the view as a string, false to echo it. - * @return string - */ - public function getExitPageTitles($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Actions.getExitPageTitles', __FUNCTION__); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnExitPageTitle')); - $view->setColumnTranslation('exit_nb_visits', Piwik_Translate('General_ColumnExits')); - $view->setColumnsToDisplay(array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate')); - - $exitPageUrlAction = $this->getExitPageUrlActionForLink(); - $view->addRelatedReports(Piwik_Translate('Actions_ExitPageTitles'), array( - 'Actions.getPageTitles' => Piwik_Translate('Actions_SubmenuPageTitles'), - "Actions.$exitPageUrlAction" => Piwik_Translate('Actions_SubmenuPagesExit'), - )); - - $this->configureViewActions($view); - - return $this->renderView($view, $fetch); - } - - /* - * DOWNLOADS - */ - public function indexDownloads($fetch = false) { return Piwik_View::singleReport( @@ -316,202 +71,79 @@ class Piwik_Actions_Controller extends Piwik_Controller $this->getDownloads(true), $fetch); } - public function getDownloads($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Actions.getDownloads', - 'getDownloadsSubDataTable'); - - $this->configureViewDownloads($view); - return $this->renderView($view, $fetch); - } - - public function getDownloadsSubDataTable($fetch = false) - { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Actions.getDownloads', - 'getDownloadsSubDataTable'); - $this->configureViewDownloads($view); - return $this->renderView($view, $fetch); - } - - - /* - * OUTLINKS - */ - public function indexOutlinks($fetch = false) { return Piwik_View::singleReport( Piwik_Translate('Actions_SubmenuOutlinks'), $this->getOutlinks(true), $fetch); } - - public function getOutlinks($fetch = false) + + // + // Actions that render individual reports + // + + public function getPageUrls($fetch = false) { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Actions.getOutlinks', - 'getOutlinksSubDataTable'); - $this->configureViewOutlinks($view); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - - public function getOutlinksSubDataTable($fetch = false) + + public function getEntryPageUrls($fetch = false) { - $view = Piwik_ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Actions.getOutlinks', - 'getOutlinksSubDataTable'); - $this->configureViewOutlinks($view); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - /* - * Page titles & Page URLs reports - */ - protected function configureViewActions($view, $doSetTranslations = true) + public function getExitPageUrls($fetch = false) { - if ($doSetTranslations) { - $view->setColumnTranslation('nb_hits', Piwik_Translate('General_ColumnPageviews')); - $view->setColumnTranslation('nb_visits', Piwik_Translate('General_ColumnUniquePageviews')); - $view->setColumnTranslation('avg_time_on_page', Piwik_Translate('General_ColumnAverageTimeOnPage')); - $view->setColumnTranslation('bounce_rate', Piwik_Translate('General_ColumnBounceRate')); - $view->setColumnTranslation('exit_rate', Piwik_Translate('General_ColumnExitRate')); - $view->setColumnTranslation('avg_time_generation', Piwik_Translate('General_ColumnAverageGenerationTime')); - - $view->queueFilter('ColumnCallbackReplace', array('avg_time_on_page', array('Piwik', 'getPrettyTimeFromSeconds'))); - - $avgTimeCallback = create_function('$time', 'return $time ? Piwik::getPrettyTimeFromSeconds($time, true, true, false) : "-";'); - $view->queueFilter('ColumnCallbackReplace', array('avg_time_generation', $avgTimeCallback)); - - $tooltipCallback = create_function('$hits, $min, $max', ' - return $hits ? - Piwik_Translate("Actions_AvgGenerationTimeTooltip", array( - $hits, "<br />", - Piwik::getPrettyTimeFromSeconds($min), - Piwik::getPrettyTimeFromSeconds($max) - )) - : false;'); - $view->queueFilter('ColumnCallbackAddMetadata', array( - array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'), - 'avg_time_generation_tooltip', $tooltipCallback)); - } - - if (Piwik_Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') != '0') { - // computing minimum value to exclude - $visitsInfo = Piwik_VisitsSummary_Controller::getVisitsSummary(); - $visitsInfo = $visitsInfo->getFirstRow(); - $nbActions = $visitsInfo->getColumn('nb_actions'); - $nbActionsLowPopulationThreshold = floor(0.02 * $nbActions); // 2 percent of the total number of actions - // we remove 1 to make sure some actions/downloads are displayed in the case we have a very few of them - // and each of them has 1 or 2 hits... - $nbActionsLowPopulationThreshold = min($visitsInfo->getColumn('max_actions') - 1, $nbActionsLowPopulationThreshold - 1); - - $view->setExcludeLowPopulation('nb_hits', $nbActionsLowPopulationThreshold); - } - - $this->configureGenericViewActions($view); - return $view; + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - /* - * Downloads report - */ - protected function configureViewDownloads($view) + public function getSiteSearchKeywords($fetch = false) { - $view->setColumnsToDisplay(array('label', 'nb_visits', 'nb_hits')); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnDownloadURL')); - $view->setColumnTranslation('nb_visits', Piwik_Translate('Actions_ColumnUniqueDownloads')); - $view->setColumnTranslation('nb_hits', Piwik_Translate('Actions_ColumnDownloads')); - $view->disableExcludeLowPopulation(); - $this->configureGenericViewActions($view); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - /* - * Outlinks report - */ - protected function configureViewOutlinks($view) + public function getSiteSearchNoResultKeywords($fetch = false) { - $view->setColumnsToDisplay(array('label', 'nb_visits', 'nb_hits')); - $view->setColumnTranslation('label', Piwik_Translate('Actions_ColumnClickedURL')); - $view->setColumnTranslation('nb_visits', Piwik_Translate('Actions_ColumnUniqueClicks')); - $view->setColumnTranslation('nb_hits', Piwik_Translate('Actions_ColumnClicks')); - $view->disableExcludeLowPopulation(); - $this->configureGenericViewActions($view); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - /* - * Common to all Actions reports, how to use the custom Actions Datatable html - */ - protected function configureGenericViewActions($view) + public function getSiteSearchCategories($fetch = false) { - $view->setDataTableCssClass('dataTableActions'); - $view->setJsType('actionDataTable'); - $view->setSubtableTemplate('@CoreHome/_dataTableActions_subDataTable.twig'); - - $view->setSearchRecursive(); - if (Piwik_ViewDataTable::shouldLoadExpanded()) { - $view->showExpanded(); - - // set levelN css class for each row - $self = $this; - $view->queueFilter(function ($dataTable) use ($self) { - $self->setDataTableRowLevels($dataTable); - }); - } - // disable Footer icons - $view->disableShowAllViewsIcons(); - $view->disableShowAllColumns(); - - $view->setLimit(self::ACTIONS_REPORT_ROWS_DISPLAY); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + } - // 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) - if (Piwik_Common::getRequestVar('flat', false) === false) { - $view->setCustomParameter('flat', 0); - } + public function getPageUrlsFollowingSiteSearch($fetch = false) + { + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + } - $view->main(); + public function getPageTitlesFollowingSiteSearch($fetch = false) + { + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - - public function setDataTableRowLevels($dataTable, $level = 0) + + public function getPageTitles($fetch = false) { - foreach ($dataTable->getRows() as $row) { - $row->setMetadata('css_class', 'level'.$level); - - $subtable = $row->getSubtable(); - if ($subtable) { - $this->setDataTableRowLevels($subtable, $level + 1); - } - } + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - /** Returns action to use when linking to the exit page URLs report. */ - private function getExitPageUrlActionForLink() + public function getEntryPageTitles($fetch = false) { - // link to the page not, just the report, but only if not a widget - return Piwik_Common::getRequestVar('widget', 0) == 0 ? 'indexExitPageUrls' : 'getExitPageUrls'; + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } + public function getExitPageTitles($fetch = false) + { + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + } - /** Returns action to use when linking to the entry page URLs report. */ - private function getEntryPageUrlActionForLink() + public function getDownloads($fetch = false) { - // link to the page not, just the report, but only if not a widget - return Piwik_Common::getRequestVar('widget', 0) == 0 ? 'indexEntryPageUrls' : 'getEntryPageUrls'; + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } - /** Returns action to use when linking to the page titles report. */ - private function getPageTitlesActionForLink() + public function getOutlinks($fetch = false) { - // link to the page not, just the report, but only if not a widget - return Piwik_Common::getRequestVar('widget', 0) == 0 ? 'indexPageTitles' : 'getPageTitles'; + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } } |