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; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Main class for Google Analytics Report module |
16
|
|
|
*/ |
17
|
|
|
class GaReport extends Module |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
use \gplcart\modules\ga_report\traits\ControllerTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Implements hook "route.list" |
32
|
|
|
* @param array $routes |
33
|
|
|
*/ |
34
|
|
|
public function hookRouteList(array &$routes) |
35
|
|
|
{ |
36
|
|
|
// Module settings page |
37
|
|
|
$routes['admin/module/settings/ga_report'] = array( |
38
|
|
|
'access' => 'module_edit', |
39
|
|
|
'handlers' => array( |
40
|
|
|
'controller' => array('gplcart\\modules\\ga_report\\controllers\\Settings', 'editSettings') |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
// Google Analytics reports |
45
|
|
|
$routes['admin/report/ga'] = array( |
46
|
|
|
'menu' => array('admin' => 'Google Analytics'), |
47
|
|
|
'access' => 'ga_report', |
48
|
|
|
'handlers' => array( |
49
|
|
|
'controller' => array('gplcart\\modules\\ga_report\\controllers\\Report', 'listReport') |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Implements hook "user.role.permissions" |
56
|
|
|
* @param array $permissions |
57
|
|
|
*/ |
58
|
|
|
public function hookUserRolePermissions(array &$permissions) |
59
|
|
|
{ |
60
|
|
|
$permissions['ga_report'] = 'Google Analytics reports: access'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Implements hook "oauth.providers" |
65
|
|
|
* @param array $providers |
66
|
|
|
*/ |
67
|
|
|
public function hookOauthProviders(array &$providers) |
68
|
|
|
{ |
69
|
|
|
$providers['ga'] = array( |
70
|
|
|
'name' => 'Google analytics', |
71
|
|
|
'settings' => $this->config->module('ga_report'), |
72
|
|
|
'url' => array( |
73
|
|
|
'process' => 'https://www.googleapis.com/analytics/v3/data/ga', |
74
|
|
|
'token' => 'https://www.googleapis.com/oauth2/v4/token' |
75
|
|
|
), |
76
|
|
|
'scope' => 'https://www.googleapis.com/auth/analytics.readonly', |
77
|
|
|
'handlers' => array( |
78
|
|
|
'token' => array('gplcart\\modules\\ga_report\\handlers\\Api', 'token'), |
79
|
|
|
'process' => array('gplcart\\modules\\ga_report\\handlers\\Api', 'process'), |
80
|
|
|
) |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Implements hook "template.dashboard" |
86
|
|
|
* @param array $panels |
87
|
|
|
* @param \gplcart\core\controllers\backend\Controller $controller |
88
|
|
|
*/ |
89
|
|
|
public function hookTemplateDashboard(array &$panels, $controller) |
90
|
|
|
{ |
91
|
|
|
/* @var $model \gplcart\modules\ga_report\models\Report */ |
92
|
|
|
$model = $this->getInstance('gplcart\\modules\\ga_report\\models\\Report'); |
93
|
|
|
|
94
|
|
|
$this->clearCacheGaReport($model, $controller); |
95
|
|
|
|
96
|
|
|
$settings = $this->config->module('ga_report'); |
97
|
|
|
$ga_panels = $this->getPanelsGaReport($settings, $model, $controller); |
98
|
|
|
|
99
|
|
|
$weight = count($panels); |
100
|
|
|
foreach ($ga_panels as $id => $panel) { |
101
|
|
|
if (in_array($id, $settings['dashboard']) && $controller->access('ga_report')) { |
102
|
|
|
$panel['weight'] = $weight; |
103
|
|
|
$panels[$id] = $panel; |
104
|
|
|
$weight++; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|