1755c393
Yarik
Basic template in...
|
1
|
<?php
|
543b9b1c
Yarik
Composer ready
|
2
|
namespace backend\controllers;
|
3cae1b75
Alexey Boroda
-Analytics almost...
|
3
4
5
|
use backend\models\Analytics;
use common\models\Settings;
|
543b9b1c
Yarik
Composer ready
|
6
7
8
9
10
|
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
|
6b69a279
Alexey Boroda
-GA js ready
|
11
12
|
use yii\web\Response;
|
1755c393
Yarik
Basic template in...
|
13
|
/**
|
543b9b1c
Yarik
Composer ready
|
14
|
* Site controller
|
1755c393
Yarik
Basic template in...
|
15
|
*/
|
543b9b1c
Yarik
Composer ready
|
16
|
class SiteController extends Controller
|
1755c393
Yarik
Basic template in...
|
17
|
{
|
543b9b1c
Yarik
Composer ready
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => [
'login',
'error',
],
'allow' => true,
],
[
'actions' => [
'logout',
'index',
|
6b69a279
Alexey Boroda
-GA js ready
|
38
|
'analytics',
|
543b9b1c
Yarik
Composer ready
|
39
40
41
|
],
'allow' => true,
'roles' => [ '@' ],
|
0bdfedea
Alexey Boroda
-Analytics started
|
42
|
],
|
1755c393
Yarik
Basic template in...
|
43
44
|
],
],
|
543b9b1c
Yarik
Composer ready
|
45
46
47
|
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
|
6b69a279
Alexey Boroda
-GA js ready
|
48
49
|
'logout' => [ 'post' ],
'analytics' => [ 'post' ],
|
543b9b1c
Yarik
Composer ready
|
50
|
],
|
1755c393
Yarik
Basic template in...
|
51
|
],
|
543b9b1c
Yarik
Composer ready
|
52
53
|
];
}
|
3cae1b75
Alexey Boroda
-Analytics almost...
|
54
|
|
543b9b1c
Yarik
Composer ready
|
55
56
57
58
59
60
61
62
63
64
65
|
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
|
3cae1b75
Alexey Boroda
-Analytics almost...
|
66
|
|
543b9b1c
Yarik
Composer ready
|
67
68
69
70
71
72
73
|
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
|
6b69a279
Alexey Boroda
-GA js ready
|
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
|
// $settings = Settings::getInstance();
//
// if (empty($settings->analytics_key)) {
return $this->render('index');
// } else {
// $analytics = new Analytics(
// [
// 'viewId' => $settings->analytics_key,
// ]
// );
// $data = $analytics->generateData();
//
// $browsers = $data[ 'table' ][ 0 ];
// arsort($browsers);
//
// $cityes = $data[ 'table' ][ 1 ];
// arsort($cityes);
//
// $countries = $data[ 'table' ][ 2 ];
// arsort($countries);
//
// return $this->render(
// 'analytics',
// [
// 'data' => $data,
// 'browsers' => $browsers,
// 'cityes' => $cityes,
// 'countries' => $countries,
// ]
// );
// }
|
3cae1b75
Alexey Boroda
-Analytics almost...
|
105
106
|
}
|
543b9b1c
Yarik
Composer ready
|
107
108
109
110
111
112
113
114
115
116
|
/**
* Login action.
*
* @return string
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
|
5e021d7a
Alexey Boroda
-Tabs for analyti...
|
117
|
|
543b9b1c
Yarik
Composer ready
|
118
119
120
121
122
123
124
125
126
127
128
129
|
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->renderPartial(
'login',
[
'model' => $model,
]
);
}
}
|
3cae1b75
Alexey Boroda
-Analytics almost...
|
130
|
|
543b9b1c
Yarik
Composer ready
|
131
132
133
134
135
136
137
138
|
/**
* Logout action.
*
* @return string
*/
public function actionLogout()
{
Yii::$app->user->logout();
|
5e021d7a
Alexey Boroda
-Tabs for analyti...
|
139
|
|
1755c393
Yarik
Basic template in...
|
140
141
|
return $this->goHome();
}
|
1755c393
Yarik
Basic template in...
|
142
|
}
|