1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Piwik_VisitTime
*/
/**
*
* @package Piwik_VisitTime
*/
class Piwik_VisitTime_Controller extends Piwik_Controller
{
public function index()
{
$view = new Piwik_View('@VisitTime/index');
$view->dataTableVisitInformationPerLocalTime = $this->getVisitInformationPerLocalTime(true);
$view->dataTableVisitInformationPerServerTime = $this->getVisitInformationPerServerTime(true);
echo $view->render();
}
public function getVisitInformationPerServerTime($fetch = false)
{
$view = $this->getGraph(__FUNCTION__, 'VisitTime.getVisitInformationPerServerTime',
'VisitTime_ColumnServerTime');
$view->setCustomParameter('hideFutureHoursWhenToday', 1);
$view->enableShowGoals();
return $this->renderView($view, $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);
}
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;
}
}
|