|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Google Analytics Report |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
|
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gplcart\modules\ga_report\controllers; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
|
13
|
|
|
use gplcart\modules\ga_report\models\Report as ReportModel; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Handles incoming requests and outputs data related to Google Analytics Report module |
|
17
|
|
|
*/ |
|
18
|
|
|
class Report extends Controller |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Report model instance |
|
23
|
|
|
* @var \gplcart\modules\ga_report\models\Report $report_model |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $report_model; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param ReportModel $model |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(ReportModel $model) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
|
|
34
|
|
|
$this->report_model = $model; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Route callback |
|
39
|
|
|
* Displays the report page |
|
40
|
|
|
*/ |
|
41
|
|
|
public function listReport() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setTitleListReport(); |
|
44
|
|
|
$this->setBreadcrumbListReport(); |
|
45
|
|
|
$this->clearCacheReport(); |
|
46
|
|
|
|
|
47
|
|
|
$this->setData('stores', $this->store->getList()); |
|
48
|
|
|
$this->setData('panels', $this->getPanelsReport()); |
|
49
|
|
|
|
|
50
|
|
|
$default = $this->module->getSettings('ga_report', 'store_id'); |
|
51
|
|
|
$this->setData('ga_store_id', $this->getQuery('ga.update.store_id', $default)); |
|
52
|
|
|
|
|
53
|
|
|
$this->outputListReport(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Set title on the report page |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function setTitleListReport() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->setTitle($this->text('Google Analytics')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Set breadcrumbs on the report page |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function setBreadcrumbListReport() |
|
68
|
|
|
{ |
|
69
|
|
|
$breadcrumb = array( |
|
70
|
|
|
'url' => $this->url('admin'), |
|
71
|
|
|
'text' => $this->text('Dashboard') |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$this->setBreadcrumb($breadcrumb); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Clear cache |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function clearCacheReport() |
|
81
|
|
|
{ |
|
82
|
|
|
if ($this->isQuery('ga.update')) { |
|
83
|
|
|
$store_id = $this->getQuery('ga.update.store_id', ''); |
|
84
|
|
|
$handler_id = $this->getQuery('ga.update.handler_id', ''); |
|
85
|
|
|
$this->report_model->clearCache($handler_id, $store_id); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Returns an array of report panels |
|
91
|
|
|
* @return array |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getPanelsReport() |
|
94
|
|
|
{ |
|
95
|
|
|
$settings = $this->module->getSettings('ga_report'); |
|
96
|
|
|
$store_id = $this->getQuery('ga.update.store_id'); |
|
97
|
|
|
|
|
98
|
|
|
if (!empty($store_id)) { |
|
99
|
|
|
$settings['store_id'] = $store_id; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$panels = array(); |
|
103
|
|
|
|
|
104
|
|
|
foreach ($this->report_model->getHandlers() as $handler) { |
|
105
|
|
|
|
|
106
|
|
|
$report = $this->report_model->get($handler, $settings); |
|
107
|
|
|
|
|
108
|
|
|
$data = array( |
|
109
|
|
|
'content' => array( |
|
110
|
|
|
'data' => array( // We need so deep nesting for compatibility with dashboard panel templates |
|
111
|
|
|
'report' => $report, |
|
112
|
|
|
'handler' => $handler, |
|
113
|
|
|
'settings' => $settings |
|
114
|
|
|
) |
|
115
|
|
|
) |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$panels[$handler['id']] = array('rendered' => $this->render($handler['template'], $data)); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return gplcart_array_split($panels, 3); // Split by columns |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Render and output the Google Analytics report page |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function outputListReport() |
|
128
|
|
|
{ |
|
129
|
|
|
$this->output('ga_report|list'); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|