Commit 6d9a4125597e423589c27fc724b5abf9812b6d53
Merge remote-tracking branch 'origin/master'
Showing
50 changed files
with
3814 additions
and
3 deletions
Show diff stats
backend/views/layouts/main-sidebar.php
@@ -121,6 +121,32 @@ use yii\widgets\Menu; | @@ -121,6 +121,32 @@ use yii\widgets\Menu; | ||
121 | 'options' => ['class'=>\Yii::$app->user->can('article') ? '' :'hide'], | 121 | 'options' => ['class'=>\Yii::$app->user->can('article') ? '' :'hide'], |
122 | ], | 122 | ], |
123 | [ | 123 | [ |
124 | + 'label' => 'Блог', | ||
125 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-edit"></i> <span>{label}</span></a>', | ||
126 | + 'options' => ['class'=>\Yii::$app->user->can('blog') ? '' :'hide'], | ||
127 | + 'active' => preg_match('/^blog.*$/', $this->context->id) ? true : false, | ||
128 | + 'items' => [ | ||
129 | + [ | ||
130 | + 'label' => 'Статьи', | ||
131 | + 'url' => ['/blog/blog-article'], | ||
132 | + 'options' => ['class'=>\Yii::$app->user->can('blog') ? '' :'hide'], | ||
133 | + 'active' => preg_match('/.*blog-article.*$/', $this->context->id), | ||
134 | + ], | ||
135 | + [ | ||
136 | + 'label' => 'Рубрики', | ||
137 | + 'url' => ['/blog/blog-category'], | ||
138 | + 'options' => ['class'=>\Yii::$app->user->can('blog') ? '' :'hide'], | ||
139 | + 'active' => preg_match('/.*blog-category.*$/', $this->context->id), | ||
140 | + ], | ||
141 | + [ | ||
142 | + 'label' => 'Тэги', | ||
143 | + 'url' => ['/blog/blog-tag'], | ||
144 | + 'options' => ['class'=>\Yii::$app->user->can('blog') ? '' :'hide'], | ||
145 | + 'active' => preg_match('/.*blog-tag.*$/', $this->context->id), | ||
146 | + ], | ||
147 | + ] | ||
148 | + ], | ||
149 | + [ | ||
124 | 'label' => 'Акции', | 150 | 'label' => 'Акции', |
125 | 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-piggy-bank"></i> <span>{label}</span></a>', | 151 | 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-piggy-bank"></i> <span>{label}</span></a>', |
126 | 'url' => ['/event/index'], | 152 | 'url' => ['/event/index'], |
common/config/main.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | return [ | 2 | return [ |
4 | 'language' => 'ru', | 3 | 'language' => 'ru', |
5 | 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', | 4 | 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', |
@@ -41,7 +40,13 @@ | @@ -41,7 +40,13 @@ | ||
41 | 'resize' => [ | 40 | 'resize' => [ |
42 | 'width' => 360, | 41 | 'width' => 360, |
43 | 'height' => 360, | 42 | 'height' => 360, |
44 | - 'master' => null, | 43 | + 'master' => NULL, |
44 | + ], | ||
45 | + ], | ||
46 | + 'list' => [ | ||
47 | + 'resize' => [ | ||
48 | + 'width' => 360, | ||
49 | + 'height' => 360, | ||
45 | ], | 50 | ], |
46 | ], | 51 | ], |
47 | ], | 52 | ], |
@@ -54,5 +59,8 @@ | @@ -54,5 +59,8 @@ | ||
54 | 'artbox-comment' => [ | 59 | 'artbox-comment' => [ |
55 | 'class' => 'common\modules\comment\Module', | 60 | 'class' => 'common\modules\comment\Module', |
56 | ], | 61 | ], |
62 | + 'blog' => [ | ||
63 | + 'class' => 'common\modules\blog\Module', | ||
64 | + ], | ||
57 | ], | 65 | ], |
58 | ]; | 66 | ]; |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog; | ||
4 | + | ||
5 | + /** | ||
6 | + * blog module definition class | ||
7 | + */ | ||
8 | + class Module extends \yii\base\Module | ||
9 | + { | ||
10 | + /** | ||
11 | + * @inheritdoc | ||
12 | + */ | ||
13 | + public $controllerNamespace = 'common\modules\blog\controllers'; | ||
14 | + | ||
15 | + /** | ||
16 | + * @inheritdoc | ||
17 | + */ | ||
18 | + public function init() | ||
19 | + { | ||
20 | + parent::init(); | ||
21 | + | ||
22 | + // custom initialization code goes here | ||
23 | + } | ||
24 | + } |
common/modules/blog/controllers/BlogArticleController.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\controllers; | ||
4 | + | ||
5 | + use common\modules\blog\models\BlogCategory; | ||
6 | + use common\modules\blog\models\BlogTag; | ||
7 | + use common\modules\product\models\Product; | ||
8 | + use Yii; | ||
9 | + use common\modules\blog\models\BlogArticle; | ||
10 | + use common\modules\blog\models\BlogArticleSearch; | ||
11 | + use yii\helpers\ArrayHelper; | ||
12 | + use yii\web\Controller; | ||
13 | + use yii\web\NotFoundHttpException; | ||
14 | + use yii\filters\VerbFilter; | ||
15 | + use yii\web\Response; | ||
16 | + | ||
17 | + /** | ||
18 | + * BlogArticleController implements the CRUD actions for BlogArticle model. | ||
19 | + */ | ||
20 | + class BlogArticleController extends Controller | ||
21 | + { | ||
22 | + /** | ||
23 | + * @inheritdoc | ||
24 | + */ | ||
25 | + public function behaviors() | ||
26 | + { | ||
27 | + return [ | ||
28 | + 'verbs' => [ | ||
29 | + 'class' => VerbFilter::className(), | ||
30 | + 'actions' => [ | ||
31 | + 'delete' => [ 'POST' ], | ||
32 | + ], | ||
33 | + ], | ||
34 | + ]; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Lists all BlogArticle models. | ||
39 | + * | ||
40 | + * @return mixed | ||
41 | + */ | ||
42 | + public function actionIndex() | ||
43 | + { | ||
44 | + $searchModel = new BlogArticleSearch(); | ||
45 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
46 | + | ||
47 | + return $this->render( | ||
48 | + 'index', | ||
49 | + [ | ||
50 | + 'searchModel' => $searchModel, | ||
51 | + 'dataProvider' => $dataProvider, | ||
52 | + ] | ||
53 | + ); | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * Displays a single BlogArticle model. | ||
58 | + * | ||
59 | + * @param integer $id | ||
60 | + * | ||
61 | + * @return mixed | ||
62 | + */ | ||
63 | + public function actionView($id) | ||
64 | + { | ||
65 | + return $this->render( | ||
66 | + 'view', | ||
67 | + [ | ||
68 | + 'model' => $this->findModel($id), | ||
69 | + ] | ||
70 | + ); | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Creates a new BlogArticle model. | ||
75 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
76 | + * | ||
77 | + * @return mixed | ||
78 | + */ | ||
79 | + public function actionCreate() | ||
80 | + { | ||
81 | + $model = new BlogArticle(); | ||
82 | + $model->generateLangs(); | ||
83 | + | ||
84 | + $categories = ArrayHelper::map( | ||
85 | + BlogCategory::find() | ||
86 | + ->joinWith('lang') | ||
87 | + ->all(), | ||
88 | + 'id', | ||
89 | + 'lang.title' | ||
90 | + ); | ||
91 | + | ||
92 | + $tags = ArrayHelper::map( | ||
93 | + BlogTag::find() | ||
94 | + ->joinWith('lang') | ||
95 | + ->all(), | ||
96 | + 'id', | ||
97 | + 'lang.label' | ||
98 | + ); | ||
99 | + | ||
100 | + if ($model->load(Yii::$app->request->post())) { | ||
101 | + $model->loadLangs(\Yii::$app->request); | ||
102 | + if ($model->save() && $model->transactionStatus) { | ||
103 | + | ||
104 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] )) { | ||
105 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] as $item) { | ||
106 | + if ($category = BlogCategory::findOne($item)) { | ||
107 | + $model->link('blogCategories', $category); | ||
108 | + } | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) { | ||
113 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) { | ||
114 | + if ($category = BlogTag::findOne($item)) { | ||
115 | + $model->link('blogTags', $category); | ||
116 | + } | ||
117 | + } | ||
118 | + } | ||
119 | + | ||
120 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) { | ||
121 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) { | ||
122 | + if ($product = Product::findOne($item)) { | ||
123 | + $model->link('products', $product); | ||
124 | + } | ||
125 | + } | ||
126 | + } | ||
127 | + | ||
128 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) { | ||
129 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) { | ||
130 | + if ($article = Product::findOne($item)) { | ||
131 | + $model->link('blogArticles', $article); | ||
132 | + } | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + return $this->redirect( | ||
137 | + [ | ||
138 | + 'view', | ||
139 | + 'id' => $model->id, | ||
140 | + ] | ||
141 | + ); | ||
142 | + } | ||
143 | + } | ||
144 | + return $this->render( | ||
145 | + 'create', | ||
146 | + [ | ||
147 | + 'model' => $model, | ||
148 | + 'modelLangs' => $model->modelLangs, | ||
149 | + 'categories' => $categories, | ||
150 | + 'tags' => $tags, | ||
151 | + 'products' => [], | ||
152 | + 'articles' => [], | ||
153 | + ] | ||
154 | + ); | ||
155 | + | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Updates an existing BlogArticle model. | ||
160 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
161 | + * | ||
162 | + * @param integer $id | ||
163 | + * | ||
164 | + * @return mixed | ||
165 | + */ | ||
166 | + public function actionUpdate($id) | ||
167 | + { | ||
168 | + $model = $this->findModel($id); | ||
169 | + $model->generateLangs(); | ||
170 | + | ||
171 | + $categories = ArrayHelper::map( | ||
172 | + BlogCategory::find() | ||
173 | + ->joinWith('lang') | ||
174 | + ->all(), | ||
175 | + 'id', | ||
176 | + 'lang.title' | ||
177 | + ); | ||
178 | + | ||
179 | + $tags = ArrayHelper::map( | ||
180 | + BlogTag::find() | ||
181 | + ->joinWith('lang') | ||
182 | + ->all(), | ||
183 | + 'id', | ||
184 | + 'lang.label' | ||
185 | + ); | ||
186 | + | ||
187 | + $products = ArrayHelper::map( | ||
188 | + $model->getProducts() | ||
189 | + ->joinWith('lang') | ||
190 | + ->asArray() | ||
191 | + ->all(), | ||
192 | + 'id', | ||
193 | + 'lang.title' | ||
194 | + ); | ||
195 | + | ||
196 | + $articles = ArrayHelper::map( | ||
197 | + $model->getBlogArticles() | ||
198 | + ->joinWith('lang') | ||
199 | + ->asArray() | ||
200 | + ->all(), | ||
201 | + 'id', | ||
202 | + 'lang.title' | ||
203 | + ); | ||
204 | + | ||
205 | + if ($model->load(Yii::$app->request->post())) { | ||
206 | + $model->loadLangs(\Yii::$app->request); | ||
207 | + if ($model->save() && $model->transactionStatus) { | ||
208 | + | ||
209 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] )) { | ||
210 | + $model->unlinkAll('blogCategories', true); | ||
211 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogCategories' ] as $item) { | ||
212 | + if ($category = BlogCategory::findOne($item)) { | ||
213 | + $model->link('blogCategories', $category); | ||
214 | + } | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogTags' ] )) { | ||
219 | + $model->unlinkAll('blogTags', true); | ||
220 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogTags' ] as $item) { | ||
221 | + if ($tag = BlogTag::findOne($item)) { | ||
222 | + $model->link('blogTags', $tag); | ||
223 | + } | ||
224 | + } | ||
225 | + } | ||
226 | + | ||
227 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'products' ] )) { | ||
228 | + $model->unlinkAll('products', true); | ||
229 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'products' ] as $item) { | ||
230 | + if ($product = Product::findOne($item)) { | ||
231 | + $model->link('products', $product); | ||
232 | + } | ||
233 | + } | ||
234 | + } | ||
235 | + | ||
236 | + if (!empty( \Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] )) { | ||
237 | + $model->unlinkAll('blogArticles', true); | ||
238 | + foreach (\Yii::$app->request->post('BlogArticle')[ 'blogArticles' ] as $item) { | ||
239 | + if ($article = BlogArticle::findOne($item)) { | ||
240 | + $model->link('blogArticles', $article); | ||
241 | + } | ||
242 | + } | ||
243 | + } | ||
244 | + | ||
245 | + return $this->redirect( | ||
246 | + [ | ||
247 | + 'view', | ||
248 | + 'id' => $model->id, | ||
249 | + ] | ||
250 | + ); | ||
251 | + } | ||
252 | + } | ||
253 | + return $this->render( | ||
254 | + 'update', | ||
255 | + [ | ||
256 | + 'model' => $model, | ||
257 | + 'modelLangs' => $model->modelLangs, | ||
258 | + 'categories' => $categories, | ||
259 | + 'tags' => $tags, | ||
260 | + 'products' => $products, | ||
261 | + 'articles' => $articles, | ||
262 | + ] | ||
263 | + ); | ||
264 | + | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * Deletes an existing BlogArticle model. | ||
269 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
270 | + * | ||
271 | + * @param integer $id | ||
272 | + * | ||
273 | + * @return mixed | ||
274 | + */ | ||
275 | + public function actionDelete($id) | ||
276 | + { | ||
277 | + $this->findModel($id) | ||
278 | + ->delete(); | ||
279 | + | ||
280 | + return $this->redirect([ 'index' ]); | ||
281 | + } | ||
282 | + | ||
283 | + /** | ||
284 | + * Finds the BlogArticle model based on its primary key value. | ||
285 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
286 | + * | ||
287 | + * @param integer $id | ||
288 | + * | ||
289 | + * @return BlogArticle the loaded model | ||
290 | + * @throws NotFoundHttpException if the model cannot be found | ||
291 | + */ | ||
292 | + protected function findModel($id) | ||
293 | + { | ||
294 | + if (( $model = BlogArticle::findOne($id) ) !== NULL) { | ||
295 | + return $model; | ||
296 | + } else { | ||
297 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
298 | + } | ||
299 | + } | ||
300 | + | ||
301 | + /** | ||
302 | + * @param string $q | ||
303 | + * @param null $id | ||
304 | + * | ||
305 | + * @return array | ||
306 | + */ | ||
307 | + public function actionProductList($q = NULL, $id = NULL) | ||
308 | + { | ||
309 | + \Yii::$app->response->format = Response::FORMAT_JSON; | ||
310 | + $out = [ | ||
311 | + 'results' => [ | ||
312 | + 'id' => '', | ||
313 | + 'text' => '', | ||
314 | + ], | ||
315 | + ]; | ||
316 | + if (!is_null($q)) { | ||
317 | + $out[ 'results' ] = Product::find() | ||
318 | + ->joinWith('lang') | ||
319 | + ->select( | ||
320 | + [ | ||
321 | + 'id', | ||
322 | + 'product_lang.title as text', | ||
323 | + ] | ||
324 | + ) | ||
325 | + ->where( | ||
326 | + [ | ||
327 | + 'like', | ||
328 | + 'product_lang.title', | ||
329 | + $q, | ||
330 | + ] | ||
331 | + ) | ||
332 | + ->limit(20) | ||
333 | + ->asArray() | ||
334 | + ->all(); | ||
335 | + } elseif ($id > 0) { | ||
336 | + $out[ 'results' ] = [ | ||
337 | + 'id' => $id, | ||
338 | + 'text' => Product::find() | ||
339 | + ->joinWith('lang') | ||
340 | + ->where([ 'id' => $id ]) | ||
341 | + ->one()->title, | ||
342 | + ]; | ||
343 | + } | ||
344 | + return $out; | ||
345 | + } | ||
346 | + | ||
347 | + /** | ||
348 | + * @param string $q | ||
349 | + * @param integer $id | ||
350 | + * | ||
351 | + * @return array | ||
352 | + */ | ||
353 | + public function actionArticleList($q = NULL, $id = NULL) | ||
354 | + { | ||
355 | + \Yii::$app->response->format = Response::FORMAT_JSON; | ||
356 | + $out = [ | ||
357 | + 'results' => [ | ||
358 | + 'id' => '', | ||
359 | + 'text' => '', | ||
360 | + ], | ||
361 | + ]; | ||
362 | + if (!is_null($q)) { | ||
363 | + $out[ 'results' ] = BlogArticle::find() | ||
364 | + ->joinWith('lang') | ||
365 | + ->select( | ||
366 | + [ | ||
367 | + 'blog_article.id as id', | ||
368 | + 'blog_article_lang.title as text', | ||
369 | + ] | ||
370 | + ) | ||
371 | + ->where( | ||
372 | + [ | ||
373 | + 'like', | ||
374 | + 'blog_article_lang.title', | ||
375 | + $q, | ||
376 | + ] | ||
377 | + ) | ||
378 | + ->andWhere( | ||
379 | + [ | ||
380 | + '!=', | ||
381 | + 'blog_article.id', | ||
382 | + $id, | ||
383 | + ] | ||
384 | + ) | ||
385 | + ->limit(20) | ||
386 | + ->asArray() | ||
387 | + ->all(); | ||
388 | + } | ||
389 | + return $out; | ||
390 | + } | ||
391 | + } |
common/modules/blog/controllers/BlogCategoryController.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\controllers; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use common\modules\blog\models\BlogCategory; | ||
7 | + use common\modules\blog\models\BlogCategorySearch; | ||
8 | + use yii\helpers\ArrayHelper; | ||
9 | + use yii\web\Controller; | ||
10 | + use yii\web\NotFoundHttpException; | ||
11 | + use yii\filters\VerbFilter; | ||
12 | + | ||
13 | + /** | ||
14 | + * BlogCategoryController implements the CRUD actions for BlogCategory model. | ||
15 | + */ | ||
16 | + class BlogCategoryController extends Controller | ||
17 | + { | ||
18 | + /** | ||
19 | + * @inheritdoc | ||
20 | + */ | ||
21 | + public function behaviors() | ||
22 | + { | ||
23 | + return [ | ||
24 | + 'verbs' => [ | ||
25 | + 'class' => VerbFilter::className(), | ||
26 | + 'actions' => [ | ||
27 | + 'delete' => [ 'POST' ], | ||
28 | + ], | ||
29 | + ], | ||
30 | + ]; | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * Lists all BlogCategory models. | ||
35 | + * | ||
36 | + * @return mixed | ||
37 | + */ | ||
38 | + public function actionIndex() | ||
39 | + { | ||
40 | + $searchModel = new BlogCategorySearch(); | ||
41 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
42 | + | ||
43 | + return $this->render( | ||
44 | + 'index', | ||
45 | + [ | ||
46 | + 'searchModel' => $searchModel, | ||
47 | + 'dataProvider' => $dataProvider, | ||
48 | + ] | ||
49 | + ); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Displays a single BlogCategory model. | ||
54 | + * | ||
55 | + * @param integer $id | ||
56 | + * | ||
57 | + * @return mixed | ||
58 | + */ | ||
59 | + public function actionView($id) | ||
60 | + { | ||
61 | + return $this->render( | ||
62 | + 'view', | ||
63 | + [ | ||
64 | + 'model' => $this->findModel($id), | ||
65 | + ] | ||
66 | + ); | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Creates a new BlogCategory model. | ||
71 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
72 | + * | ||
73 | + * @return mixed | ||
74 | + */ | ||
75 | + public function actionCreate() | ||
76 | + { | ||
77 | + $model = new BlogCategory(); | ||
78 | + $model->generateLangs(); | ||
79 | + $parentCategories = ArrayHelper::map( | ||
80 | + BlogCategory::find() | ||
81 | + ->joinWith('lang') | ||
82 | + ->where( | ||
83 | + [ | ||
84 | + 'parent_id' => 0, | ||
85 | + ] | ||
86 | + ) | ||
87 | + ->all(), | ||
88 | + 'id', | ||
89 | + 'lang.title' | ||
90 | + ); | ||
91 | + | ||
92 | + if ($model->load(Yii::$app->request->post())) { | ||
93 | + $model->loadLangs(\Yii::$app->request); | ||
94 | + if ($model->save() && $model->transactionStatus) { | ||
95 | + return $this->redirect( | ||
96 | + [ | ||
97 | + 'view', | ||
98 | + 'id' => $model->id, | ||
99 | + ] | ||
100 | + ); | ||
101 | + } | ||
102 | + } | ||
103 | + return $this->render( | ||
104 | + 'create', | ||
105 | + [ | ||
106 | + 'model' => $model, | ||
107 | + 'modelLangs' => $model->modelLangs, | ||
108 | + 'parentCategories' => $parentCategories, | ||
109 | + ] | ||
110 | + ); | ||
111 | + | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * Updates an existing BlogCategory model. | ||
116 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
117 | + * | ||
118 | + * @param integer $id | ||
119 | + * | ||
120 | + * @return mixed | ||
121 | + */ | ||
122 | + public function actionUpdate($id) | ||
123 | + { | ||
124 | + $model = $this->findModel($id); | ||
125 | + $model->generateLangs(); | ||
126 | + $parentCategories = ArrayHelper::map( | ||
127 | + BlogCategory::find() | ||
128 | + ->joinWith('lang') | ||
129 | + ->where( | ||
130 | + [ | ||
131 | + 'parent_id' => 0, | ||
132 | + ] | ||
133 | + ) | ||
134 | + ->andWhere( | ||
135 | + [ | ||
136 | + '!=', | ||
137 | + BlogCategory::tableName() . '_id', | ||
138 | + $model->id, | ||
139 | + ] | ||
140 | + ) | ||
141 | + ->all(), | ||
142 | + 'id', | ||
143 | + 'lang.title' | ||
144 | + ); | ||
145 | + | ||
146 | + if ($model->load(Yii::$app->request->post())) { | ||
147 | + $model->loadLangs(\Yii::$app->request); | ||
148 | + if ($model->save() && $model->transactionStatus) { | ||
149 | + return $this->redirect( | ||
150 | + [ | ||
151 | + 'view', | ||
152 | + 'id' => $model->id, | ||
153 | + ] | ||
154 | + ); | ||
155 | + } | ||
156 | + } | ||
157 | + return $this->render( | ||
158 | + 'update', | ||
159 | + [ | ||
160 | + 'model' => $model, | ||
161 | + 'modelLangs' => $model->modelLangs, | ||
162 | + 'parentCategories' => $parentCategories, | ||
163 | + ] | ||
164 | + ); | ||
165 | + | ||
166 | + } | ||
167 | + | ||
168 | + /** | ||
169 | + * Deletes an existing BlogCategory model. | ||
170 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
171 | + * | ||
172 | + * @param integer $id | ||
173 | + * | ||
174 | + * @return mixed | ||
175 | + */ | ||
176 | + public function actionDelete($id) | ||
177 | + { | ||
178 | + $this->findModel($id) | ||
179 | + ->delete(); | ||
180 | + | ||
181 | + return $this->redirect([ 'index' ]); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Finds the BlogCategory model based on its primary key value. | ||
186 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
187 | + * | ||
188 | + * @param integer $id | ||
189 | + * | ||
190 | + * @return BlogCategory the loaded model | ||
191 | + * @throws NotFoundHttpException if the model cannot be found | ||
192 | + */ | ||
193 | + protected function findModel($id) | ||
194 | + { | ||
195 | + if (( $model = BlogCategory::findOne($id) ) !== NULL) { | ||
196 | + return $model; | ||
197 | + } else { | ||
198 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
199 | + } | ||
200 | + } | ||
201 | + } |
common/modules/blog/controllers/BlogTagController.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\controllers; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use common\modules\blog\models\BlogTag; | ||
7 | + use common\modules\blog\models\BlogTagSearch; | ||
8 | + use yii\web\Controller; | ||
9 | + use yii\web\NotFoundHttpException; | ||
10 | + use yii\filters\VerbFilter; | ||
11 | + | ||
12 | + /** | ||
13 | + * BlogTagController implements the CRUD actions for BlogTag model. | ||
14 | + */ | ||
15 | + class BlogTagController extends Controller | ||
16 | + { | ||
17 | + /** | ||
18 | + * @inheritdoc | ||
19 | + */ | ||
20 | + public function behaviors() | ||
21 | + { | ||
22 | + return [ | ||
23 | + 'verbs' => [ | ||
24 | + 'class' => VerbFilter::className(), | ||
25 | + 'actions' => [ | ||
26 | + 'delete' => [ 'POST' ], | ||
27 | + ], | ||
28 | + ], | ||
29 | + ]; | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * Lists all BlogTag models. | ||
34 | + * | ||
35 | + * @return mixed | ||
36 | + */ | ||
37 | + public function actionIndex() | ||
38 | + { | ||
39 | + $searchModel = new BlogTagSearch(); | ||
40 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
41 | + | ||
42 | + return $this->render( | ||
43 | + 'index', | ||
44 | + [ | ||
45 | + 'searchModel' => $searchModel, | ||
46 | + 'dataProvider' => $dataProvider, | ||
47 | + ] | ||
48 | + ); | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Displays a single BlogTag model. | ||
53 | + * | ||
54 | + * @param integer $id | ||
55 | + * | ||
56 | + * @return mixed | ||
57 | + */ | ||
58 | + public function actionView($id) | ||
59 | + { | ||
60 | + return $this->render( | ||
61 | + 'view', | ||
62 | + [ | ||
63 | + 'model' => $this->findModel($id), | ||
64 | + ] | ||
65 | + ); | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Creates a new BlogTag model. | ||
70 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
71 | + * | ||
72 | + * @return mixed | ||
73 | + */ | ||
74 | + public function actionCreate() | ||
75 | + { | ||
76 | + $model = new BlogTag(); | ||
77 | + $model->generateLangs(); | ||
78 | + | ||
79 | + if (\Yii::$app->request->isPost) { | ||
80 | + $model->loadLangs(\Yii::$app->request); | ||
81 | + $model->markAttributeDirty('id'); | ||
82 | + if ($model->save() && $model->transactionStatus) { | ||
83 | + return $this->redirect( | ||
84 | + [ | ||
85 | + 'view', | ||
86 | + 'id' => $model->id, | ||
87 | + ] | ||
88 | + ); | ||
89 | + } | ||
90 | + } | ||
91 | + return $this->render( | ||
92 | + 'create', | ||
93 | + [ | ||
94 | + 'model' => $model, | ||
95 | + 'modelLangs' => $model->modelLangs, | ||
96 | + ] | ||
97 | + ); | ||
98 | + | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Updates an existing BlogTag model. | ||
103 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
104 | + * | ||
105 | + * @param integer $id | ||
106 | + * | ||
107 | + * @return mixed | ||
108 | + */ | ||
109 | + public function actionUpdate($id) | ||
110 | + { | ||
111 | + $model = $this->findModel($id); | ||
112 | + $model->generateLangs(); | ||
113 | + | ||
114 | + if (Yii::$app->request->isPost) { | ||
115 | + $model->loadLangs(\Yii::$app->request); | ||
116 | + $model->markAttributeDirty('id'); | ||
117 | + if ($model->save() && $model->transactionStatus) { | ||
118 | + return $this->redirect( | ||
119 | + [ | ||
120 | + 'view', | ||
121 | + 'id' => $model->id, | ||
122 | + ] | ||
123 | + ); | ||
124 | + } | ||
125 | + } | ||
126 | + return $this->render( | ||
127 | + 'update', | ||
128 | + [ | ||
129 | + 'model' => $model, | ||
130 | + 'modelLangs' => $model->modelLangs, | ||
131 | + ] | ||
132 | + ); | ||
133 | + | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
137 | + * Deletes an existing BlogTag model. | ||
138 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
139 | + * | ||
140 | + * @param integer $id | ||
141 | + * | ||
142 | + * @return mixed | ||
143 | + */ | ||
144 | + public function actionDelete($id) | ||
145 | + { | ||
146 | + $this->findModel($id) | ||
147 | + ->delete(); | ||
148 | + | ||
149 | + return $this->redirect([ 'index' ]); | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Finds the BlogTag model based on its primary key value. | ||
154 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
155 | + * | ||
156 | + * @param integer $id | ||
157 | + * | ||
158 | + * @return BlogTag the loaded model | ||
159 | + * @throws NotFoundHttpException if the model cannot be found | ||
160 | + */ | ||
161 | + protected function findModel($id) | ||
162 | + { | ||
163 | + if (( $model = BlogTag::findOne($id) ) !== NULL) { | ||
164 | + return $model; | ||
165 | + } else { | ||
166 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
167 | + } | ||
168 | + } | ||
169 | + } |
common/modules/blog/controllers/DefaultController.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace common\modules\blog\controllers; | ||
4 | + | ||
5 | +use yii\web\Controller; | ||
6 | + | ||
7 | +/** | ||
8 | + * Default controller for the `blog` module | ||
9 | + */ | ||
10 | +class DefaultController extends Controller | ||
11 | +{ | ||
12 | + /** | ||
13 | + * Renders the index view for the module | ||
14 | + * @return string | ||
15 | + */ | ||
16 | + public function actionIndex() | ||
17 | + { | ||
18 | + return $this->render('index'); | ||
19 | + } | ||
20 | +} |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use common\behaviors\SaveImgBehavior; | ||
6 | + use yii\behaviors\TimestampBehavior; | ||
7 | + use yii\db\ActiveRecord; | ||
8 | + use common\modules\language\behaviors\LanguageBehavior; | ||
9 | + use common\modules\language\models\Language; | ||
10 | + use common\modules\product\models\Product; | ||
11 | + use yii\db\ActiveQuery; | ||
12 | + use yii\web\Request; | ||
13 | + | ||
14 | + /** | ||
15 | + * This is the model class for table "blog_article". | ||
16 | + * | ||
17 | + * @property integer $id | ||
18 | + * @property string $image | ||
19 | + * @property integer $created_at | ||
20 | + * @property integer $updated_at | ||
21 | + * @property integer $deleted_at | ||
22 | + * @property integer $sort | ||
23 | + * @property boolean $status | ||
24 | + * @property integer $author_id | ||
25 | + * @property BlogArticleLang[] $blogArticleLangs | ||
26 | + * @property Language[] $languages | ||
27 | + * @property BlogArticle[] $relatedBlogArticles | ||
28 | + * @property BlogArticle[] $blogArticles | ||
29 | + * @property BlogCategory[] $blogCategories | ||
30 | + * @property Product[] $products | ||
31 | + * @property BlogTag[] $blogTags | ||
32 | + * * * From language behavior * | ||
33 | + * @property BlogArticleLang $lang | ||
34 | + * @property BlogArticleLang[] $langs | ||
35 | + * @property BlogArticleLang $objectLang | ||
36 | + * @property string $ownerKey | ||
37 | + * @property string $langKey | ||
38 | + * @property BlogArticleLang[] $modelLangs | ||
39 | + * @property bool $transactionStatus | ||
40 | + * @method string getOwnerKey() | ||
41 | + * @method void setOwnerKey( string $value ) | ||
42 | + * @method string getLangKey() | ||
43 | + * @method void setLangKey( string $value ) | ||
44 | + * @method ActiveQuery getLangs() | ||
45 | + * @method ActiveQuery getLang( integer $language_id ) | ||
46 | + * @method BlogArticleLang[] generateLangs() | ||
47 | + * @method void loadLangs( Request $request ) | ||
48 | + * @method bool linkLangs() | ||
49 | + * @method bool saveLangs() | ||
50 | + * @method bool getTransactionStatus() | ||
51 | + * * End language behavior * | ||
52 | + * * From SaveImgBehavior | ||
53 | + * @property string|null $imageFile | ||
54 | + * @property string|null $imageUrl | ||
55 | + * @method string|null getImageFile( int $field ) | ||
56 | + * @method string|null getImageUrl( int $field ) | ||
57 | + * * End SaveImgBehavior | ||
58 | + */ | ||
59 | + class BlogArticle extends ActiveRecord | ||
60 | + { | ||
61 | + /** | ||
62 | + * @inheritdoc | ||
63 | + */ | ||
64 | + public static function tableName() | ||
65 | + { | ||
66 | + return 'blog_article'; | ||
67 | + } | ||
68 | + | ||
69 | + public function behaviors() | ||
70 | + { | ||
71 | + return [ | ||
72 | + [ | ||
73 | + 'class' => TimestampBehavior::className(), | ||
74 | + ], | ||
75 | + [ | ||
76 | + 'class' => SaveImgBehavior::className(), | ||
77 | + 'fields' => [ | ||
78 | + [ | ||
79 | + 'name' => 'image', | ||
80 | + 'directory' => 'blog/article', | ||
81 | + ], | ||
82 | + ], | ||
83 | + ], | ||
84 | + 'language' => [ | ||
85 | + 'class' => LanguageBehavior::className(), | ||
86 | + ], | ||
87 | + ]; | ||
88 | + } | ||
89 | + /** | ||
90 | + * @inheritdoc | ||
91 | + */ | ||
92 | + public function rules() | ||
93 | + { | ||
94 | + return [ | ||
95 | + [ | ||
96 | + [ | ||
97 | + 'created_at', | ||
98 | + 'updated_at', | ||
99 | + 'deleted_at', | ||
100 | + 'sort', | ||
101 | + 'author_id', | ||
102 | + ], | ||
103 | + 'integer', | ||
104 | + ], | ||
105 | + [ | ||
106 | + [ 'status' ], | ||
107 | + 'boolean', | ||
108 | + ], | ||
109 | + [ | ||
110 | + [ 'image' ], | ||
111 | + 'string', | ||
112 | + 'max' => 255, | ||
113 | + ], | ||
114 | + ]; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * @inheritdoc | ||
119 | + */ | ||
120 | + public function attributeLabels() | ||
121 | + { | ||
122 | + return [ | ||
123 | + 'id' => 'ID', | ||
124 | + 'image' => 'Image', | ||
125 | + 'created_at' => 'Created At', | ||
126 | + 'updated_at' => 'Updated At', | ||
127 | + 'deleted_at' => 'Deleted At', | ||
128 | + 'sort' => 'Sort', | ||
129 | + 'status' => 'Status', | ||
130 | + 'author_id' => 'Author ID', | ||
131 | + ]; | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * @return \yii\db\ActiveQuery | ||
136 | + */ | ||
137 | + public function getBlogArticleLangs() | ||
138 | + { | ||
139 | + return $this->hasMany(BlogArticleLang::className(), [ 'blog_article_id' => 'id' ]); | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * @return \yii\db\ActiveQuery | ||
144 | + */ | ||
145 | + public function getLanguages() | ||
146 | + { | ||
147 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | ||
148 | + ->viaTable('blog_article_lang', [ 'blog_article_id' => 'id' ]); | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * @return \yii\db\ActiveQuery | ||
153 | + */ | ||
154 | + public function getRelatedBlogArticles() | ||
155 | + { | ||
156 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'related_blog_article_id' ]) | ||
157 | + ->viaTable('blog_article_to_article', [ 'blog_article_id' => 'id' ]); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * @return \yii\db\ActiveQuery | ||
162 | + */ | ||
163 | + public function getBlogArticles() | ||
164 | + { | ||
165 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | ||
166 | + ->viaTable('blog_article_to_article', [ 'related_blog_article_id' => 'id' ]); | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * @return \yii\db\ActiveQuery | ||
171 | + */ | ||
172 | + public function getBlogCategories() | ||
173 | + { | ||
174 | + return $this->hasMany(BlogCategory::className(), [ 'id' => 'blog_category_id' ]) | ||
175 | + ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * @return \yii\db\ActiveQuery | ||
180 | + */ | ||
181 | + public function getProducts() | ||
182 | + { | ||
183 | + return $this->hasMany(Product::className(), [ 'id' => 'product_id' ]) | ||
184 | + ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * @return \yii\db\ActiveQuery | ||
189 | + */ | ||
190 | + public function getBlogTags() | ||
191 | + { | ||
192 | + return $this->hasMany(BlogTag::className(), [ 'id' => 'blog_tag_id' ]) | ||
193 | + ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); | ||
194 | + } | ||
195 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use common\modules\language\models\Language; | ||
6 | + use yii\db\ActiveRecord; | ||
7 | + | ||
8 | + /** | ||
9 | + * This is the model class for table "blog_article_lang". | ||
10 | + * | ||
11 | + * @property integer $id | ||
12 | + * @property integer $blog_article_id | ||
13 | + * @property integer $language_id | ||
14 | + * @property string $title | ||
15 | + * @property string $body | ||
16 | + * @property string $body_preview | ||
17 | + * @property string $alias | ||
18 | + * @property string $meta_title | ||
19 | + * @property string $meta_description | ||
20 | + * @property string $h1 | ||
21 | + * @property string $seo_text | ||
22 | + * @property BlogArticle $blogArticle | ||
23 | + * @property Language $language | ||
24 | + */ | ||
25 | + class BlogArticleLang extends ActiveRecord | ||
26 | + { | ||
27 | + /** | ||
28 | + * @inheritdoc | ||
29 | + */ | ||
30 | + public static function tableName() | ||
31 | + { | ||
32 | + return 'blog_article_lang'; | ||
33 | + } | ||
34 | + | ||
35 | + public function behaviors() | ||
36 | + { | ||
37 | + return [ | ||
38 | + 'slug' => [ | ||
39 | + 'class' => 'common\behaviors\Slug', | ||
40 | + ], | ||
41 | + ]; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * @inheritdoc | ||
46 | + */ | ||
47 | + public function rules() | ||
48 | + { | ||
49 | + return [ | ||
50 | + [ | ||
51 | + [ | ||
52 | + 'blog_article_id', | ||
53 | + 'language_id', | ||
54 | + ], | ||
55 | + 'required', | ||
56 | + ], | ||
57 | + [ | ||
58 | + [ | ||
59 | + 'blog_article_id', | ||
60 | + 'language_id', | ||
61 | + ], | ||
62 | + 'integer', | ||
63 | + ], | ||
64 | + [ | ||
65 | + [ | ||
66 | + 'body', | ||
67 | + 'body_preview', | ||
68 | + ], | ||
69 | + 'string', | ||
70 | + ], | ||
71 | + [ | ||
72 | + [ | ||
73 | + 'title', | ||
74 | + 'alias', | ||
75 | + 'meta_title', | ||
76 | + 'meta_description', | ||
77 | + 'h1', | ||
78 | + 'seo_text', | ||
79 | + ], | ||
80 | + 'string', | ||
81 | + 'max' => 255, | ||
82 | + ], | ||
83 | + [ | ||
84 | + [ 'alias' ], | ||
85 | + 'unique', | ||
86 | + ], | ||
87 | + [ | ||
88 | + [ | ||
89 | + 'blog_article_id', | ||
90 | + 'language_id', | ||
91 | + ], | ||
92 | + 'unique', | ||
93 | + 'targetAttribute' => [ | ||
94 | + 'blog_article_id', | ||
95 | + 'language_id', | ||
96 | + ], | ||
97 | + 'message' => 'The combination of Blog Article ID and Language ID has already been taken.', | ||
98 | + ], | ||
99 | + [ | ||
100 | + [ 'blog_article_id' ], | ||
101 | + 'exist', | ||
102 | + 'skipOnError' => true, | ||
103 | + 'targetClass' => BlogArticle::className(), | ||
104 | + 'targetAttribute' => [ 'blog_article_id' => 'id' ], | ||
105 | + ], | ||
106 | + [ | ||
107 | + [ 'language_id' ], | ||
108 | + 'exist', | ||
109 | + 'skipOnError' => true, | ||
110 | + 'targetClass' => Language::className(), | ||
111 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
112 | + ], | ||
113 | + ]; | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * @inheritdoc | ||
118 | + */ | ||
119 | + public function attributeLabels() | ||
120 | + { | ||
121 | + return [ | ||
122 | + 'id' => 'ID', | ||
123 | + 'blog_article_id' => 'Blog Article ID', | ||
124 | + 'language_id' => 'Language ID', | ||
125 | + 'title' => 'Title', | ||
126 | + 'body' => 'Body', | ||
127 | + 'body_preview' => 'Body Preview', | ||
128 | + 'alias' => 'Alias', | ||
129 | + 'meta_title' => 'Meta Title', | ||
130 | + 'meta_description' => 'Meta Description', | ||
131 | + 'h1' => 'H1', | ||
132 | + 'seo_text' => 'Seo Text', | ||
133 | + ]; | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
137 | + * @return \yii\db\ActiveQuery | ||
138 | + */ | ||
139 | + public function getBlogArticle() | ||
140 | + { | ||
141 | + return $this->hasOne(BlogArticle::className(), [ 'id' => 'blog_article_id' ]); | ||
142 | + } | ||
143 | + | ||
144 | + /** | ||
145 | + * @return \yii\db\ActiveQuery | ||
146 | + */ | ||
147 | + public function getLanguage() | ||
148 | + { | ||
149 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
150 | + } | ||
151 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * BlogArticleSearch represents the model behind the search form about `common\modules\blog\models\BlogArticle`. | ||
10 | + */ | ||
11 | + class BlogArticleSearch extends BlogArticle | ||
12 | + { | ||
13 | + /** | ||
14 | + * @var string | ||
15 | + */ | ||
16 | + public $title; | ||
17 | + /** | ||
18 | + * @inheritdoc | ||
19 | + */ | ||
20 | + public function rules() | ||
21 | + { | ||
22 | + return [ | ||
23 | + [ | ||
24 | + [ | ||
25 | + 'id', | ||
26 | + 'deleted_at', | ||
27 | + 'sort', | ||
28 | + 'author_id', | ||
29 | + ], | ||
30 | + 'integer', | ||
31 | + ], | ||
32 | + [ | ||
33 | + [ 'image' ], | ||
34 | + 'safe', | ||
35 | + ], | ||
36 | + [ | ||
37 | + [ 'status' ], | ||
38 | + 'boolean', | ||
39 | + ], | ||
40 | + [ | ||
41 | + [ 'title' ], | ||
42 | + 'string', | ||
43 | + ], | ||
44 | + ]; | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * @inheritdoc | ||
49 | + */ | ||
50 | + public function behaviors() | ||
51 | + { | ||
52 | + return []; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * @inheritdoc | ||
57 | + */ | ||
58 | + public function scenarios() | ||
59 | + { | ||
60 | + // bypass scenarios() implementation in the parent class | ||
61 | + return Model::scenarios(); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Creates data provider instance with search query applied | ||
66 | + * | ||
67 | + * @param array $params | ||
68 | + * | ||
69 | + * @return ActiveDataProvider | ||
70 | + */ | ||
71 | + public function search($params) | ||
72 | + { | ||
73 | + $query = BlogArticle::find() | ||
74 | + ->joinWith('lang'); | ||
75 | + | ||
76 | + // add conditions that should always apply here | ||
77 | + | ||
78 | + $dataProvider = new ActiveDataProvider( | ||
79 | + [ | ||
80 | + 'query' => $query, | ||
81 | + 'sort' => [ | ||
82 | + 'attributes' => [ | ||
83 | + 'id', | ||
84 | + 'created_at', | ||
85 | + 'updated_at', | ||
86 | + 'title' => [ | ||
87 | + 'asc' => [ 'blog_article_lang.title' => SORT_ASC ], | ||
88 | + 'desc' => [ 'blog_article_lang.title' => SORT_DESC ], | ||
89 | + ], | ||
90 | + ], | ||
91 | + ], | ||
92 | + ] | ||
93 | + ); | ||
94 | + | ||
95 | + $this->load($params); | ||
96 | + | ||
97 | + if (!$this->validate()) { | ||
98 | + // uncomment the following line if you do not want to return any records when validation fails | ||
99 | + // $query->where('0=1'); | ||
100 | + return $dataProvider; | ||
101 | + } | ||
102 | + | ||
103 | + // grid filtering conditions | ||
104 | + $query->andFilterWhere( | ||
105 | + [ | ||
106 | + 'id' => $this->id, | ||
107 | + 'status' => $this->status, | ||
108 | + 'author_id' => $this->author_id, | ||
109 | + ] | ||
110 | + ); | ||
111 | + | ||
112 | + $query->andFilterWhere( | ||
113 | + [ | ||
114 | + 'like', | ||
115 | + 'image', | ||
116 | + $this->image, | ||
117 | + ] | ||
118 | + ); | ||
119 | + | ||
120 | + $query->andFilterWhere( | ||
121 | + [ | ||
122 | + 'like', | ||
123 | + 'blog_article_lang.title', | ||
124 | + $this->title, | ||
125 | + ] | ||
126 | + ); | ||
127 | + | ||
128 | + return $dataProvider; | ||
129 | + } | ||
130 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use yii\db\ActiveRecord; | ||
6 | + use common\modules\language\behaviors\LanguageBehavior; | ||
7 | + use common\behaviors\SaveImgBehavior; | ||
8 | + use common\modules\language\models\Language; | ||
9 | + use yii\db\ActiveQuery; | ||
10 | + use yii\web\Request; | ||
11 | + | ||
12 | + /** | ||
13 | + * This is the model class for table "blog_category". | ||
14 | + * | ||
15 | + * @property integer $id | ||
16 | + * @property integer $sort | ||
17 | + * @property string $image | ||
18 | + * @property integer $parent_id | ||
19 | + * @property boolean $status | ||
20 | + * @property BlogArticle[] $blogArticles | ||
21 | + * @property BlogCategoryLang[] $blogCategoryLangs | ||
22 | + * @property Language[] $languages | ||
23 | + * @property BlogCategory $parent | ||
24 | + * * From language behavior * | ||
25 | + * @property BlogCategoryLang $lang | ||
26 | + * @property BlogCategoryLang[] $langs | ||
27 | + * @property BlogCategoryLang $objectLang | ||
28 | + * @property string $ownerKey | ||
29 | + * @property string $langKey | ||
30 | + * @property BlogCategoryLang[] $modelLangs | ||
31 | + * @property bool $transactionStatus | ||
32 | + * @method string getOwnerKey() | ||
33 | + * @method void setOwnerKey( string $value ) | ||
34 | + * @method string getLangKey() | ||
35 | + * @method void setLangKey( string $value ) | ||
36 | + * @method ActiveQuery getLangs() | ||
37 | + * @method ActiveQuery getLang( integer $language_id ) | ||
38 | + * @method BlogCategoryLang[] generateLangs() | ||
39 | + * @method void loadLangs( Request $request ) | ||
40 | + * @method bool linkLangs() | ||
41 | + * @method bool saveLangs() | ||
42 | + * @method bool getTransactionStatus() | ||
43 | + * * End language behavior * | ||
44 | + * * From SaveImgBehavior * | ||
45 | + * @property string|null $imageFile | ||
46 | + * @property string|null $imageUrl | ||
47 | + * @method string|null getImageFile( int $field ) | ||
48 | + * @method string|null getImageUrl( int $field ) | ||
49 | + * * End SaveImgBehavior | ||
50 | + */ | ||
51 | + class BlogCategory extends ActiveRecord | ||
52 | + { | ||
53 | + /** | ||
54 | + * @inheritdoc | ||
55 | + */ | ||
56 | + public static function tableName() | ||
57 | + { | ||
58 | + return 'blog_category'; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * @inheritdoc | ||
63 | + */ | ||
64 | + public function behaviors() | ||
65 | + { | ||
66 | + return [ | ||
67 | + [ | ||
68 | + 'class' => SaveImgBehavior::className(), | ||
69 | + 'fields' => [ | ||
70 | + [ | ||
71 | + 'name' => 'image', | ||
72 | + 'directory' => 'blog/category', | ||
73 | + ], | ||
74 | + ], | ||
75 | + ], | ||
76 | + 'language' => [ | ||
77 | + 'class' => LanguageBehavior::className(), | ||
78 | + ], | ||
79 | + 'Slug' => [ | ||
80 | + 'class' => 'common\behaviors\Slug', | ||
81 | + ], | ||
82 | + ]; | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * @inheritdoc | ||
87 | + */ | ||
88 | + public function rules() | ||
89 | + { | ||
90 | + return [ | ||
91 | + [ | ||
92 | + [ | ||
93 | + 'sort', | ||
94 | + 'parent_id', | ||
95 | + ], | ||
96 | + 'integer', | ||
97 | + ], | ||
98 | + [ | ||
99 | + [ 'status' ], | ||
100 | + 'boolean', | ||
101 | + ], | ||
102 | + [ | ||
103 | + [ 'image' ], | ||
104 | + 'string', | ||
105 | + 'max' => 255, | ||
106 | + ], | ||
107 | + [ | ||
108 | + [ 'parent_id' ], | ||
109 | + 'default', | ||
110 | + 'value' => 0, | ||
111 | + ], | ||
112 | + ]; | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * @inheritdoc | ||
117 | + */ | ||
118 | + public function attributeLabels() | ||
119 | + { | ||
120 | + return [ | ||
121 | + 'id' => 'ID', | ||
122 | + 'sort' => 'Sort', | ||
123 | + 'image' => 'Image', | ||
124 | + 'parent_id' => 'Parent ID', | ||
125 | + 'status' => 'Status', | ||
126 | + ]; | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * @return \yii\db\ActiveQuery | ||
131 | + */ | ||
132 | + public function getBlogArticles() | ||
133 | + { | ||
134 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | ||
135 | + ->viaTable('blog_article_to_category', [ 'blog_category_id' => 'id' ]); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * @return \yii\db\ActiveQuery | ||
140 | + */ | ||
141 | + public function getBlogCategoryLangs() | ||
142 | + { | ||
143 | + return $this->hasMany(BlogCategoryLang::className(), [ 'blog_category_id' => 'id' ]); | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * @return \yii\db\ActiveQuery | ||
148 | + */ | ||
149 | + public function getLanguages() | ||
150 | + { | ||
151 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | ||
152 | + ->viaTable('blog_category_lang', [ 'blog_category_id' => 'id' ]); | ||
153 | + } | ||
154 | + | ||
155 | + public function getParent() | ||
156 | + { | ||
157 | + return $this->hasOne(BlogCategory::className(), [ 'id' => 'parent_id' ]); | ||
158 | + } | ||
159 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use yii\db\ActiveRecord; | ||
6 | + use common\modules\language\models\Language; | ||
7 | + | ||
8 | + /** | ||
9 | + * This is the model class for table "blog_category_lang". | ||
10 | + * | ||
11 | + * @property integer $id | ||
12 | + * @property integer $blog_category_id | ||
13 | + * @property integer $language_id | ||
14 | + * @property string $title | ||
15 | + * @property string $alias | ||
16 | + * @property string $description | ||
17 | + * @property string $meta_title | ||
18 | + * @property string $meta_description | ||
19 | + * @property string $h1 | ||
20 | + * @property string $seo_text | ||
21 | + * @property BlogCategory $blogCategory | ||
22 | + * @property Language $language | ||
23 | + */ | ||
24 | + class BlogCategoryLang extends ActiveRecord | ||
25 | + { | ||
26 | + /** | ||
27 | + * @inheritdoc | ||
28 | + */ | ||
29 | + public static function tableName() | ||
30 | + { | ||
31 | + return 'blog_category_lang'; | ||
32 | + } | ||
33 | + | ||
34 | + public function behaviors() | ||
35 | + { | ||
36 | + return [ | ||
37 | + 'slug' => [ | ||
38 | + 'class' => 'common\behaviors\Slug', | ||
39 | + ], | ||
40 | + ]; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * @inheritdoc | ||
45 | + */ | ||
46 | + public function rules() | ||
47 | + { | ||
48 | + return [ | ||
49 | + [ | ||
50 | + [ | ||
51 | + 'blog_category_id', | ||
52 | + 'language_id', | ||
53 | + ], | ||
54 | + 'required', | ||
55 | + ], | ||
56 | + [ | ||
57 | + [ | ||
58 | + 'blog_category_id', | ||
59 | + 'language_id', | ||
60 | + ], | ||
61 | + 'integer', | ||
62 | + ], | ||
63 | + [ | ||
64 | + [ 'description' ], | ||
65 | + 'string', | ||
66 | + ], | ||
67 | + [ | ||
68 | + [ | ||
69 | + 'title', | ||
70 | + 'alias', | ||
71 | + 'meta_title', | ||
72 | + 'meta_description', | ||
73 | + 'h1', | ||
74 | + 'seo_text', | ||
75 | + ], | ||
76 | + 'string', | ||
77 | + 'max' => 255, | ||
78 | + ], | ||
79 | + [ | ||
80 | + [ 'alias' ], | ||
81 | + 'unique', | ||
82 | + ], | ||
83 | + [ | ||
84 | + [ | ||
85 | + 'blog_category_id', | ||
86 | + 'language_id', | ||
87 | + ], | ||
88 | + 'unique', | ||
89 | + 'targetAttribute' => [ | ||
90 | + 'blog_category_id', | ||
91 | + 'language_id', | ||
92 | + ], | ||
93 | + 'message' => 'The combination of Blog Category ID and Language ID has already been taken.', | ||
94 | + ], | ||
95 | + [ | ||
96 | + [ 'blog_category_id' ], | ||
97 | + 'exist', | ||
98 | + 'skipOnError' => true, | ||
99 | + 'targetClass' => BlogCategory::className(), | ||
100 | + 'targetAttribute' => [ 'blog_category_id' => 'id' ], | ||
101 | + ], | ||
102 | + [ | ||
103 | + [ 'language_id' ], | ||
104 | + 'exist', | ||
105 | + 'skipOnError' => true, | ||
106 | + 'targetClass' => Language::className(), | ||
107 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
108 | + ], | ||
109 | + ]; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * @inheritdoc | ||
114 | + */ | ||
115 | + public function attributeLabels() | ||
116 | + { | ||
117 | + return [ | ||
118 | + 'id' => 'ID', | ||
119 | + 'blog_category_id' => 'Blog Category ID', | ||
120 | + 'language_id' => 'Language ID', | ||
121 | + 'title' => 'Title', | ||
122 | + 'alias' => 'Alias', | ||
123 | + 'description' => 'Description', | ||
124 | + 'meta_title' => 'Meta Title', | ||
125 | + 'meta_description' => 'Meta Description', | ||
126 | + 'h1' => 'H1', | ||
127 | + 'seo_text' => 'Seo Text', | ||
128 | + ]; | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * @return \yii\db\ActiveQuery | ||
133 | + */ | ||
134 | + public function getBlogCategory() | ||
135 | + { | ||
136 | + return $this->hasOne(BlogCategory::className(), [ 'id' => 'blog_category_id' ]); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * @return \yii\db\ActiveQuery | ||
141 | + */ | ||
142 | + public function getLanguage() | ||
143 | + { | ||
144 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
145 | + } | ||
146 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * BlogCategorySearch represents the model behind the search form about `common\modules\blog\models\BlogCategory`. | ||
10 | + */ | ||
11 | + class BlogCategorySearch extends BlogCategory | ||
12 | + { | ||
13 | + /** | ||
14 | + * @var string | ||
15 | + */ | ||
16 | + public $title; | ||
17 | + /** | ||
18 | + * @inheritdoc | ||
19 | + */ | ||
20 | + public function rules() | ||
21 | + { | ||
22 | + return [ | ||
23 | + [ | ||
24 | + [ | ||
25 | + 'id', | ||
26 | + 'sort', | ||
27 | + 'parent_id', | ||
28 | + ], | ||
29 | + 'integer', | ||
30 | + ], | ||
31 | + [ | ||
32 | + [ 'image' ], | ||
33 | + 'safe', | ||
34 | + ], | ||
35 | + [ | ||
36 | + [ 'status' ], | ||
37 | + 'boolean', | ||
38 | + ], | ||
39 | + [ | ||
40 | + [ 'title' ], | ||
41 | + 'string', | ||
42 | + ], | ||
43 | + ]; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * @inheritdoc | ||
48 | + */ | ||
49 | + public function behaviors() | ||
50 | + { | ||
51 | + return []; | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * @inheritdoc | ||
56 | + */ | ||
57 | + public function scenarios() | ||
58 | + { | ||
59 | + // bypass scenarios() implementation in the parent class | ||
60 | + return Model::scenarios(); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Creates data provider instance with search query applied | ||
65 | + * | ||
66 | + * @param array $params | ||
67 | + * | ||
68 | + * @return ActiveDataProvider | ||
69 | + */ | ||
70 | + public function search($params) | ||
71 | + { | ||
72 | + $query = BlogCategory::find() | ||
73 | + ->joinWith('lang', 'parent.lang'); | ||
74 | + | ||
75 | + // add conditions that should always apply here | ||
76 | + | ||
77 | + $dataProvider = new ActiveDataProvider( | ||
78 | + [ | ||
79 | + 'query' => $query, | ||
80 | + 'sort' => [ | ||
81 | + 'attributes' => [ | ||
82 | + 'title' => [ | ||
83 | + 'asc' => [ 'blog_category_lang.title' => SORT_ASC ], | ||
84 | + 'desc' => [ 'blog_category_lang.title' => SORT_DESC ], | ||
85 | + ], | ||
86 | + 'id', | ||
87 | + ], | ||
88 | + ], | ||
89 | + ] | ||
90 | + ); | ||
91 | + | ||
92 | + $this->load($params); | ||
93 | + | ||
94 | + if (!$this->validate()) { | ||
95 | + // uncomment the following line if you do not want to return any records when validation fails | ||
96 | + // $query->where('0=1'); | ||
97 | + return $dataProvider; | ||
98 | + } | ||
99 | + | ||
100 | + // grid filtering conditions | ||
101 | + $query->andFilterWhere( | ||
102 | + [ | ||
103 | + 'id' => $this->id, | ||
104 | + 'sort' => $this->sort, | ||
105 | + 'parent_id' => $this->parent_id, | ||
106 | + 'status' => $this->status, | ||
107 | + ] | ||
108 | + ); | ||
109 | + | ||
110 | + $query->andFilterWhere( | ||
111 | + [ | ||
112 | + 'like', | ||
113 | + 'image', | ||
114 | + $this->image, | ||
115 | + ] | ||
116 | + ); | ||
117 | + | ||
118 | + $query->andFilterWhere( | ||
119 | + [ | ||
120 | + 'like', | ||
121 | + 'blog_category_lang.title', | ||
122 | + $this->title, | ||
123 | + ] | ||
124 | + ); | ||
125 | + | ||
126 | + return $dataProvider; | ||
127 | + } | ||
128 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use yii\db\ActiveRecord; | ||
6 | + use common\modules\language\behaviors\LanguageBehavior; | ||
7 | + use common\modules\language\models\Language; | ||
8 | + use yii\db\ActiveQuery; | ||
9 | + use yii\web\Request; | ||
10 | + | ||
11 | + /** | ||
12 | + * This is the model class for table "blog_tag". | ||
13 | + * | ||
14 | + * @property integer $id | ||
15 | + * @property BlogArticle[] $blogArticles | ||
16 | + * @property BlogTagLang[] $blogTagLangs | ||
17 | + * @property Language[] $languages | ||
18 | + * * From language behavior * | ||
19 | + * @property BlogTagLang $lang | ||
20 | + * @property BlogTagLang[] $langs | ||
21 | + * @property BlogTagLang $objectLang | ||
22 | + * @property string $ownerKey | ||
23 | + * @property string $langKey | ||
24 | + * @property BlogTagLang[] $modelLangs | ||
25 | + * @property bool $transactionStatus | ||
26 | + * @method string getOwnerKey() | ||
27 | + * @method void setOwnerKey( string $value ) | ||
28 | + * @method string getLangKey() | ||
29 | + * @method void setLangKey( string $value ) | ||
30 | + * @method ActiveQuery getLangs() | ||
31 | + * @method ActiveQuery getLang( integer $language_id ) | ||
32 | + * @method BlogTagLang[] generateLangs() | ||
33 | + * @method void loadLangs( Request $request ) | ||
34 | + * @method bool linkLangs() | ||
35 | + * @method bool saveLangs() | ||
36 | + * @method bool getTransactionStatus() | ||
37 | + * * End language behavior * | ||
38 | + */ | ||
39 | + class BlogTag extends ActiveRecord | ||
40 | + { | ||
41 | + /** | ||
42 | + * @inheritdoc | ||
43 | + */ | ||
44 | + public static function tableName() | ||
45 | + { | ||
46 | + return 'blog_tag'; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * @inheritdoc | ||
51 | + */ | ||
52 | + public function behaviors() | ||
53 | + { | ||
54 | + return [ | ||
55 | + 'language' => [ | ||
56 | + 'class' => LanguageBehavior::className(), | ||
57 | + ], | ||
58 | + ]; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * @inheritdoc | ||
63 | + */ | ||
64 | + public function rules() | ||
65 | + { | ||
66 | + return [ | ||
67 | + [ | ||
68 | + [ 'id' ], | ||
69 | + 'integer', | ||
70 | + ], | ||
71 | + ]; | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * @inheritdoc | ||
76 | + */ | ||
77 | + public function attributeLabels() | ||
78 | + { | ||
79 | + return [ | ||
80 | + 'id' => 'ID', | ||
81 | + ]; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * @return \yii\db\ActiveQuery | ||
86 | + */ | ||
87 | + public function getBlogArticles() | ||
88 | + { | ||
89 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | ||
90 | + ->viaTable('blog_article_to_tag', [ 'blog_tag_id' => 'id' ]); | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * @return \yii\db\ActiveQuery | ||
95 | + */ | ||
96 | + public function getBlogTagLangs() | ||
97 | + { | ||
98 | + return $this->hasMany(BlogTagLang::className(), [ 'blog_tag_id' => 'id' ]); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * @return \yii\db\ActiveQuery | ||
103 | + */ | ||
104 | + public function getLanguages() | ||
105 | + { | ||
106 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | ||
107 | + ->viaTable('blog_tag_lang', [ 'blog_tag_id' => 'id' ]); | ||
108 | + } | ||
109 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use common\modules\language\models\Language; | ||
6 | + use yii\db\ActiveRecord; | ||
7 | + | ||
8 | + /** | ||
9 | + * This is the model class for table "blog_tag_lang". | ||
10 | + * | ||
11 | + * @property integer $id | ||
12 | + * @property integer $blog_tag_id | ||
13 | + * @property integer $language_id | ||
14 | + * @property string $label | ||
15 | + * @property BlogTag $blogTag | ||
16 | + * @property Language $language | ||
17 | + */ | ||
18 | + class BlogTagLang extends ActiveRecord | ||
19 | + { | ||
20 | + /** | ||
21 | + * @inheritdoc | ||
22 | + */ | ||
23 | + public static function tableName() | ||
24 | + { | ||
25 | + return 'blog_tag_lang'; | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
29 | + * @inheritdoc | ||
30 | + */ | ||
31 | + public function rules() | ||
32 | + { | ||
33 | + return [ | ||
34 | + [ | ||
35 | + [ | ||
36 | + 'blog_tag_id', | ||
37 | + 'language_id', | ||
38 | + ], | ||
39 | + 'required', | ||
40 | + ], | ||
41 | + [ | ||
42 | + [ | ||
43 | + 'blog_tag_id', | ||
44 | + 'language_id', | ||
45 | + ], | ||
46 | + 'integer', | ||
47 | + ], | ||
48 | + [ | ||
49 | + [ 'label' ], | ||
50 | + 'string', | ||
51 | + 'max' => 255, | ||
52 | + ], | ||
53 | + [ | ||
54 | + [ | ||
55 | + 'blog_tag_id', | ||
56 | + 'language_id', | ||
57 | + ], | ||
58 | + 'unique', | ||
59 | + 'targetAttribute' => [ | ||
60 | + 'blog_tag_id', | ||
61 | + 'language_id', | ||
62 | + ], | ||
63 | + 'message' => 'The combination of Blog Tag ID and Language ID has already been taken.', | ||
64 | + ], | ||
65 | + [ | ||
66 | + [ 'blog_tag_id' ], | ||
67 | + 'exist', | ||
68 | + 'skipOnError' => true, | ||
69 | + 'targetClass' => BlogTag::className(), | ||
70 | + 'targetAttribute' => [ 'blog_tag_id' => 'id' ], | ||
71 | + ], | ||
72 | + [ | ||
73 | + [ 'language_id' ], | ||
74 | + 'exist', | ||
75 | + 'skipOnError' => true, | ||
76 | + 'targetClass' => Language::className(), | ||
77 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
78 | + ], | ||
79 | + ]; | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * @inheritdoc | ||
84 | + */ | ||
85 | + public function attributeLabels() | ||
86 | + { | ||
87 | + return [ | ||
88 | + 'id' => 'ID', | ||
89 | + 'blog_tag_id' => 'Blog Tag ID', | ||
90 | + 'language_id' => 'Language ID', | ||
91 | + 'label' => 'Label', | ||
92 | + ]; | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * @return \yii\db\ActiveQuery | ||
97 | + */ | ||
98 | + public function getBlogTag() | ||
99 | + { | ||
100 | + return $this->hasOne(BlogTag::className(), [ 'id' => 'blog_tag_id' ]); | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * @return \yii\db\ActiveQuery | ||
105 | + */ | ||
106 | + public function getLanguage() | ||
107 | + { | ||
108 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
109 | + } | ||
110 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace common\modules\blog\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * BlogTagSearch represents the model behind the search form about `common\modules\blog\models\BlogTag`. | ||
10 | + */ | ||
11 | + class BlogTagSearch extends BlogTag | ||
12 | + { | ||
13 | + /** | ||
14 | + * @var string | ||
15 | + */ | ||
16 | + public $label; | ||
17 | + | ||
18 | + /** | ||
19 | + * @inheritdoc | ||
20 | + */ | ||
21 | + public function rules() | ||
22 | + { | ||
23 | + return [ | ||
24 | + [ | ||
25 | + [ 'id' ], | ||
26 | + 'integer', | ||
27 | + ], | ||
28 | + [ | ||
29 | + [ 'label' ], | ||
30 | + 'string', | ||
31 | + ], | ||
32 | + ]; | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * @inheritdoc | ||
37 | + */ | ||
38 | + public function behaviors() | ||
39 | + { | ||
40 | + return []; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * @inheritdoc | ||
45 | + */ | ||
46 | + public function scenarios() | ||
47 | + { | ||
48 | + // bypass scenarios() implementation in the parent class | ||
49 | + return Model::scenarios(); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Creates data provider instance with search query applied | ||
54 | + * | ||
55 | + * @param array $params | ||
56 | + * | ||
57 | + * @return ActiveDataProvider | ||
58 | + */ | ||
59 | + public function search($params) | ||
60 | + { | ||
61 | + $query = BlogTag::find() | ||
62 | + ->joinWith('lang'); | ||
63 | + | ||
64 | + // add conditions that should always apply here | ||
65 | + | ||
66 | + $dataProvider = new ActiveDataProvider( | ||
67 | + [ | ||
68 | + 'query' => $query, | ||
69 | + 'sort' => [ | ||
70 | + 'attributes' => [ | ||
71 | + 'id', | ||
72 | + 'label' => [ | ||
73 | + 'asc' => [ 'blog_tag_lang.label' => SORT_ASC ], | ||
74 | + 'desc' => [ 'blog_tag_lang.label' => SORT_DESC ], | ||
75 | + ], | ||
76 | + ], | ||
77 | + ], | ||
78 | + ] | ||
79 | + ); | ||
80 | + | ||
81 | + $this->load($params); | ||
82 | + | ||
83 | + if (!$this->validate()) { | ||
84 | + // uncomment the following line if you do not want to return any records when validation fails | ||
85 | + // $query->where('0=1'); | ||
86 | + return $dataProvider; | ||
87 | + } | ||
88 | + | ||
89 | + // grid filtering conditions | ||
90 | + $query->andFilterWhere( | ||
91 | + [ | ||
92 | + 'id' => $this->id, | ||
93 | + ] | ||
94 | + ); | ||
95 | + | ||
96 | + $query->andFilterWhere( | ||
97 | + [ | ||
98 | + 'like', | ||
99 | + 'blog_tag_lang.label', | ||
100 | + $this->label, | ||
101 | + ] | ||
102 | + ); | ||
103 | + | ||
104 | + return $dataProvider; | ||
105 | + } | ||
106 | + } |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogArticle; | ||
4 | + use common\modules\blog\models\BlogArticleLang; | ||
5 | + use common\modules\blog\models\BlogCategory; | ||
6 | + use common\modules\blog\models\BlogTag; | ||
7 | + use kartik\select2\Select2; | ||
8 | + use yii\helpers\Html; | ||
9 | + use yii\web\View; | ||
10 | + use yii\widgets\ActiveForm; | ||
11 | + use common\modules\language\widgets\LanguageForm; | ||
12 | + use yii\web\JsExpression; | ||
13 | + | ||
14 | + /** | ||
15 | + * @var View $this | ||
16 | + * @var BlogArticle $model | ||
17 | + * @var ActiveForm $form | ||
18 | + * @var BlogArticleLang[] $modelLangs | ||
19 | + * @var BlogCategory[] $categories | ||
20 | + * @var BlogTag[] $tags | ||
21 | + * @var array $products | ||
22 | + * @var array $articles | ||
23 | + */ | ||
24 | +?> | ||
25 | + | ||
26 | +<div class="blog-article-form"> | ||
27 | + | ||
28 | + <?php $form = ActiveForm::begin( | ||
29 | + [ | ||
30 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | ||
31 | + ] | ||
32 | + ); ?> | ||
33 | + | ||
34 | + <?php | ||
35 | + echo LanguageForm::widget( | ||
36 | + [ | ||
37 | + 'modelLangs' => $modelLangs, | ||
38 | + 'formView' => '@common/modules/blog/views/blog-article/_form_language', | ||
39 | + 'form' => $form, | ||
40 | + ] | ||
41 | + ); | ||
42 | + ?> | ||
43 | + | ||
44 | + <?php | ||
45 | + echo $form->field($model, 'blogCategories') | ||
46 | + ->widget( | ||
47 | + Select2::className(), | ||
48 | + [ | ||
49 | + 'data' => $categories, | ||
50 | + 'theme' => Select2::THEME_BOOTSTRAP, | ||
51 | + 'options' => [ | ||
52 | + 'placeholder' => \Yii::t('blog', 'Select category'), | ||
53 | + 'multiple' => true, | ||
54 | + ], | ||
55 | + 'pluginOptions' => [ | ||
56 | + 'allowClear' => true, | ||
57 | + ], | ||
58 | + ] | ||
59 | + ); | ||
60 | + ?> | ||
61 | + | ||
62 | + <?php | ||
63 | + echo $form->field($model, 'blogTags') | ||
64 | + ->widget( | ||
65 | + Select2::className(), | ||
66 | + [ | ||
67 | + 'data' => $tags, | ||
68 | + 'theme' => Select2::THEME_BOOTSTRAP, | ||
69 | + 'options' => [ | ||
70 | + 'placeholder' => \Yii::t('blog', 'Select tag'), | ||
71 | + 'multiple' => true, | ||
72 | + ], | ||
73 | + 'pluginOptions' => [ | ||
74 | + 'allowClear' => true, | ||
75 | + ], | ||
76 | + ] | ||
77 | + ); | ||
78 | + ?> | ||
79 | + | ||
80 | + <?= $form->field($model, 'image') | ||
81 | + ->widget( | ||
82 | + \kartik\file\FileInput::className(), | ||
83 | + [ | ||
84 | + 'language' => 'ru', | ||
85 | + 'options' => [ | ||
86 | + 'accept' => 'image/*', | ||
87 | + 'multiple' => false, | ||
88 | + ], | ||
89 | + 'pluginOptions' => [ | ||
90 | + 'allowedFileExtensions' => [ | ||
91 | + 'jpg', | ||
92 | + 'gif', | ||
93 | + 'png', | ||
94 | + ], | ||
95 | + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage( | ||
96 | + $model->imageUrl, | ||
97 | + 'list' | ||
98 | + ) : '', | ||
99 | + 'overwriteInitial' => true, | ||
100 | + 'showRemove' => false, | ||
101 | + 'showUpload' => false, | ||
102 | + 'previewFileType' => 'image', | ||
103 | + ], | ||
104 | + ] | ||
105 | + ); ?> | ||
106 | + | ||
107 | + <?php | ||
108 | + echo $form->field($model, 'products') | ||
109 | + ->widget( | ||
110 | + Select2::className(), | ||
111 | + [ | ||
112 | + 'data' => $products, | ||
113 | + 'options' => [ | ||
114 | + 'placeholder' => \Yii::t('blog', 'Select related products'), | ||
115 | + 'multiple' => true, | ||
116 | + ], | ||
117 | + 'pluginOptions' => [ | ||
118 | + 'allowClear' => true, | ||
119 | + 'minimumInputLength' => 3, | ||
120 | + 'language' => [ | ||
121 | + 'errorLoading' => new JsExpression( | ||
122 | + "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }" | ||
123 | + ), | ||
124 | + ], | ||
125 | + 'ajax' => [ | ||
126 | + 'url' => yii\helpers\Url::to([ '/blog/blog-article/product-list' ]), | ||
127 | + 'dataType' => 'json', | ||
128 | + 'data' => new JsExpression('function(params) { return {q:params.term}; }'), | ||
129 | + ], | ||
130 | + 'templateResult' => new JsExpression('function(product) { return product.text; }'), | ||
131 | + 'templateSelection' => new JsExpression('function (product) { return product.text; }'), | ||
132 | + ], | ||
133 | + ] | ||
134 | + ); | ||
135 | + ?> | ||
136 | + | ||
137 | + <?php | ||
138 | + echo $form->field($model, 'blogArticles') | ||
139 | + ->widget( | ||
140 | + Select2::className(), | ||
141 | + [ | ||
142 | + 'data' => $articles, | ||
143 | + 'options' => [ | ||
144 | + 'placeholder' => \Yii::t('blog', 'Select related articles'), | ||
145 | + 'multiple' => true, | ||
146 | + ], | ||
147 | + 'pluginOptions' => [ | ||
148 | + 'allowClear' => true, | ||
149 | + 'minimumInputLength' => 3, | ||
150 | + 'language' => [ | ||
151 | + 'errorLoading' => new JsExpression( | ||
152 | + "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }" | ||
153 | + ), | ||
154 | + ], | ||
155 | + 'ajax' => [ | ||
156 | + 'url' => yii\helpers\Url::to([ '/blog/blog-article/article-list' ]), | ||
157 | + 'dataType' => 'json', | ||
158 | + 'data' => new JsExpression( | ||
159 | + 'function(params) { return {q:params.term, id:' . $model->id . '}; }' | ||
160 | + ), | ||
161 | + ], | ||
162 | + 'templateResult' => new JsExpression('function(article) { return article.text; }'), | ||
163 | + 'templateSelection' => new JsExpression('function (article) { return article.text; }'), | ||
164 | + ], | ||
165 | + ] | ||
166 | + ); | ||
167 | + ?> | ||
168 | + | ||
169 | + <?= $form->field($model, 'sort') | ||
170 | + ->textInput() ?> | ||
171 | + | ||
172 | + <?= $form->field($model, 'status') | ||
173 | + ->checkbox() ?> | ||
174 | + | ||
175 | + <?= $form->field($model, 'author_id') | ||
176 | + ->textInput() ?> | ||
177 | + | ||
178 | + <div class="form-group"> | ||
179 | + <?= Html::submitButton( | ||
180 | + $model->isNewRecord ? 'Create' : 'Update', | ||
181 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
182 | + ) ?> | ||
183 | + </div> | ||
184 | + | ||
185 | + <?php ActiveForm::end(); ?> | ||
186 | + | ||
187 | +</div> |
common/modules/blog/views/blog-article/_form_language.php
0 → 100644
1 | +<?php | ||
2 | + use common\models\ArticleLang; | ||
3 | + use common\modules\language\models\Language; | ||
4 | + use mihaildev\ckeditor\CKEditor; | ||
5 | + use mihaildev\elfinder\ElFinder; | ||
6 | + use yii\web\View; | ||
7 | + use yii\widgets\ActiveForm; | ||
8 | + | ||
9 | + /** | ||
10 | + * @var ArticleLang $model_lang | ||
11 | + * @var Language $language | ||
12 | + * @var ActiveForm $form | ||
13 | + * @var View $this | ||
14 | + */ | ||
15 | +?> | ||
16 | +<?= $form->field($model_lang, '[' . $language->id . ']title') | ||
17 | + ->textInput([ 'maxlength' => true ]); ?> | ||
18 | + | ||
19 | +<?= $form->field($model_lang, '[' . $language->id . ']alias') | ||
20 | + ->textInput([ 'maxlength' => true ]); ?> | ||
21 | + | ||
22 | +<?= $form->field($model_lang, '[' . $language->id . ']body') | ||
23 | + ->widget( | ||
24 | + CKEditor::className(), | ||
25 | + [ | ||
26 | + 'editorOptions' => ElFinder::ckeditorOptions( | ||
27 | + 'elfinder', | ||
28 | + [ | ||
29 | + 'preset' => 'full', | ||
30 | + 'inline' => false, | ||
31 | + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() | ||
32 | + ->createUrl('file/uploader/images-upload'), | ||
33 | + ] | ||
34 | + ), | ||
35 | + ] | ||
36 | + ) ?> | ||
37 | + | ||
38 | +<?= $form->field($model_lang, '[' . $language->id . ']body_preview') | ||
39 | + ->textarea( | ||
40 | + [ | ||
41 | + 'rows' => '10', | ||
42 | + ] | ||
43 | + ) ?> | ||
44 | + | ||
45 | +<?= $form->field($model_lang, '[' . $language->id . ']meta_title') | ||
46 | + ->textInput([ 'maxlength' => true ]); ?> | ||
47 | + | ||
48 | +<?= $form->field($model_lang, '[' . $language->id . ']meta_description') | ||
49 | + ->textInput([ 'maxlength' => true ]); ?> | ||
50 | + | ||
51 | +<?= $form->field($model_lang, '[' . $language->id . ']seo_text') | ||
52 | + ->textInput([ 'maxlength' => true ]); ?> | ||
53 | + | ||
54 | +<?= $form->field($model_lang, '[' . $language->id . ']h1') | ||
55 | + ->textInput([ 'maxlength' => true ]); ?> |
1 | +<?php | ||
2 | + | ||
3 | + use yii\helpers\Html; | ||
4 | + use yii\widgets\ActiveForm; | ||
5 | + | ||
6 | + /* @var $this yii\web\View */ | ||
7 | + /* @var $model common\modules\blog\models\BlogArticleSearch */ | ||
8 | + /* @var $form yii\widgets\ActiveForm */ | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="blog-article-search"> | ||
12 | + | ||
13 | + <?php $form = ActiveForm::begin( | ||
14 | + [ | ||
15 | + 'action' => [ 'index' ], | ||
16 | + 'method' => 'get', | ||
17 | + ] | ||
18 | + ); ?> | ||
19 | + | ||
20 | + <?= $form->field($model, 'id') ?> | ||
21 | + | ||
22 | + <?= $form->field($model, 'image') ?> | ||
23 | + | ||
24 | + <?= $form->field($model, 'created_at') ?> | ||
25 | + | ||
26 | + <?= $form->field($model, 'updated_at') ?> | ||
27 | + | ||
28 | + <?= $form->field($model, 'deleted_at') ?> | ||
29 | + | ||
30 | + <?php // echo $form->field($model, 'sort') ?> | ||
31 | + | ||
32 | + <?php // echo $form->field($model, 'status')->checkbox() ?> | ||
33 | + | ||
34 | + <?php // echo $form->field($model, 'author_id') ?> | ||
35 | + | ||
36 | + <div class="form-group"> | ||
37 | + <?= Html::submitButton('Search', [ 'class' => 'btn btn-primary' ]) ?> | ||
38 | + <?= Html::resetButton('Reset', [ 'class' => 'btn btn-default' ]) ?> | ||
39 | + </div> | ||
40 | + | ||
41 | + <?php ActiveForm::end(); ?> | ||
42 | + | ||
43 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogArticle; | ||
4 | + use common\modules\blog\models\BlogArticleLang; | ||
5 | + use common\modules\blog\models\BlogCategory; | ||
6 | + use common\modules\blog\models\BlogTag; | ||
7 | + use yii\helpers\Html; | ||
8 | + use yii\web\View; | ||
9 | + | ||
10 | + /** | ||
11 | + * @var View $this | ||
12 | + * @var BlogArticle $model | ||
13 | + * @var BlogArticleLang[] $modelLangs | ||
14 | + * @var BlogCategory[] $categories | ||
15 | + * @var BlogTag[] $tags | ||
16 | + * @var array $products | ||
17 | + * @var array $articles | ||
18 | + */ | ||
19 | + | ||
20 | + $this->title = \Yii::t('blog', 'Create Blog Article'); | ||
21 | + $this->params[ 'breadcrumbs' ][] = [ | ||
22 | + 'label' => \Yii::t('blog', 'Blog Articles'), | ||
23 | + 'url' => [ 'index' ], | ||
24 | + ]; | ||
25 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
26 | +?> | ||
27 | +<div class="blog-article-create"> | ||
28 | + | ||
29 | + <h1><?= Html::encode($this->title) ?></h1> | ||
30 | + | ||
31 | + <?= $this->render( | ||
32 | + '_form', | ||
33 | + [ | ||
34 | + 'model' => $model, | ||
35 | + 'modelLangs' => $modelLangs, | ||
36 | + 'categories' => $categories, | ||
37 | + 'tags' => $tags, | ||
38 | + 'products' => $products, | ||
39 | + 'articles' => $articles, | ||
40 | + ] | ||
41 | + ) ?> | ||
42 | + | ||
43 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogArticle; | ||
4 | + use common\modules\blog\models\BlogArticleSearch; | ||
5 | + use yii\data\ActiveDataProvider; | ||
6 | + use yii\helpers\Html; | ||
7 | + use yii\grid\GridView; | ||
8 | + use yii\web\View; | ||
9 | + | ||
10 | + /** | ||
11 | + * @var View $this | ||
12 | + * @var BlogArticleSearch $searchModel | ||
13 | + * @var ActiveDataProvider $dataProvider | ||
14 | + */ | ||
15 | + | ||
16 | + $this->title = \Yii::t('blog', 'Blog Articles'); | ||
17 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
18 | +?> | ||
19 | +<div class="blog-article-index"> | ||
20 | + | ||
21 | + <h1><?= Html::encode($this->title) ?></h1> | ||
22 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | ||
23 | + | ||
24 | + <p> | ||
25 | + <?= Html::a(\Yii::t('blog', 'Create Blog Article'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> | ||
26 | + </p> | ||
27 | + <?= GridView::widget( | ||
28 | + [ | ||
29 | + 'dataProvider' => $dataProvider, | ||
30 | + 'filterModel' => $searchModel, | ||
31 | + 'columns' => [ | ||
32 | + 'id', | ||
33 | + [ | ||
34 | + 'attribute' => 'title', | ||
35 | + 'value' => 'lang.title', | ||
36 | + ], | ||
37 | + 'imageUrl:image', | ||
38 | + [ | ||
39 | + 'attribute' => 'status', | ||
40 | + 'value' => function($model) { | ||
41 | + /** | ||
42 | + * @var BlogArticle $model | ||
43 | + */ | ||
44 | + return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); | ||
45 | + }, | ||
46 | + 'filter' => [ | ||
47 | + 0 => \Yii::t('blog', 'Not active'), | ||
48 | + 1 => \Yii::t('blog', 'Active'), | ||
49 | + ], | ||
50 | + ], | ||
51 | + 'created_at:date', | ||
52 | + 'updated_at:date', | ||
53 | + [ 'class' => 'yii\grid\ActionColumn' ], | ||
54 | + ], | ||
55 | + ] | ||
56 | + ); ?> | ||
57 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogArticle; | ||
4 | + use common\modules\blog\models\BlogArticleLang; | ||
5 | + use common\modules\blog\models\BlogCategory; | ||
6 | + use common\modules\blog\models\BlogTag; | ||
7 | + use yii\helpers\Html; | ||
8 | + use yii\web\View; | ||
9 | + | ||
10 | + /** | ||
11 | + * @var View $this | ||
12 | + * @var BlogArticle $model | ||
13 | + * @var BlogArticleLang[] $modelLangs | ||
14 | + * @var BlogCategory[] $categories | ||
15 | + * @var BlogTag[] $tags | ||
16 | + * @var array $products | ||
17 | + * @var array $articles | ||
18 | + */ | ||
19 | + | ||
20 | + $this->title = \Yii::t('blog', 'Update Blog Article: ') . $model->lang->title; | ||
21 | + $this->params[ 'breadcrumbs' ][] = [ | ||
22 | + 'label' => \Yii::t('blog', 'Blog Articles'), | ||
23 | + 'url' => [ 'index' ], | ||
24 | + ]; | ||
25 | + $this->params[ 'breadcrumbs' ][] = [ | ||
26 | + 'label' => $model->lang->title, | ||
27 | + 'url' => [ | ||
28 | + 'view', | ||
29 | + 'id' => $model->id, | ||
30 | + ], | ||
31 | + ]; | ||
32 | + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update'); | ||
33 | +?> | ||
34 | +<div class="blog-article-update"> | ||
35 | + | ||
36 | + <h1><?= Html::encode($this->title) ?></h1> | ||
37 | + | ||
38 | + <?= $this->render( | ||
39 | + '_form', | ||
40 | + [ | ||
41 | + 'model' => $model, | ||
42 | + 'modelLangs' => $modelLangs, | ||
43 | + 'categories' => $categories, | ||
44 | + 'tags' => $tags, | ||
45 | + 'products' => $products, | ||
46 | + 'articles' => $articles, | ||
47 | + ] | ||
48 | + ) ?> | ||
49 | + | ||
50 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogArticle; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\web\View; | ||
6 | + use yii\widgets\DetailView; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogArticle $model | ||
11 | + */ | ||
12 | + | ||
13 | + $this->title = $model->lang->title; | ||
14 | + $this->params[ 'breadcrumbs' ][] = [ | ||
15 | + 'label' => \Yii::t('blog', 'Blog Articles'), | ||
16 | + 'url' => [ 'index' ], | ||
17 | + ]; | ||
18 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
19 | +?> | ||
20 | +<div class="blog-article-view"> | ||
21 | + | ||
22 | + <h1><?= Html::encode($this->title) ?></h1> | ||
23 | + | ||
24 | + <p> | ||
25 | + <?= Html::a( | ||
26 | + 'Update', | ||
27 | + [ | ||
28 | + 'update', | ||
29 | + 'id' => $model->id, | ||
30 | + ], | ||
31 | + [ 'class' => 'btn btn-primary' ] | ||
32 | + ) ?> | ||
33 | + <?= Html::a( | ||
34 | + 'Delete', | ||
35 | + [ | ||
36 | + 'delete', | ||
37 | + 'id' => $model->id, | ||
38 | + ], | ||
39 | + [ | ||
40 | + 'class' => 'btn btn-danger', | ||
41 | + 'data' => [ | ||
42 | + 'confirm' => 'Are you sure you want to delete this item?', | ||
43 | + 'method' => 'post', | ||
44 | + ], | ||
45 | + ] | ||
46 | + ) ?> | ||
47 | + </p> | ||
48 | + | ||
49 | + <?= DetailView::widget( | ||
50 | + [ | ||
51 | + 'model' => $model, | ||
52 | + 'attributes' => [ | ||
53 | + 'id', | ||
54 | + 'imageUrl:image', | ||
55 | + 'created_at:date', | ||
56 | + 'updated_at:date', | ||
57 | + [ | ||
58 | + 'attribute' => 'status', | ||
59 | + 'value' => ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'), | ||
60 | + ], | ||
61 | + 'lang.alias', | ||
62 | + 'lang.body:html', | ||
63 | + ], | ||
64 | + ] | ||
65 | + ) ?> | ||
66 | + | ||
67 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogCategory; | ||
4 | + use common\modules\blog\models\BlogCategoryLang; | ||
5 | + use kartik\select2\Select2; | ||
6 | + use yii\helpers\Html; | ||
7 | + use yii\web\View; | ||
8 | + use yii\widgets\ActiveForm; | ||
9 | + use common\modules\language\widgets\LanguageForm; | ||
10 | + | ||
11 | + /** | ||
12 | + * @var View $this | ||
13 | + * @var BlogCategory $model | ||
14 | + * @var ActiveForm $form | ||
15 | + * @var BlogCategoryLang[] $modelLangs | ||
16 | + * @var array $parentCategories | ||
17 | + */ | ||
18 | +?> | ||
19 | + | ||
20 | +<div class="blog-category-form"> | ||
21 | + | ||
22 | + <?php $form = ActiveForm::begin( | ||
23 | + [ | ||
24 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | ||
25 | + | ||
26 | + ] | ||
27 | + ); ?> | ||
28 | + | ||
29 | + <?php | ||
30 | + echo LanguageForm::widget( | ||
31 | + [ | ||
32 | + 'modelLangs' => $modelLangs, | ||
33 | + 'formView' => '@common/modules/blog/views/blog-category/_form_language', | ||
34 | + 'form' => $form, | ||
35 | + ] | ||
36 | + ); | ||
37 | + ?> | ||
38 | + | ||
39 | + <?= $form->field($model, 'image') | ||
40 | + ->widget( | ||
41 | + \kartik\file\FileInput::className(), | ||
42 | + [ | ||
43 | + 'language' => 'ru', | ||
44 | + 'options' => [ | ||
45 | + 'accept' => 'image/*', | ||
46 | + 'multiple' => false, | ||
47 | + ], | ||
48 | + 'pluginOptions' => [ | ||
49 | + 'allowedFileExtensions' => [ | ||
50 | + 'jpg', | ||
51 | + 'gif', | ||
52 | + 'png', | ||
53 | + ], | ||
54 | + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage( | ||
55 | + $model->imageUrl, | ||
56 | + 'list' | ||
57 | + ) : '', | ||
58 | + 'overwriteInitial' => true, | ||
59 | + 'showRemove' => false, | ||
60 | + 'showUpload' => false, | ||
61 | + 'previewFileType' => 'image', | ||
62 | + ], | ||
63 | + ] | ||
64 | + ); ?> | ||
65 | + | ||
66 | + <?= $form->field($model, 'sort') | ||
67 | + ->textInput() ?> | ||
68 | + | ||
69 | + <?php echo $form->field($model, 'parent_id') | ||
70 | + ->widget( | ||
71 | + Select2::className(), | ||
72 | + [ | ||
73 | + 'data' => $parentCategories, | ||
74 | + 'options' => [ 'placeholder' => \Yii::t('blog', 'Has no parent rubric') ], | ||
75 | + 'pluginOptions' => [ | ||
76 | + 'allowClear' => true, | ||
77 | + ], | ||
78 | + ] | ||
79 | + ); | ||
80 | + ?> | ||
81 | + | ||
82 | + <?= $form->field($model, 'status') | ||
83 | + ->checkbox() ?> | ||
84 | + | ||
85 | + <div class="form-group"> | ||
86 | + <?= Html::submitButton( | ||
87 | + $model->isNewRecord ? 'Create' : 'Update', | ||
88 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
89 | + ) ?> | ||
90 | + </div> | ||
91 | + | ||
92 | + <?php ActiveForm::end(); ?> | ||
93 | + | ||
94 | +</div> |
common/modules/blog/views/blog-category/_form_language.php
0 → 100644
1 | +<?php | ||
2 | + use common\models\ArticleLang; | ||
3 | + use common\modules\language\models\Language; | ||
4 | + use yii\web\View; | ||
5 | + use yii\widgets\ActiveForm; | ||
6 | + | ||
7 | + /** | ||
8 | + * @var ArticleLang $model_lang | ||
9 | + * @var Language $language | ||
10 | + * @var ActiveForm $form | ||
11 | + * @var View $this | ||
12 | + */ | ||
13 | +?> | ||
14 | +<?= $form->field($model_lang, '[' . $language->id . ']title') | ||
15 | + ->textInput([ 'maxlength' => true ]); ?> | ||
16 | + | ||
17 | +<?= $form->field($model_lang, '[' . $language->id . ']alias') | ||
18 | + ->textInput([ 'maxlength' => true ]); ?> | ||
19 | + | ||
20 | +<?= $form->field($model_lang, '[' . $language->id . ']description') | ||
21 | + ->textarea( | ||
22 | + [ | ||
23 | + 'rows' => '10', | ||
24 | + ] | ||
25 | + ) ?> | ||
26 | + | ||
27 | +<?= $form->field($model_lang, '[' . $language->id . ']meta_title') | ||
28 | + ->textInput([ 'maxlength' => true ]); ?> | ||
29 | + | ||
30 | +<?= $form->field($model_lang, '[' . $language->id . ']meta_description') | ||
31 | + ->textInput([ 'maxlength' => true ]); ?> | ||
32 | + | ||
33 | +<?= $form->field($model_lang, '[' . $language->id . ']seo_text') | ||
34 | + ->textInput([ 'maxlength' => true ]); ?> | ||
35 | + | ||
36 | +<?= $form->field($model_lang, '[' . $language->id . ']h1') | ||
37 | + ->textInput([ 'maxlength' => true ]); ?> |
common/modules/blog/views/blog-category/_search.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\widgets\ActiveForm; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\modules\blog\models\BlogCategorySearch */ | ||
8 | +/* @var $form yii\widgets\ActiveForm */ | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="blog-category-search"> | ||
12 | + | ||
13 | + <?php $form = ActiveForm::begin([ | ||
14 | + 'action' => ['index'], | ||
15 | + 'method' => 'get', | ||
16 | + ]); ?> | ||
17 | + | ||
18 | + <?= $form->field($model, 'id') ?> | ||
19 | + | ||
20 | + <?= $form->field($model, 'sort') ?> | ||
21 | + | ||
22 | + <?= $form->field($model, 'image') ?> | ||
23 | + | ||
24 | + <?= $form->field($model, 'parent_id') ?> | ||
25 | + | ||
26 | + <?= $form->field($model, 'status')->checkbox() ?> | ||
27 | + | ||
28 | + <div class="form-group"> | ||
29 | + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | ||
30 | + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | ||
31 | + </div> | ||
32 | + | ||
33 | + <?php ActiveForm::end(); ?> | ||
34 | + | ||
35 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogArticleLang; | ||
4 | + use common\modules\blog\models\BlogCategory; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogCategory $model | ||
11 | + * @var BlogArticleLang[] $modelLangs | ||
12 | + * @var array $parentCategories | ||
13 | + */ | ||
14 | + | ||
15 | + $this->title = \Yii::t('blog', 'Create Blog Category'); | ||
16 | + $this->params[ 'breadcrumbs' ][] = [ | ||
17 | + 'label' => \Yii::t('blog', 'Blog Categories'), | ||
18 | + 'url' => [ 'index' ], | ||
19 | + ]; | ||
20 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
21 | +?> | ||
22 | +<div class="blog-category-create"> | ||
23 | + | ||
24 | + <h1><?= Html::encode($this->title) ?></h1> | ||
25 | + | ||
26 | + <?= $this->render( | ||
27 | + '_form', | ||
28 | + [ | ||
29 | + 'model' => $model, | ||
30 | + 'modelLangs' => $modelLangs, | ||
31 | + 'parentCategories' => $parentCategories, | ||
32 | + ] | ||
33 | + ) ?> | ||
34 | + | ||
35 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogCategory; | ||
4 | + use common\modules\blog\models\BlogCategorySearch; | ||
5 | + use yii\data\ActiveDataProvider; | ||
6 | + use yii\helpers\Html; | ||
7 | + use yii\grid\GridView; | ||
8 | + use yii\web\View; | ||
9 | + | ||
10 | + /** | ||
11 | + * @var View $this | ||
12 | + * @var BlogCategorySearch $searchModel | ||
13 | + * @var ActiveDataProvider $dataProvider | ||
14 | + */ | ||
15 | + | ||
16 | + $this->title = \Yii::t('blog', 'Blog Categories'); | ||
17 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
18 | +?> | ||
19 | +<div class="blog-category-index"> | ||
20 | + | ||
21 | + <h1><?= Html::encode($this->title) ?></h1> | ||
22 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | ||
23 | + | ||
24 | + <p> | ||
25 | + <?= Html::a(\Yii::t('blog', 'Create Blog Category'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> | ||
26 | + </p> | ||
27 | + <?= GridView::widget( | ||
28 | + [ | ||
29 | + 'dataProvider' => $dataProvider, | ||
30 | + 'filterModel' => $searchModel, | ||
31 | + 'columns' => [ | ||
32 | + 'id', | ||
33 | + [ | ||
34 | + 'attribute' => 'title', | ||
35 | + 'value' => 'lang.title', | ||
36 | + ], | ||
37 | + 'imageUrl:image', | ||
38 | + [ | ||
39 | + 'label' => \Yii::t('blog', 'Parent category'), | ||
40 | + 'value' => function($model) { | ||
41 | + /** | ||
42 | + * @var BlogCategory $model | ||
43 | + */ | ||
44 | + if (!empty( $model->parent )) { | ||
45 | + return $model->parent->lang->title; | ||
46 | + } else { | ||
47 | + return false; | ||
48 | + }; | ||
49 | + }, | ||
50 | + ], | ||
51 | + [ | ||
52 | + 'attribute' => 'status', | ||
53 | + 'value' => function($model) { | ||
54 | + /** | ||
55 | + * @var BlogCategory $model | ||
56 | + */ | ||
57 | + return ( !$model->status ) ? \Yii::t('blog', 'Not active') : \Yii::t('blog', 'Active'); | ||
58 | + }, | ||
59 | + 'filter' => [ | ||
60 | + 0 => \Yii::t('blog', 'Not active'), | ||
61 | + 1 => \Yii::t('blog', 'Active'), | ||
62 | + ], | ||
63 | + ], | ||
64 | + [ 'class' => 'yii\grid\ActionColumn' ], | ||
65 | + ], | ||
66 | + ] | ||
67 | + ); ?> | ||
68 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogCategory; | ||
4 | + use common\modules\blog\models\BlogCategoryLang; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogCategory $model | ||
11 | + * @var BlogCategoryLang $modelLangs | ||
12 | + * @var array $parentCategories | ||
13 | + */ | ||
14 | + | ||
15 | + $this->title = \Yii::t('blog', 'Update Blog Category: ') . $model->lang->title; | ||
16 | + $this->params[ 'breadcrumbs' ][] = [ | ||
17 | + 'label' => \Yii::t('blog', 'Blog Categories'), | ||
18 | + 'url' => [ 'index' ], | ||
19 | + ]; | ||
20 | + $this->params[ 'breadcrumbs' ][] = [ | ||
21 | + 'label' => $model->lang->title, | ||
22 | + 'url' => [ | ||
23 | + 'view', | ||
24 | + 'id' => $model->id, | ||
25 | + ], | ||
26 | + ]; | ||
27 | + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update'); | ||
28 | +?> | ||
29 | +<div class="blog-category-update"> | ||
30 | + | ||
31 | + <h1><?= Html::encode($this->title) ?></h1> | ||
32 | + | ||
33 | + <?= $this->render( | ||
34 | + '_form', | ||
35 | + [ | ||
36 | + 'model' => $model, | ||
37 | + 'modelLangs' => $modelLangs, | ||
38 | + 'parentCategories' => $parentCategories, | ||
39 | + ] | ||
40 | + ) ?> | ||
41 | + | ||
42 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogCategory; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\web\View; | ||
6 | + use yii\widgets\DetailView; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogCategory $model | ||
11 | + */ | ||
12 | + | ||
13 | + $this->title = $model->lang->title; | ||
14 | + $this->params[ 'breadcrumbs' ][] = [ | ||
15 | + 'label' => \Yii::t('blog', 'Blog Categories'), | ||
16 | + 'url' => [ 'index' ], | ||
17 | + ]; | ||
18 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
19 | +?> | ||
20 | +<div class="blog-category-view"> | ||
21 | + | ||
22 | + <h1><?= Html::encode($this->title) ?></h1> | ||
23 | + | ||
24 | + <p> | ||
25 | + <?= Html::a( | ||
26 | + 'Update', | ||
27 | + [ | ||
28 | + 'update', | ||
29 | + 'id' => $model->id, | ||
30 | + ], | ||
31 | + [ 'class' => 'btn btn-primary' ] | ||
32 | + ) ?> | ||
33 | + <?= Html::a( | ||
34 | + 'Delete', | ||
35 | + [ | ||
36 | + 'delete', | ||
37 | + 'id' => $model->id, | ||
38 | + ], | ||
39 | + [ | ||
40 | + 'class' => 'btn btn-danger', | ||
41 | + 'data' => [ | ||
42 | + 'confirm' => 'Are you sure you want to delete this item?', | ||
43 | + 'method' => 'post', | ||
44 | + ], | ||
45 | + ] | ||
46 | + ) ?> | ||
47 | + </p> | ||
48 | + | ||
49 | + <?= DetailView::widget( | ||
50 | + [ | ||
51 | + 'model' => $model, | ||
52 | + 'attributes' => [ | ||
53 | + 'id', | ||
54 | + 'sort', | ||
55 | + 'imageUrl:image', | ||
56 | + [ | ||
57 | + 'attribute' => 'parent_id', | ||
58 | + 'value' => ( !empty( $model->parent ) ) ? $model->parent->lang->title : '', | ||
59 | + ], | ||
60 | + 'lang.alias', | ||
61 | + 'lang.description:text', | ||
62 | + [ | ||
63 | + 'attribute' => 'status', | ||
64 | + 'value' => ( $model->status ) ? \Yii::t('blog', 'Active') : \Yii::t('blog', 'Not active'), | ||
65 | + ], | ||
66 | + ], | ||
67 | + ] | ||
68 | + ) ?> | ||
69 | + | ||
70 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogTag; | ||
4 | + use common\modules\blog\models\BlogTagLang; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + use yii\widgets\ActiveForm; | ||
8 | + use common\modules\language\widgets\LanguageForm; | ||
9 | + | ||
10 | + /** | ||
11 | + * @var View $this | ||
12 | + * @var BlogTag $model | ||
13 | + * @var ActiveForm $form | ||
14 | + * @var BlogTagLang[] $modelLangs | ||
15 | + */ | ||
16 | +?> | ||
17 | + | ||
18 | +<div class="blog-tag-form"> | ||
19 | + | ||
20 | + <?php $form = ActiveForm::begin(); ?> | ||
21 | + | ||
22 | + <?php | ||
23 | + echo LanguageForm::widget( | ||
24 | + [ | ||
25 | + 'modelLangs' => $modelLangs, | ||
26 | + 'formView' => '@common/modules/blog/views/blog-tag/_form_language', | ||
27 | + 'form' => $form, | ||
28 | + ] | ||
29 | + ); | ||
30 | + ?> | ||
31 | + | ||
32 | + <div class="form-group"> | ||
33 | + <?= Html::submitButton( | ||
34 | + $model->isNewRecord ? 'Create' : 'Update', | ||
35 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
36 | + ) ?> | ||
37 | + </div> | ||
38 | + | ||
39 | + <?php ActiveForm::end(); ?> | ||
40 | + | ||
41 | +</div> |
common/modules/blog/views/blog-tag/_form_language.php
0 → 100644
1 | +<?php | ||
2 | + use common\models\ArticleLang; | ||
3 | + use common\modules\language\models\Language; | ||
4 | + use yii\web\View; | ||
5 | + use yii\widgets\ActiveForm; | ||
6 | + | ||
7 | + /** | ||
8 | + * @var ArticleLang $model_lang | ||
9 | + * @var Language $language | ||
10 | + * @var ActiveForm $form | ||
11 | + * @var View $this | ||
12 | + */ | ||
13 | +?> | ||
14 | +<?= $form->field($model_lang, '[' . $language->id . ']label') | ||
15 | + ->textInput([ 'maxlength' => true ]); ?> |
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\widgets\ActiveForm; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\modules\blog\models\BlogTagSearch */ | ||
8 | +/* @var $form yii\widgets\ActiveForm */ | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="blog-tag-search"> | ||
12 | + | ||
13 | + <?php $form = ActiveForm::begin([ | ||
14 | + 'action' => ['index'], | ||
15 | + 'method' => 'get', | ||
16 | + ]); ?> | ||
17 | + | ||
18 | + <?= $form->field($model, 'id') ?> | ||
19 | + | ||
20 | + <div class="form-group"> | ||
21 | + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | ||
22 | + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | ||
23 | + </div> | ||
24 | + | ||
25 | + <?php ActiveForm::end(); ?> | ||
26 | + | ||
27 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogTag; | ||
4 | + use common\modules\blog\models\BlogTagLang; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogTagLang[] $modelLangs | ||
11 | + * @var BlogTag $model | ||
12 | + */ | ||
13 | + | ||
14 | + $this->title = \Yii::t('blog', 'Create Blog Tag'); | ||
15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
16 | + 'label' => \Yii::t('blog', 'Blog Tags'), | ||
17 | + 'url' => [ 'index' ], | ||
18 | + ]; | ||
19 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
20 | +?> | ||
21 | +<div class="blog-tag-create"> | ||
22 | + | ||
23 | + <h1><?= Html::encode($this->title) ?></h1> | ||
24 | + | ||
25 | + <?= $this->render( | ||
26 | + '_form', | ||
27 | + [ | ||
28 | + 'model' => $model, | ||
29 | + 'modelLangs' => $modelLangs, | ||
30 | + ] | ||
31 | + ) ?> | ||
32 | + | ||
33 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogTagSearch; | ||
4 | + use yii\data\ActiveDataProvider; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\grid\GridView; | ||
7 | + use yii\web\View; | ||
8 | + | ||
9 | + /** | ||
10 | + * @var View $this | ||
11 | + * @var BlogTagSearch $searchModel | ||
12 | + * @var ActiveDataProvider $dataProvider | ||
13 | + */ | ||
14 | + | ||
15 | + $this->title = \Yii::t('blog', 'Blog Tags'); | ||
16 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
17 | +?> | ||
18 | +<div class="blog-tag-index"> | ||
19 | + | ||
20 | + <h1><?= Html::encode($this->title) ?></h1> | ||
21 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | ||
22 | + | ||
23 | + <p> | ||
24 | + <?= Html::a(\Yii::t('blog', 'Create Blog Tag'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> | ||
25 | + </p> | ||
26 | + <?= GridView::widget( | ||
27 | + [ | ||
28 | + 'dataProvider' => $dataProvider, | ||
29 | + 'filterModel' => $searchModel, | ||
30 | + 'columns' => [ | ||
31 | + 'id', | ||
32 | + [ | ||
33 | + 'attribute' => 'label', | ||
34 | + 'value' => 'lang.label', | ||
35 | + ], | ||
36 | + [ | ||
37 | + 'class' => 'yii\grid\ActionColumn', | ||
38 | + ], | ||
39 | + ], | ||
40 | + ] | ||
41 | + ); ?> | ||
42 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogTag; | ||
4 | + use common\modules\blog\models\BlogTagLang; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogTagLang[] $modelLangs | ||
11 | + * @var BlogTag $model | ||
12 | + */ | ||
13 | + | ||
14 | + $this->title = \Yii::t('blog', 'Update Blog Tag: ') . $model->lang->label; | ||
15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
16 | + 'label' => \Yii::t('blog', 'Blog Tags'), | ||
17 | + 'url' => [ 'index' ], | ||
18 | + ]; | ||
19 | + $this->params[ 'breadcrumbs' ][] = [ | ||
20 | + 'label' => $model->lang->label, | ||
21 | + 'url' => [ | ||
22 | + 'view', | ||
23 | + 'id' => $model->id, | ||
24 | + ], | ||
25 | + ]; | ||
26 | + $this->params[ 'breadcrumbs' ][] = \Yii::t('blog', 'Update'); | ||
27 | +?> | ||
28 | +<div class="blog-tag-update"> | ||
29 | + | ||
30 | + <h1><?= Html::encode($this->title) ?></h1> | ||
31 | + | ||
32 | + <?= $this->render( | ||
33 | + '_form', | ||
34 | + [ | ||
35 | + 'model' => $model, | ||
36 | + 'modelLangs' => $modelLangs, | ||
37 | + ] | ||
38 | + ) ?> | ||
39 | + | ||
40 | +</div> |
1 | +<?php | ||
2 | + | ||
3 | + use common\modules\blog\models\BlogTag; | ||
4 | + use yii\helpers\Html; | ||
5 | + use yii\web\View; | ||
6 | + use yii\widgets\DetailView; | ||
7 | + | ||
8 | + /** | ||
9 | + * @var View $this | ||
10 | + * @var BlogTag $model | ||
11 | + */ | ||
12 | + | ||
13 | + $this->title = $model->lang->label; | ||
14 | + $this->params[ 'breadcrumbs' ][] = [ | ||
15 | + 'label' => \Yii::t('blog', 'Blog Tags'), | ||
16 | + 'url' => [ 'index' ], | ||
17 | + ]; | ||
18 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
19 | +?> | ||
20 | +<div class="blog-tag-view"> | ||
21 | + | ||
22 | + <h1><?= Html::encode($this->title) ?></h1> | ||
23 | + | ||
24 | + <p> | ||
25 | + <?= Html::a( | ||
26 | + 'Update', | ||
27 | + [ | ||
28 | + 'update', | ||
29 | + 'id' => $model->id, | ||
30 | + ], | ||
31 | + [ 'class' => 'btn btn-primary' ] | ||
32 | + ) ?> | ||
33 | + <?= Html::a( | ||
34 | + 'Delete', | ||
35 | + [ | ||
36 | + 'delete', | ||
37 | + 'id' => $model->id, | ||
38 | + ], | ||
39 | + [ | ||
40 | + 'class' => 'btn btn-danger', | ||
41 | + 'data' => [ | ||
42 | + 'confirm' => 'Are you sure you want to delete this item?', | ||
43 | + 'method' => 'post', | ||
44 | + ], | ||
45 | + ] | ||
46 | + ) ?> | ||
47 | + </p> | ||
48 | + | ||
49 | + <?= DetailView::widget( | ||
50 | + [ | ||
51 | + 'model' => $model, | ||
52 | + 'attributes' => [ | ||
53 | + 'id', | ||
54 | + 'lang.label', | ||
55 | + ], | ||
56 | + ] | ||
57 | + ) ?> | ||
58 | + | ||
59 | +</div> |
1 | +<div class="blog-default-index"> | ||
2 | + <h1><?= $this->context->action->uniqueId ?></h1> | ||
3 | + <p> | ||
4 | + This is the view content for action "<?= $this->context->action->id ?>". | ||
5 | + The action belongs to the controller "<?= get_class($this->context) ?>" | ||
6 | + in the "<?= $this->context->module->id ?>" module. | ||
7 | + </p> | ||
8 | + <p> | ||
9 | + You may customize this page by editing the following file:<br> | ||
10 | + <code><?= __FILE__ ?></code> | ||
11 | + </p> | ||
12 | +</div> |
1 | +<?php | ||
2 | + return [ | ||
3 | + 'Select category' => 'Выберите категорию ...', | ||
4 | + 'Select tag' => 'Выберите тэг ...', | ||
5 | + 'Has no parent rubric' => 'Без категории', | ||
6 | + 'Waiting for results' => 'Загрузка ...', | ||
7 | + 'Select related products' => 'Выберите сопутствующие товары', | ||
8 | + 'Select related articles' => 'Выберите статьи', | ||
9 | + 'Blog Articles' => 'Статьи блога', | ||
10 | + 'Create Blog Article' => 'Создать статью', | ||
11 | + 'Update Blog Article: ' => 'Обновить статью: ', | ||
12 | + 'Not active' => 'Не активна', | ||
13 | + 'Active' => 'Активна', | ||
14 | + 'Are you sure you want to delete this item?' => 'Вы точно хотите это удалить ?', | ||
15 | + 'Update' => 'Обновить', | ||
16 | + 'Blog Categories' => 'Рубрики', | ||
17 | + 'Create Blog Category' => 'Создать рубрику', | ||
18 | + 'Update Blog Category: ' => 'Обновить рубрику: ', | ||
19 | + 'Blog Tags' => 'Тэги', | ||
20 | + 'Create Blog Tag' => 'Создать тэг', | ||
21 | + 'Update Blog Tag: ' => 'Обновить тэг: ', | ||
22 | + ]; | ||
0 | \ No newline at end of file | 23 | \ No newline at end of file |
console/migrations/blog/m161101_142334_blog_article.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_142334_blog_article extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create main table with blog's articles | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_article', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'image' => $this->string(255), | ||
17 | + 'created_at' => $this->integer(), | ||
18 | + 'updated_at' => $this->integer(), | ||
19 | + 'deleted_at' => $this->integer(), | ||
20 | + 'sort' => $this->integer(), | ||
21 | + 'status' => $this->boolean(), | ||
22 | + 'author_id' => $this->integer(), | ||
23 | + ] | ||
24 | + ); | ||
25 | + } | ||
26 | + | ||
27 | + public function down() | ||
28 | + { | ||
29 | + $this->dropTable('blog_article'); | ||
30 | + } | ||
31 | +} |
console/migrations/blog/m161101_142752_blog_article_lang.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_142752_blog_article_lang extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create table with language fields of blog articles | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_article_lang', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_article_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'language_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + 'title' => $this->string(255), | ||
21 | + 'body' => $this->text(), | ||
22 | + 'body_preview' => $this->text(), | ||
23 | + 'alias' => $this->string(255), | ||
24 | + 'meta_title' => $this->string(255), | ||
25 | + 'meta_description' => $this->string(255), | ||
26 | + 'h1' => $this->string(255), | ||
27 | + 'seo_text' => $this->string(255), | ||
28 | + ] | ||
29 | + ); | ||
30 | + | ||
31 | + /** | ||
32 | + * Creating indexes for unique fields (field pairs) | ||
33 | + */ | ||
34 | + $this->createIndex( | ||
35 | + 'blog_article_lang_uk', | ||
36 | + 'blog_article_lang', | ||
37 | + [ | ||
38 | + 'blog_article_id', | ||
39 | + 'language_id', | ||
40 | + ], | ||
41 | + true | ||
42 | + ); | ||
43 | + | ||
44 | + $this->createIndex( | ||
45 | + 'blog_article_alias_uk', | ||
46 | + 'blog_article_lang', | ||
47 | + 'alias', | ||
48 | + true | ||
49 | + ); | ||
50 | + | ||
51 | + /** | ||
52 | + * Add foreign keys in blog_articles and language tables | ||
53 | + */ | ||
54 | + $this->addForeignKey( | ||
55 | + 'blog_article_fk', | ||
56 | + 'blog_article_lang', | ||
57 | + 'blog_article_id', | ||
58 | + 'blog_article', | ||
59 | + 'id', | ||
60 | + 'CASCADE', | ||
61 | + 'CASCADE' | ||
62 | + ); | ||
63 | + | ||
64 | + $this->addForeignKey( | ||
65 | + 'blog_article_lang_fk', | ||
66 | + 'blog_article_lang', | ||
67 | + 'language_id', | ||
68 | + 'language', | ||
69 | + 'id', | ||
70 | + 'RESTRICT', | ||
71 | + 'CASCADE' | ||
72 | + ); | ||
73 | + } | ||
74 | + | ||
75 | + public function down() | ||
76 | + { | ||
77 | + $this->dropForeignKey('blog_article_lang_fk', 'blog_article_lang'); | ||
78 | + $this->dropForeignKey('blog_article_fk', 'blog_article_lang'); | ||
79 | + $this->dropIndex('blog_article_alias_uk', 'blog_article_lang'); | ||
80 | + $this->dropIndex('blog_article_lang_uk', 'blog_article_lang'); | ||
81 | + $this->dropTable('blog_article_lang'); | ||
82 | + } | ||
83 | +} |
console/migrations/blog/m161101_143033_blog_category.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_143033_blog_category extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create table for blog's categories | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_category', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'sort' => $this->integer(), | ||
17 | + 'image' => $this->string(255), | ||
18 | + 'parent_id' => $this->integer() | ||
19 | + ->defaultValue(0), | ||
20 | + 'status' => $this->boolean(), | ||
21 | + ] | ||
22 | + ); | ||
23 | + } | ||
24 | + | ||
25 | + public function down() | ||
26 | + { | ||
27 | + $this->dropTable('blog_category'); | ||
28 | + } | ||
29 | +} |
console/migrations/blog/m161101_143259_blog_category_lang.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_143259_blog_category_lang extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Table for category languages | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_category_lang', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_category_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'language_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + 'title' => $this->string(255), | ||
21 | + 'alias' => $this->string(255), | ||
22 | + 'description' => $this->text(), | ||
23 | + 'meta_title' => $this->string(255), | ||
24 | + 'meta_description' => $this->string(255), | ||
25 | + 'h1' => $this->string(255), | ||
26 | + 'seo_text' => $this->string(255), | ||
27 | + ] | ||
28 | + ); | ||
29 | + | ||
30 | + /** | ||
31 | + * Create unique indexes for language and alias | ||
32 | + */ | ||
33 | + $this->createIndex( | ||
34 | + 'blog_category_lang_uk', | ||
35 | + 'blog_category_lang', | ||
36 | + [ | ||
37 | + 'blog_category_id', | ||
38 | + 'language_id', | ||
39 | + ], | ||
40 | + true | ||
41 | + ); | ||
42 | + | ||
43 | + $this->createIndex( | ||
44 | + 'blog_category_alias_uk', | ||
45 | + 'blog_category_lang', | ||
46 | + 'alias', | ||
47 | + true | ||
48 | + ); | ||
49 | + | ||
50 | + /** | ||
51 | + * Add foreign keys for language tables | ||
52 | + */ | ||
53 | + $this->addForeignKey( | ||
54 | + 'blog_category_fk', | ||
55 | + 'blog_category_lang', | ||
56 | + 'blog_category_id', | ||
57 | + 'blog_category', | ||
58 | + 'id', | ||
59 | + 'CASCADE', | ||
60 | + 'CASCADE' | ||
61 | + ); | ||
62 | + | ||
63 | + $this->addForeignKey( | ||
64 | + 'blog_category_lang_fk', | ||
65 | + 'blog_category_lang', | ||
66 | + 'language_id', | ||
67 | + 'language', | ||
68 | + 'id', | ||
69 | + 'RESTRICT', | ||
70 | + 'CASCADE' | ||
71 | + ); | ||
72 | + } | ||
73 | + | ||
74 | + public function down() | ||
75 | + { | ||
76 | + $this->dropForeignKey('blog_category_lang_fk', 'blog_category_lang'); | ||
77 | + $this->dropForeignKey('blog_category_fk', 'blog_category_lang'); | ||
78 | + $this->dropIndex('blog_category_alias_uk', 'blog_category_lang'); | ||
79 | + $this->dropIndex('blog_category_lang_uk', 'blog_category_lang'); | ||
80 | + $this->dropTable('blog_category_lang'); | ||
81 | + } | ||
82 | +} |
console/migrations/blog/m161101_143541_blog_article_to_category.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_143541_blog_article_to_category extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create junction table to connect articles with categories | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_article_to_category', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_article_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'blog_category_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + ] | ||
21 | + ); | ||
22 | + | ||
23 | + /** | ||
24 | + * Add foreign keys and indexes for junction table | ||
25 | + */ | ||
26 | + $this->createIndex( | ||
27 | + 'blog_article_to_category_uk', | ||
28 | + 'blog_article_to_category', | ||
29 | + [ | ||
30 | + 'blog_article_id', | ||
31 | + 'blog_category_id', | ||
32 | + ], | ||
33 | + true | ||
34 | + ); | ||
35 | + | ||
36 | + $this->addForeignKey( | ||
37 | + 'blog_article_to_category_art_fk', | ||
38 | + 'blog_article_to_category', | ||
39 | + 'blog_article_id', | ||
40 | + 'blog_article', | ||
41 | + 'id', | ||
42 | + 'CASCADE', | ||
43 | + 'CASCADE' | ||
44 | + ); | ||
45 | + | ||
46 | + $this->addForeignKey( | ||
47 | + 'blog_article_to_category_cat_fk', | ||
48 | + 'blog_article_to_category', | ||
49 | + 'blog_category_id', | ||
50 | + 'blog_category', | ||
51 | + 'id', | ||
52 | + 'CASCADE', | ||
53 | + 'CASCADE' | ||
54 | + ); | ||
55 | + } | ||
56 | + | ||
57 | + public function down() | ||
58 | + { | ||
59 | + $this->dropForeignKey('blog_article_to_category_cat_fk', 'blog_article_to_category'); | ||
60 | + $this->dropForeignKey('blog_article_to_category_art_fk', 'blog_article_to_category'); | ||
61 | + $this->dropIndex('blog_article_to_category_uk', 'blog_article_to_category'); | ||
62 | + $this->dropTable('blog_article_to_category'); | ||
63 | + } | ||
64 | +} |
console/migrations/blog/m161101_143734_blog_tag.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_143734_blog_tag extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create table for tags | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_tag', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + ] | ||
17 | + ); | ||
18 | + } | ||
19 | + | ||
20 | + public function down() | ||
21 | + { | ||
22 | + $this->dropTable('blog_tag'); | ||
23 | + } | ||
24 | +} |
console/migrations/blog/m161101_143939_blog_tag_lang.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_143939_blog_tag_lang extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Tags can be in different languages | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_tag_lang', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_tag_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'language_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + 'label' => $this->string(255), | ||
21 | + ] | ||
22 | + ); | ||
23 | + | ||
24 | + /** | ||
25 | + * Creating indexes and foreign keys for language table | ||
26 | + */ | ||
27 | + $this->createIndex( | ||
28 | + 'blog_tag_lang_uk', | ||
29 | + 'blog_tag_lang', | ||
30 | + [ | ||
31 | + 'blog_tag_id', | ||
32 | + 'language_id', | ||
33 | + ], | ||
34 | + true | ||
35 | + ); | ||
36 | + | ||
37 | + $this->addForeignKey( | ||
38 | + 'blog_tag_lang_fk', | ||
39 | + 'blog_tag_lang', | ||
40 | + 'language_id', | ||
41 | + 'language', | ||
42 | + 'id', | ||
43 | + 'RESTRICT', | ||
44 | + 'CASCADE' | ||
45 | + ); | ||
46 | + | ||
47 | + $this->addForeignKey( | ||
48 | + 'blog_tag_fk', | ||
49 | + 'blog_tag_lang', | ||
50 | + 'blog_tag_id', | ||
51 | + 'blog_tag', | ||
52 | + 'id', | ||
53 | + 'CASCADE', | ||
54 | + 'CASCADE' | ||
55 | + ); | ||
56 | + } | ||
57 | + | ||
58 | + public function down() | ||
59 | + { | ||
60 | + $this->dropForeignKey('blog_tag_fk', 'blog_tag_lang'); | ||
61 | + $this->dropForeignKey('blog_tag_lang_fk', 'blog_tag_lang'); | ||
62 | + $this->dropIndex('blog_tag_lang_uk', 'blog_tag_lang'); | ||
63 | + $this->dropTable('blog_tag_lang'); | ||
64 | + } | ||
65 | +} |
console/migrations/blog/m161101_144140_blog_article_to_tag.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_144140_blog_article_to_tag extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create junction table to connect articles with tags | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_article_to_tag', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_article_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'blog_tag_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + ] | ||
21 | + ); | ||
22 | + | ||
23 | + /** | ||
24 | + * Create indexes and foreign keys for junction table | ||
25 | + */ | ||
26 | + $this->createIndex( | ||
27 | + 'blog_article_to_tag_uk', | ||
28 | + 'blog_article_to_tag', | ||
29 | + [ | ||
30 | + 'blog_article_id', | ||
31 | + 'blog_tag_id', | ||
32 | + ], | ||
33 | + true | ||
34 | + ); | ||
35 | + | ||
36 | + $this->addForeignKey( | ||
37 | + 'blog_article_to_tag_tag_fk', | ||
38 | + 'blog_article_to_tag', | ||
39 | + 'blog_tag_id', | ||
40 | + 'blog_tag', | ||
41 | + 'id', | ||
42 | + 'CASCADE', | ||
43 | + 'CASCADE' | ||
44 | + ); | ||
45 | + | ||
46 | + $this->addForeignKey( | ||
47 | + 'blog_article_to_tag_art_fk', | ||
48 | + 'blog_article_to_tag', | ||
49 | + 'blog_article_id', | ||
50 | + 'blog_article', | ||
51 | + 'id', | ||
52 | + 'CASCADE', | ||
53 | + 'CASCADE' | ||
54 | + ); | ||
55 | + } | ||
56 | + | ||
57 | + public function down() | ||
58 | + { | ||
59 | + $this->dropForeignKey('blog_article_to_tag_art_fk', 'blog_article_to_tag'); | ||
60 | + $this->dropForeignKey('blog_article_to_tag_tag_fk', 'blog_article_to_tag'); | ||
61 | + $this->dropIndex('blog_article_to_tag_uk', 'blog_article_to_tag'); | ||
62 | + $this->dropTable('blog_article_to_tag'); | ||
63 | + } | ||
64 | +} |
console/migrations/blog/m161101_144312_blog_article_to_article.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_144312_blog_article_to_article extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Create table and all relations for related articles functionality | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_article_to_article', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_article_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'related_blog_article_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + ] | ||
21 | + ); | ||
22 | + | ||
23 | + $this->createIndex( | ||
24 | + 'blog_article_to_article_uk', | ||
25 | + 'blog_article_to_article', | ||
26 | + [ | ||
27 | + 'blog_article_id', | ||
28 | + 'related_blog_article_id', | ||
29 | + ], | ||
30 | + true | ||
31 | + ); | ||
32 | + | ||
33 | + $this->addForeignKey( | ||
34 | + 'blog_article_to_article_art_fk', | ||
35 | + 'blog_article_to_article', | ||
36 | + 'blog_article_id', | ||
37 | + 'blog_article', | ||
38 | + 'id', | ||
39 | + 'CASCADE', | ||
40 | + 'CASCADE' | ||
41 | + ); | ||
42 | + | ||
43 | + $this->addForeignKey( | ||
44 | + 'blog_article_to_article_rel_fk', | ||
45 | + 'blog_article_to_article', | ||
46 | + 'related_blog_article_id', | ||
47 | + 'blog_article', | ||
48 | + 'id', | ||
49 | + 'CASCADE', | ||
50 | + 'CASCADE' | ||
51 | + ); | ||
52 | + } | ||
53 | + | ||
54 | + public function down() | ||
55 | + { | ||
56 | + $this->dropForeignKey('blog_article_to_article_rel_fk', 'blog_article_to_article'); | ||
57 | + $this->dropForeignKey('blog_article_to_article_art_fk', 'blog_article_to_article'); | ||
58 | + $this->dropIndex('blog_article_to_article_uk', 'blog_article_to_article'); | ||
59 | + $this->dropTable('blog_article_to_article'); | ||
60 | + } | ||
61 | +} |
console/migrations/blog/m161101_144434_blog_article_to_product.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m161101_144434_blog_article_to_product extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + /** | ||
10 | + * Creates junction table and all stuff for adding related products to articles | ||
11 | + */ | ||
12 | + $this->createTable( | ||
13 | + 'blog_article_to_product', | ||
14 | + [ | ||
15 | + 'id' => $this->primaryKey(), | ||
16 | + 'blog_article_id' => $this->integer() | ||
17 | + ->notNull(), | ||
18 | + 'product_id' => $this->integer() | ||
19 | + ->notNull(), | ||
20 | + ] | ||
21 | + ); | ||
22 | + | ||
23 | + $this->createIndex( | ||
24 | + 'blog_article_to_product_uk', | ||
25 | + 'blog_article_to_product', | ||
26 | + [ | ||
27 | + 'blog_article_id', | ||
28 | + 'product_id', | ||
29 | + ], | ||
30 | + true | ||
31 | + ); | ||
32 | + | ||
33 | + $this->addForeignKey( | ||
34 | + 'blog_article_to_product_art_fk', | ||
35 | + 'blog_article_to_product', | ||
36 | + 'blog_article_id', | ||
37 | + 'blog_article', | ||
38 | + 'id', | ||
39 | + 'CASCADE', | ||
40 | + 'CASCADE' | ||
41 | + ); | ||
42 | + | ||
43 | + $this->addForeignKey( | ||
44 | + 'blog_article_to_product_prod_fk', | ||
45 | + 'blog_article_to_product', | ||
46 | + 'product_id', | ||
47 | + 'product', | ||
48 | + 'id', | ||
49 | + 'CASCADE', | ||
50 | + 'CASCADE' | ||
51 | + ); | ||
52 | + } | ||
53 | + | ||
54 | + public function down() | ||
55 | + { | ||
56 | + $this->dropForeignKey('blog_article_to_product_prod_fk', 'blog_article_to_product'); | ||
57 | + $this->dropForeignKey('blog_article_to_product_art_fk', 'blog_article_to_product'); | ||
58 | + $this->dropIndex('blog_article_to_product_uk', 'blog_article_to_product'); | ||
59 | + $this->dropTable('blog_article_to_product'); | ||
60 | + } | ||
61 | +} |
storage/.htaccess