b7e90569
Yarik
Namespaces
|
1
2
3
4
|
<?php
namespace artweb\artbox\ecommerce\controllers;
|
20cfd476
Alexey Boroda
-Sizes in process
|
5
|
use artweb\artbox\ecommerce\models\BrandSize;
|
b7e90569
Yarik
Namespaces
|
6
7
8
|
use Yii;
use artweb\artbox\ecommerce\models\Brand;
use artweb\artbox\ecommerce\models\BrandSearch;
|
20cfd476
Alexey Boroda
-Sizes in process
|
9
|
use yii\data\ActiveDataProvider;
|
b7e90569
Yarik
Namespaces
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
/**
* BrandController implements the CRUD actions for Brand model.
*/
class BrandController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
|
8e356b8c
Alexey Boroda
-Sizes half way done
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// 'access' => [
// 'class' => AccessControl::className(),
// 'rules' => [
// [
// 'actions' => [
// 'login',
// 'error',
// ],
// 'allow' => true,
// ],
// [
// 'actions' => [
// 'logout',
// 'index',
// 'create',
// 'update',
// 'view',
// 'delete',
// 'delete-image',
// 'size',
// ],
// 'allow' => true,
// 'roles' => [ '@' ],
// ],
// ],
// ],
|
b7e90569
Yarik
Namespaces
|
53
54
55
|
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
|
2ffeed3d
Yarik
Image delete func...
|
56
57
|
'logout' => [ 'post' ],
'delete-image' => [ 'post' ],
|
b7e90569
Yarik
Namespaces
|
58
59
60
61
62
63
64
|
],
],
];
}
/**
* Lists all Brand models.
|
2ffeed3d
Yarik
Image delete func...
|
65
|
*
|
b7e90569
Yarik
Namespaces
|
66
67
68
69
70
71
72
|
* @return mixed
*/
public function actionIndex()
{
$searchModel = new BrandSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
2ffeed3d
Yarik
Image delete func...
|
73
74
75
76
77
78
79
|
return $this->render(
'index',
[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]
);
|
b7e90569
Yarik
Namespaces
|
80
81
82
83
84
85
86
87
88
89
90
|
}
/**
* Displays a single Brand model.
*
* @param integer $id
*
* @return mixed
*/
public function actionView($id)
{
|
2ffeed3d
Yarik
Image delete func...
|
91
92
93
94
95
96
|
return $this->render(
'view',
[
'model' => $this->findModel($id),
]
);
|
b7e90569
Yarik
Namespaces
|
97
98
99
100
101
|
}
/**
* Creates a new Brand model.
* If creation is successful, the browser will be redirected to the 'view' page.
|
2ffeed3d
Yarik
Image delete func...
|
102
|
*
|
b7e90569
Yarik
Namespaces
|
103
104
105
106
107
108
|
* @return mixed
*/
public function actionCreate()
{
$model = new Brand();
$model->generateLangs();
|
2ffeed3d
Yarik
Image delete func...
|
109
|
if ($model->load(Yii::$app->request->post())) {
|
b7e90569
Yarik
Namespaces
|
110
|
$model->loadLangs(\Yii::$app->request);
|
2ffeed3d
Yarik
Image delete func...
|
111
112
113
114
115
116
117
|
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));
|
b7e90569
Yarik
Namespaces
|
118
119
|
}
}
|
2ffeed3d
Yarik
Image delete func...
|
120
121
122
123
124
125
126
|
return $this->render(
'create',
[
'model' => $model,
'modelLangs' => $model->modelLangs,
]
);
|
b7e90569
Yarik
Namespaces
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
}
/**
* Updates an existing Brand 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);
$model->generateLangs();
|
2ffeed3d
Yarik
Image delete func...
|
142
|
if ($model->load(Yii::$app->request->post())) {
|
b7e90569
Yarik
Namespaces
|
143
|
$model->loadLangs(\Yii::$app->request);
|
2ffeed3d
Yarik
Image delete func...
|
144
145
146
147
148
149
150
|
if ($model->save() && $model->transactionStatus) {
return $this->redirect(
[
'view',
'id' => $model->id,
]
);
|
b7e90569
Yarik
Namespaces
|
151
152
|
}
}
|
2ffeed3d
Yarik
Image delete func...
|
153
154
155
156
157
158
159
|
return $this->render(
'update',
[
'model' => $model,
'modelLangs' => $model->modelLangs,
]
);
|
b7e90569
Yarik
Namespaces
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
}
/**
* Deletes an existing Brand 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' ]);
}
|
20cfd476
Alexey Boroda
-Sizes in process
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
public function actionSize($id)
{
$model = $this->findModel($id);
$dataProvider = new ActiveDataProvider(
[
'query' => BrandSize::find()
->where(
[
'brand_id' => $id,
]
),
]
);
return $this->render(
'size',
[
'model' => $model,
'dataProvider' => $dataProvider,
]
);
}
|
2ffeed3d
Yarik
Image delete func...
|
202
203
204
|
public function actionDeleteImage($id)
{
$model = $this->findModel($id);
|
20cfd476
Alexey Boroda
-Sizes in process
|
205
206
|
$model->image = NULL;
$model->updateAttributes([ 'image' ]);
|
2ffeed3d
Yarik
Image delete func...
|
207
208
209
|
return true;
}
|
b7e90569
Yarik
Namespaces
|
210
211
212
213
214
215
216
217
218
219
220
|
/**
* Finds the Brand model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
*
* @return Brand the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
|
2ffeed3d
Yarik
Image delete func...
|
221
222
223
|
if (( $model = Brand::find()
->with('lang')
->where([ 'id' => $id ])
|
20cfd476
Alexey Boroda
-Sizes in process
|
224
|
->one() ) !== NULL
|
2ffeed3d
Yarik
Image delete func...
|
225
|
) {
|
b7e90569
Yarik
Namespaces
|
226
227
228
229
230
231
|
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
|