1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\backend\controllers; |
4
|
|
|
|
5
|
|
|
use app\backend\actions\UpdateEditable; |
6
|
|
|
use app\modules\image\widgets\RemoveAction; |
7
|
|
|
use app\modules\image\widgets\SaveInfoAction; |
8
|
|
|
use app\modules\image\widgets\UploadAction; |
9
|
|
|
use app\modules\image\widgets\views\AddImageAction; |
10
|
|
|
use app\widgets\navigation\models\Navigation; |
11
|
|
|
use devgroup\JsTreeWidget\AdjacencyFullTreeDataAction; |
12
|
|
|
use devgroup\JsTreeWidget\TreeNodeMoveAction; |
13
|
|
|
use devgroup\JsTreeWidget\TreeNodesReorderAction; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\filters\AccessControl; |
16
|
|
|
use yii\helpers\Url; |
17
|
|
|
use yii\web\Controller; |
18
|
|
|
|
19
|
|
|
class NavigationController extends Controller |
20
|
|
|
{ |
21
|
|
View Code Duplication |
public function behaviors() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
'access' => [ |
25
|
|
|
'class' => AccessControl::className(), |
|
|
|
|
26
|
|
|
'rules' => [ |
27
|
|
|
[ |
28
|
|
|
'allow' => true, |
29
|
|
|
'roles' => ['navigation manage'], |
30
|
|
|
], |
31
|
|
|
], |
32
|
|
|
], |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function actions() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
'getTree' => [ |
40
|
|
|
'class' => AdjacencyFullTreeDataAction::className(), |
|
|
|
|
41
|
|
|
'class_name' => Navigation::className(), |
|
|
|
|
42
|
|
|
'model_label_attribute' => 'name', |
43
|
|
|
], |
44
|
|
|
'move' => [ |
45
|
|
|
'class' => TreeNodeMoveAction::className(), |
|
|
|
|
46
|
|
|
'className' => Navigation::className(), |
|
|
|
|
47
|
|
|
], |
48
|
|
|
'reorder' => [ |
49
|
|
|
'class' => TreeNodesReorderAction::className(), |
|
|
|
|
50
|
|
|
'className' => Navigation::className(), |
|
|
|
|
51
|
|
|
], |
52
|
|
|
'addImage' => [ |
53
|
|
|
'class' => AddImageAction::className(), |
|
|
|
|
54
|
|
|
], |
55
|
|
|
'upload' => [ |
56
|
|
|
'class' => UploadAction::className(), |
|
|
|
|
57
|
|
|
], |
58
|
|
|
'remove' => [ |
59
|
|
|
'class' => RemoveAction::className(), |
|
|
|
|
60
|
|
|
], |
61
|
|
|
'save-info' => [ |
62
|
|
|
'class' => SaveInfoAction::className(), |
|
|
|
|
63
|
|
|
], |
64
|
|
|
'update-editable' => [ |
65
|
|
|
'class' => UpdateEditable::className(), |
|
|
|
|
66
|
|
|
'modelName' => Navigation::className(), |
|
|
|
|
67
|
|
|
'allowedAttributes' => [ |
68
|
|
View Code Duplication |
'active' => function (Navigation $model) { |
69
|
|
|
if ($model === null || $model->active === null) { |
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
if ($model->active === 1) { |
73
|
|
|
$label_class = 'label-success'; |
74
|
|
|
$value = 'Active'; |
75
|
|
|
} else { |
76
|
|
|
$value = 'Inactive'; |
77
|
|
|
$label_class = 'label-default'; |
78
|
|
|
} |
79
|
|
|
return \yii\helpers\Html::tag( |
80
|
|
|
'span', |
81
|
|
|
Yii::t('app', $value), |
82
|
|
|
['class' => "label $label_class"] |
83
|
|
|
); |
84
|
|
|
}, |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function actionIndex($parent_id = 0) |
91
|
|
|
{ |
92
|
|
|
$searchModel = new Navigation(['scenario' => 'search']); |
93
|
|
|
$searchModel->parent_id = $parent_id; |
94
|
|
|
$dataProvider = $searchModel->search($_GET); |
95
|
|
|
|
96
|
|
|
$model = null; |
97
|
|
|
if ($parent_id > 0) { |
98
|
|
|
$model = Navigation::findOne($parent_id); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $this->render( |
102
|
|
|
'index', |
103
|
|
|
[ |
104
|
|
|
'dataProvider' => $dataProvider, |
105
|
|
|
'searchModel' => $searchModel, |
106
|
|
|
'model' => $model, |
107
|
|
|
] |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function actionEdit($parent_id, $id = null) |
112
|
|
|
{ |
113
|
|
|
if ($id === null) { |
114
|
|
|
$model = new Navigation(['parent_id' => $parent_id]); |
115
|
|
|
} else { |
116
|
|
|
$model = Navigation::findOne($id); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$post = Yii::$app->request->post(); |
120
|
|
|
if ($model->load($post) && $model->validate()) { |
121
|
|
View Code Duplication |
if ($model->save()) { |
122
|
|
|
Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved')); |
123
|
|
|
$returnUrl = Yii::$app->request->get('returnUrl', ['/backend/navigation/index', 'id' => $model->id]); |
124
|
|
|
switch (Yii::$app->request->post('action', 'save')) { |
125
|
|
|
case 'next': |
126
|
|
|
return $this->redirect( |
127
|
|
|
[ |
128
|
|
|
'/backend/navigation/edit', |
129
|
|
|
'parent_id' => $model->parent_id, |
130
|
|
|
'returnUrl' => $returnUrl, |
131
|
|
|
] |
132
|
|
|
); |
133
|
|
|
case 'back': |
134
|
|
|
return $this->redirect($returnUrl); |
135
|
|
|
default: |
136
|
|
|
return $this->redirect( |
137
|
|
|
Url::toRoute( |
138
|
|
|
[ |
139
|
|
|
'/backend/navigation/edit', |
140
|
|
|
'id' => $model->id, |
141
|
|
|
'parent_id' => $model->parent_id, |
142
|
|
|
'returnUrl' => $returnUrl, |
143
|
|
|
] |
144
|
|
|
) |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
} else { |
148
|
|
|
\Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data')); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $this->render( |
153
|
|
|
'navigation-form', |
154
|
|
|
[ |
155
|
|
|
'model' => $model, |
156
|
|
|
] |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
View Code Duplication |
public function actionDelete($id) |
161
|
|
|
{ |
162
|
|
|
$model = Navigation::findOne($id); |
163
|
|
|
$model->delete(); |
164
|
|
|
Yii::$app->session->setFlash('info', Yii::t('app', 'Object removed')); |
165
|
|
|
return $this->redirect( |
166
|
|
|
Url::to( |
167
|
|
|
[ |
168
|
|
|
'/backend/navigation/index', |
169
|
|
|
'parent_id' => $model->parent_id, |
170
|
|
|
] |
171
|
|
|
) |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function actionRemoveAll($parent_id) |
176
|
|
|
{ |
177
|
|
|
$items = Yii::$app->request->post('items', []); |
178
|
|
|
if (!empty($items)) { |
179
|
|
|
$items = Navigation::find()->where(['in', 'id', $items])->all(); |
180
|
|
|
foreach ($items as $item) { |
181
|
|
|
$item->delete(); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $this->redirect(['index', 'parent_id' => $parent_id]); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
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.