1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\backend\controllers; |
4
|
|
|
|
5
|
|
|
use app\backend\actions\FlushCacheAction; |
6
|
|
|
use app\backend\models\Notification; |
7
|
|
|
use app\components\Helper; |
8
|
|
|
use app\modules\image\actions\UpdateNameAction; |
9
|
|
|
use vova07\imperavi\actions\GetAction; |
10
|
|
|
use Yii; |
11
|
|
|
use yii\filters\AccessControl; |
12
|
|
|
use yii\web\Controller; |
13
|
|
|
use yii\web\NotFoundHttpException; |
14
|
|
|
use yii\web\Response; |
15
|
|
|
use yii\web\ServerErrorHttpException; |
16
|
|
|
|
17
|
|
|
class DashboardController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function behaviors() |
20
|
|
|
{ |
21
|
|
|
return [ |
22
|
|
|
'access' => [ |
23
|
|
|
'class' => AccessControl::className(), |
|
|
|
|
24
|
|
|
'rules' => [ |
25
|
|
|
[ |
26
|
|
|
'allow' => true, |
27
|
|
|
'actions' => ['flush-cache'], |
28
|
|
|
'roles' => ['cache manage'], |
29
|
|
|
], |
30
|
|
|
[ |
31
|
|
|
'allow' => false, |
32
|
|
|
'actions' => ['flush-cache'], |
33
|
|
|
], |
34
|
|
|
[ |
35
|
|
|
'allow' => true, |
36
|
|
|
'roles' => ['administrate'], |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function actions() |
44
|
|
|
{ |
45
|
|
|
$uploadDir = Yii::$app->getModule('backend')->wysiwygUploadDir; |
46
|
|
|
return [ |
47
|
|
|
'flush-cache' => [ |
48
|
|
|
'class' => FlushCacheAction::className(), |
|
|
|
|
49
|
|
|
], |
50
|
|
|
'imperavi-image-upload' => [ |
51
|
|
|
'class' => 'vova07\imperavi\actions\UploadAction', |
52
|
|
|
'url' => $uploadDir, |
53
|
|
|
'path' => '@webroot' . $uploadDir, |
54
|
|
|
], |
55
|
|
|
'imperavi-images-get' => [ |
56
|
|
|
'class' => 'vova07\imperavi\actions\GetAction', |
57
|
|
|
'url' => $uploadDir, |
58
|
|
|
'path' => '@webroot' . $uploadDir, |
59
|
|
|
'type' => GetAction::TYPE_IMAGES, |
60
|
|
|
], |
61
|
|
|
'rename-image' => [ |
62
|
|
|
'class' => UpdateNameAction::className(), |
|
|
|
|
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function actionIndex() |
68
|
|
|
{ |
69
|
|
|
return $this->render('index'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function actionNotifications($id = null) |
73
|
|
|
{ |
74
|
|
|
$pageSize = 10; |
75
|
|
|
$query = Notification::find()->where( |
76
|
|
|
[ |
77
|
|
|
'user_id' => \Yii::$app->user->id, |
78
|
|
|
] |
79
|
|
|
)->orderBy('`id` DESC'); |
80
|
|
|
$showMoreLink = true; |
81
|
|
|
if (is_null($id)) { |
82
|
|
|
$query->andWhere(['viewed' => 0]); |
83
|
|
|
} else { |
84
|
|
|
$query->andWhere(['viewed' => 1]); |
85
|
|
|
if ($id != -1) { |
86
|
|
|
$query->andWhere(['<', 'id', $id]); |
87
|
|
|
} |
88
|
|
|
$query->limit($pageSize); |
89
|
|
|
} |
90
|
|
|
$notifications = $query->all(); |
91
|
|
|
$count = count($notifications); |
92
|
|
|
if (!is_null($id)) { |
93
|
|
|
if ($count < $pageSize) { |
94
|
|
|
$showMoreLink = false; |
95
|
|
|
} |
96
|
|
|
if ($count > 0) { |
97
|
|
|
$id = $notifications[$count - 1]->id; |
98
|
|
|
} |
99
|
|
|
} else { |
100
|
|
|
$id = -1; |
101
|
|
|
} |
102
|
|
|
return $this->renderPartial( |
103
|
|
|
'notifications', |
104
|
|
|
[ |
105
|
|
|
'id' => $id, |
106
|
|
|
'notifications' => $notifications, |
107
|
|
|
'showMoreLink' => $showMoreLink, |
108
|
|
|
] |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function actionMarkNotification($id) |
113
|
|
|
{ |
114
|
|
|
$notification = Notification::findOne($id); |
115
|
|
|
if (is_null($notification) || $notification->user_id != \Yii::$app->user->id) { |
116
|
|
|
throw new NotFoundHttpException; |
117
|
|
|
} |
118
|
|
|
$notification->viewed = 1; |
119
|
|
|
if (!$notification->save(true, ['viewed'])) { |
120
|
|
|
throw new ServerErrorHttpException; |
121
|
|
|
} |
122
|
|
|
return 'Notification has been marked as viewed'; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function actionMakeSlug($word) |
126
|
|
|
{ |
127
|
|
|
\Yii::$app->response->format = Response::FORMAT_JSON; |
128
|
|
|
return Helper::createSlug($word); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.