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/VisitTime | |
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/VisitTime')
-rw-r--r-- | plugins/VisitTime/Controller.php | 73 | ||||
-rw-r--r-- | plugins/VisitTime/VisitTime.php | 89 |
2 files changed, 85 insertions, 77 deletions
diff --git a/plugins/VisitTime/Controller.php b/plugins/VisitTime/Controller.php index 769c102761..600262625c 100644 --- a/plugins/VisitTime/Controller.php +++ b/plugins/VisitTime/Controller.php @@ -25,83 +25,16 @@ class Piwik_VisitTime_Controller extends Piwik_Controller public function getVisitInformationPerServerTime($fetch = false) { - $view = $this->getGraph(__FUNCTION__, 'VisitTime.getVisitInformationPerServerTime', - 'VisitTime_ColumnServerTime'); - - $view->setCustomParameter('hideFutureHoursWhenToday', 1); - $view->enableShowGoals(); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } public function getVisitInformationPerLocalTime($fetch = false) { - $view = $this->getGraph(__FUNCTION__, 'VisitTime.getVisitInformationPerLocalTime', - 'VisitTime_ColumnLocalTime'); - - // add the visits by day of week as a related report, if the current period is not 'day' - if (Piwik_Common::getRequestVar('period', 'day') != 'day') { - $view->addRelatedReports(Piwik_Translate('VisitTime_LocalTime'), array( - 'VisitTime.getByDayOfWeek' => Piwik_Translate('VisitTime_VisitsByDayOfWeek') - )); - } - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } public function getByDayOfWeek($fetch = false) { - $view = $this->getGraph( - __FUNCTION__, 'VisitTime.getByDayOfWeek', 'VisitTime_DayOfWeek', $limit = 7, $sort = false); - $view->disableSort(); - - if ($view instanceof Piwik_ViewDataTable_GenerateGraphHTML) { - $view->showAllTicks(); - } - $dateRange = $this->getRangeDate(); - - $view->setFooterMessage(Piwik_Translate('General_ReportGeneratedFrom', $dateRange)); - - return $this->renderView($view, $fetch); - } - - protected function getRangeDate() - { - // get query params - $idSite = Piwik_Common::getRequestVar('idSite'); - $date = Piwik_Common::getRequestVar('date'); - $period = Piwik_Common::getRequestVar('period'); - - // create a period instance - $oPeriod = Piwik_Period::makePeriodFromQueryParams(Piwik_Site::getTimezoneFor($idSite), $period, $date); - - // set the footer message using the period start & end date - $start = $oPeriod->getDateStart()->toString(); - $end = $oPeriod->getDateEnd()->toString(); - if ($start == $end) { - $dateRange = $start; - } else { - $dateRange = $start . " – " . $end; - } - return $dateRange; - } - - private function getGraph($controllerMethod, $apiMethod, $labelTranslation, $limit = 24) - { - $view = Piwik_ViewDataTable::factory('graphVerticalBar'); - $view->init($this->pluginName, $controllerMethod, $apiMethod); - - - $view->setColumnTranslation('label', Piwik_Translate($labelTranslation)); - $view->setSortedColumn('label', 'asc'); - - $view->setLimit($limit); - $view->setGraphLimit($limit); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->disableOffsetInformationAndPaginationControls(); - $this->setMetricsVariablesView($view); - - return $view; + return Piwik_ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index 36ecd86f65..39934563e5 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -29,13 +29,14 @@ class Piwik_VisitTime extends Piwik_Plugin function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenu', - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenu', + 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } @@ -117,6 +118,59 @@ class Piwik_VisitTime extends Piwik_Plugin 'acceptedValues' => $acceptedValues ); } + + public function getReportDisplayProperties(&$properties, $apiAction) + { + $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, + 'default_view_type' => 'graphVerticalBar' + ); + + $reportViewProperties = array( + 'VisitTime.getVisitInformationPerServerTime' => array_merge($commonProperties, array( + 'filter_limit' => 24, + 'graph_limit' => 24, + 'show_goals' => true, + 'translations' => array('label' => Piwik_Translate('VisitTime_ColumnServerTime')), + + // custom parameter + 'hideFutureHoursWhenToday' => 1, + )), + + 'VisitTime.getVisitInformationPerLocalTime' => array_merge($commonProperties, array( + 'filter_limit' => 24, + 'graph_limit' => 24, + 'title' => Piwik_Translate('VisitTime_ColumnLocalTime'), + 'translations' => array('label' => Piwik_Translate('VisitTime_LocalTime')), + )), + + 'VisitTime.getByDayOfWeek' => array_merge($commonProperties, array( + 'filter_limit' => 7, + 'graph_limit' => 7, + 'enable_sort' => false, + 'show_all_ticks' => true, + 'show_footer_message' => + Piwik_Translate('General_ReportGeneratedFrom', self::getDateRangeForFooterMessage()), + 'translations' => array('label' => Piwik_Translate('VisitTime_DayOfWeek')), + )), + ); + + // add the visits by day of week as a related report, if the current period is not 'day' + if (Piwik_Common::getRequestVar('period', 'day') != 'day') { + $reportViewProperties['VisitTime.getVisitInformationPerLocalTime']['relatedReports'] = array( + 'VisitTime.getByDayOfWeek' => Piwik_Translate('VisitTime_VisitsByDayOfWeek') + ); + } + + if (isset($reportViewProperties[$apiAction])) { + $properties = $reportViewProperties[$apiAction]; + } + } public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { @@ -134,4 +188,25 @@ class Piwik_VisitTime extends Piwik_Plugin $archiving->archiveDay(); } } + + private static function getDateRangeForFooterMessage() + { + // get query params + $idSite = Piwik_Common::getRequestVar('idSite'); + $date = Piwik_Common::getRequestVar('date'); + $period = Piwik_Common::getRequestVar('period'); + + // create a period instance + $oPeriod = Piwik_Period::makePeriodFromQueryParams(Piwik_Site::getTimezoneFor($idSite), $period, $date); + + // set the footer message using the period start & end date + $start = $oPeriod->getDateStart()->toString(); + $end = $oPeriod->getDateEnd()->toString(); + if ($start == $end) { + $dateRange = $start; + } else { + $dateRange = $start . " – " . $end; + } + return $dateRange; + } } |