d8c1a2e0
Yarik
Big commit artbox
|
1
|
<?php
|
d55d2fe0
Yarik
Multilanguage
|
2
3
4
5
6
7
8
9
10
11
12
|
namespace backend\controllers;
use developeruz\db_rbac\behaviors\AccessBehavior;
use common\components\artboxtree\ArtboxTreeHelper;
use Yii;
use common\modules\product\models\Category;
use common\modules\product\models\CategorySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
|
d55d2fe0
Yarik
Multilanguage
|
13
|
|
d8c1a2e0
Yarik
Big commit artbox
|
14
|
/**
|
d55d2fe0
Yarik
Multilanguage
|
15
|
* CategoryController implements the CRUD actions for Category model.
|
d8c1a2e0
Yarik
Big commit artbox
|
16
|
*/
|
d55d2fe0
Yarik
Multilanguage
|
17
|
class CategoryController extends Controller
|
d8c1a2e0
Yarik
Big commit artbox
|
18
|
{
|
d55d2fe0
Yarik
Multilanguage
|
19
20
21
22
23
24
25
26
27
28
29
|
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessBehavior::className(),
'rules' => [
'site' => [
|
d8c1a2e0
Yarik
Big commit artbox
|
30
|
[
|
d55d2fe0
Yarik
Multilanguage
|
31
32
33
34
35
36
37
38
|
'actions' => [
'login',
'error',
],
'allow' => true,
],
],
],
|
d8c1a2e0
Yarik
Big commit artbox
|
39
|
],
|
d55d2fe0
Yarik
Multilanguage
|
40
41
42
43
44
45
46
47
48
49
50
|
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => [ 'post' ],
],
],
];
}
/**
* Lists all Category models.
|
c70f24ea
Yarik
For Leha commit.
|
51
|
*
|
d55d2fe0
Yarik
Multilanguage
|
52
53
54
55
56
57
|
* @return mixed
*/
public function actionIndex()
{
$searchModel = new CategorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
c70f24ea
Yarik
For Leha commit.
|
58
59
60
61
62
63
64
|
return $this->render(
'index',
[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]
);
|
d55d2fe0
Yarik
Multilanguage
|
65
66
67
68
69
70
71
72
73
74
75
|
}
/**
* Displays a single Category model.
*
* @param integer $id
*
* @return mixed
*/
public function actionView($id)
{
|
4a7f93fb
Yarik
Another one admin...
|
76
77
78
79
|
$model = $this->findModel($id);
$tree = $model->getParents()
->with('lang')
->all();
|
c70f24ea
Yarik
For Leha commit.
|
80
81
82
83
84
85
86
|
return $this->render(
'view',
[
'model' => $model,
'tree' => $tree,
]
);
|
d55d2fe0
Yarik
Multilanguage
|
87
88
89
90
91
|
}
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
|
c70f24ea
Yarik
For Leha commit.
|
92
|
*
|
d55d2fe0
Yarik
Multilanguage
|
93
94
95
96
97
|
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
|
72a992f5
Yarik
Import browser v1.0
|
98
|
$model->generateLangs();
|
c70f24ea
Yarik
For Leha commit.
|
99
|
if ($model->load(Yii::$app->request->post())) {
|
72a992f5
Yarik
Import browser v1.0
|
100
|
$model->loadLangs(\Yii::$app->request);
|
c70f24ea
Yarik
For Leha commit.
|
101
102
103
104
105
106
107
|
if ($model->save() && $model->transactionStatus) {
return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(
[
'view',
'id' => $model->id,
]
) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams));
|
d55d2fe0
Yarik
Multilanguage
|
108
|
}
|
d8c1a2e0
Yarik
Big commit artbox
|
109
|
}
|
c70f24ea
Yarik
For Leha commit.
|
110
|
if (!empty( Yii::$app->request->queryParams[ 'parent' ] )) {
|
d55d2fe0
Yarik
Multilanguage
|
111
|
$model->parent_id = Yii::$app->request->queryParams[ 'parent' ];
|
d8c1a2e0
Yarik
Big commit artbox
|
112
|
}
|
c70f24ea
Yarik
For Leha commit.
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
return $this->render(
'create',
[
'model' => $model,
'modelLangs' => $model->modelLangs,
'categories' => ArtboxTreeHelper::treeMap(
Category::find()
->getTree(),
'id',
'id',
'.'
),
]
);
|
d8c1a2e0
Yarik
Big commit artbox
|
127
|
}
|
d55d2fe0
Yarik
Multilanguage
|
128
129
130
131
132
133
134
135
136
137
138
139
|
/**
* Updates an existing Category model.
* If update is successful, the browser will be redirected to the 'view' page.
*
* @param integer $id
*
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
|
72a992f5
Yarik
Import browser v1.0
|
140
|
$model->generateLangs();
|
c70f24ea
Yarik
For Leha commit.
|
141
|
if ($model->load(Yii::$app->request->post())) {
|
72a992f5
Yarik
Import browser v1.0
|
142
|
$model->loadLangs(\Yii::$app->request);
|
c70f24ea
Yarik
For Leha commit.
|
143
144
145
146
147
148
149
|
if ($model->save() && $model->transactionStatus) {
return $this->redirect(
[
'view',
'id' => $model->id,
]
);
|
d55d2fe0
Yarik
Multilanguage
|
150
|
}
|
d8c1a2e0
Yarik
Big commit artbox
|
151
|
}
|
c70f24ea
Yarik
For Leha commit.
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
return $this->render(
'update',
[
'model' => $model,
'modelLangs' => $model->modelLangs,
'categories' => ArtboxTreeHelper::treeMap(
Category::find()
->getTree(),
'id',
'id',
'.'
),
]
);
|
d8c1a2e0
Yarik
Big commit artbox
|
166
|
}
|
d55d2fe0
Yarik
Multilanguage
|
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/**
* Deletes an existing Category model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
*
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)
->delete();
return $this->redirect([ 'index' ]);
}
/**
* Finds the Category model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
*
* @return Category the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
|
c70f24ea
Yarik
For Leha commit.
|
195
196
197
198
|
if (( $model = Category::find()
->where([ 'id' => $id ])
->with('lang')
->one() ) !== null
|
4a7f93fb
Yarik
Another one admin...
|
199
|
) {
|
d55d2fe0
Yarik
Multilanguage
|
200
201
202
203
|
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
|
d8c1a2e0
Yarik
Big commit artbox
|
204
205
|
}
}
|