1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers\admin; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\base\InvalidConfigException; |
7
|
|
|
use app\traits\AdminBeforeActionTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class UserController |
11
|
|
|
* UserController implements the CRUD actions for identityClass. |
12
|
|
|
* |
13
|
|
|
* @package app\controllers\admin |
14
|
|
|
*/ |
15
|
|
|
class UserController extends BaseUserController |
16
|
|
|
{ |
17
|
|
|
use AdminBeforeActionTrait; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return mixed|string |
21
|
|
|
*/ |
22
|
|
|
public function actionIndex() |
23
|
|
|
{ |
24
|
|
|
if (!$this->checkAccessToIndex()) { |
25
|
|
|
return $this->accessError(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$request = Yii::$app->request; |
|
|
|
|
29
|
|
|
|
30
|
|
|
if ($request->get('id') != null && $request->get('order') != null) { |
31
|
|
|
|
32
|
|
|
if (!$this->checkAccessToAdministrate()) { |
33
|
|
|
return $this->accessError(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->actionSetOrder($request->get('id'), $request->get('order')); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return parent::actionIndex(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param int $id |
44
|
|
|
* @param int $order |
45
|
|
|
* |
46
|
|
|
* @return \yii\web\Response |
47
|
|
|
*/ |
48
|
|
|
public function actionSetOrder(int $id, int $order) |
49
|
|
|
{ |
50
|
|
|
/* @var \app\models\User $model */ |
51
|
|
|
$model = $this->findModel($id); |
52
|
|
|
$model->moveOrder($order); |
53
|
|
|
|
54
|
|
|
return $this->redirect([ |
55
|
|
|
$this->urlPrefix.'index' |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param int|string $id |
61
|
|
|
* |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
public function actionView($id) |
65
|
|
|
{ |
66
|
|
|
if (!$this->checkAccessToView()) { |
67
|
|
|
return $this->accessError(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return parent::actionView($id); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return mixed|string|\yii\web\Response |
75
|
|
|
*/ |
76
|
|
|
public function actionCreate() |
77
|
|
|
{ |
78
|
|
|
if (!$this->checkAccessToCreate()) { |
79
|
|
|
return $this->accessError(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return parent::actionCreate(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param int|string $id |
87
|
|
|
* |
88
|
|
|
* @return string|\yii\web\Response |
89
|
|
|
*/ |
90
|
|
|
public function actionUpdate($id) |
91
|
|
|
{ |
92
|
|
|
if ($id != Yii::$app->getUser()->id && !$this->checkAccessToUpdate()) { |
93
|
|
|
return $this->accessError(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return parent::actionUpdate($id); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param int|string $id |
101
|
|
|
* |
102
|
|
|
* @return mixed|\yii\web\Response |
103
|
|
|
*/ |
104
|
|
|
public function actionDelete($id) |
105
|
|
|
{ |
106
|
|
|
if (!$this->checkAccessToDelete()) { |
107
|
|
|
return $this->accessError(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return parent::actionDelete($id); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns addition fields. |
115
|
|
|
* |
116
|
|
|
* @throws InvalidConfigException |
117
|
|
|
* |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
protected function getAdditionFields(): array |
121
|
|
|
{ |
122
|
|
|
$additionFields = parent::getAdditionFields(); |
123
|
|
|
|
124
|
|
|
if ($this->action->id == 'create' || $this->action->id == 'update') { |
125
|
|
|
return array_merge($additionFields, [ |
126
|
|
|
'changeRoles' => $this->checkAccessToSetRoles() |
127
|
|
|
]); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
if ($this->action->id == 'index') { |
131
|
|
|
return array_merge($additionFields, [ |
132
|
|
|
'administrateAccess' => $this->checkAccessToAdministrate() |
133
|
|
|
]); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $additionFields; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|