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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
* @package Piwik
*/
/**
*
* @package Piwik_
*/
abstract class Piwik_Controller
{
function __construct()
{
$aPluginName = explode('_', get_class($this));
$this->pluginName = $aPluginName[1];
$this->strDate = Piwik_Common::getRequestVar('date', 'yesterday','string');
// the date looks like YYYY-MM-DD we can build it
try{
$this->date = Piwik_Date::factory($this->strDate);
$this->strDate = $this->date->toString();
} catch(Exception $e){
// the date looks like YYYY-MM-DD,YYYY-MM-DD or other format
// case the date looks like a range
$this->date = null;
}
}
function getDefaultAction()
{
return 'index';
}
/* FACTORING // COPIED FROM Home_Controller */
protected function renderView($view, $fetch)
{
$view->main();
$rendered = $view->getView()->render();
if($fetch)
{
return $rendered;
}
echo $rendered;
}
protected function getLastUnitGraph($currentModuleName, $currentControllerAction, $apiMethod)
{
require_once "ViewDataTable/Graph.php";
$view = Piwik_ViewDataTable::factory(null, 'graphEvolution');
$view->init( $currentModuleName, $currentControllerAction, $apiMethod );
// if the date is not yet a nicely formatted date range ie. YYYY-MM-DD,YYYY-MM-DD we build it
// otherwise the current controller action is being called with the good date format already so it's fine
// see constructor
if( !is_null($this->date))
{
$view->setParametersToModify( $this->getGraphParamsModified( array('date'=>$this->strDate)));
}
return $view;
}
protected function getNumericValue( $methodToCall )
{
$requestString = 'method='.$methodToCall.'&format=original';
$request = new Piwik_API_Request($requestString);
return $request->process();
}
protected function getUrlSparkline( $action )
{
$params = $this->getGraphParamsModified(
array( 'viewDataTable' => 'sparkline',
'action' => $action)
);
$url = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
return $url;
}
/**
*
* @param array paramsToSet = array( 'date' => 'last50', 'viewDataTable' =>'sparkline' )
*/
protected function getGraphParamsModified($paramsToSet = array())
{
if(!isset($paramsToSet['range']))
{
$range = 'last30';
}
else
{
$range = $paramsToSet['range'];
}
if(!isset($paramsToSet['date']))
{
$endDate = $this->strDate;
}
else
{
$endDate = $paramsToSet['date'];
}
if(!isset($paramsToSet['period']))
{
$period = Piwik_Common::getRequestVar('period');
}
else
{
$period = $paramsToSet['period'];
}
$last30Relative = new Piwik_Period_Range($period, $range );
$last30Relative->setDefaultEndDate(new Piwik_Date($endDate));
$paramDate = $last30Relative->getDateStart()->toString() . "," . $last30Relative->getDateEnd()->toString();
$params = array_merge($paramsToSet , array( 'date' => $paramDate ) );
return $params;
}
}
|