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/Controller.php | |
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/Controller.php')
-rw-r--r-- | plugins/Actions/Controller.php | 454 |
1 files changed, 43 insertions, 411 deletions
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); } } |