Commit c5a6465c805db4ee441f9fa1749840c4f6e16362
1 parent
f14c090e
-Blog half-way done
Showing
50 changed files
with
2443 additions
and
40 deletions
Show diff stats
backend/views/layouts/main-sidebar.php
| ... | ... | @@ -121,6 +121,29 @@ use yii\widgets\Menu; |
| 121 | 121 | 'options' => ['class'=>\Yii::$app->user->can('article') ? '' :'hide'], |
| 122 | 122 | ], |
| 123 | 123 | [ |
| 124 | + 'label' => 'Блог', | |
| 125 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-picture"></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 | + ], | |
| 134 | + [ | |
| 135 | + 'label' => 'Рубрики', | |
| 136 | + 'url' => ['/blog/blog-category'], | |
| 137 | + 'options' => ['class'=>\Yii::$app->user->can('blog') ? '' :'hide'], | |
| 138 | + ], | |
| 139 | + [ | |
| 140 | + 'label' => 'Тэги', | |
| 141 | + 'url' => ['/blog/blog-tag'], | |
| 142 | + 'options' => ['class'=>\Yii::$app->user->can('blog') ? '' :'hide'], | |
| 143 | + ], | |
| 144 | + ] | |
| 145 | + ], | |
| 146 | + [ | |
| 124 | 147 | 'label' => 'Акции', |
| 125 | 148 | 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-piggy-bank"></i> <span>{label}</span></a>', |
| 126 | 149 | 'url' => ['/event/index'], | ... | ... |
common/config/main.php
| 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 Yii; | |
| 6 | +use common\modules\blog\models\BlogArticle; | |
| 7 | +use common\modules\blog\models\BlogArticleSearch; | |
| 8 | +use yii\web\Controller; | |
| 9 | +use yii\web\NotFoundHttpException; | |
| 10 | +use yii\filters\VerbFilter; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * BlogArticleController implements the CRUD actions for BlogArticle model. | |
| 14 | + */ | |
| 15 | +class BlogArticleController 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 BlogArticle models. | |
| 34 | + * @return mixed | |
| 35 | + */ | |
| 36 | + public function actionIndex() | |
| 37 | + { | |
| 38 | + $searchModel = new BlogArticleSearch(); | |
| 39 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| 40 | + | |
| 41 | + return $this->render('index', [ | |
| 42 | + 'searchModel' => $searchModel, | |
| 43 | + 'dataProvider' => $dataProvider, | |
| 44 | + ]); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Displays a single BlogArticle model. | |
| 49 | + * @param integer $id | |
| 50 | + * @return mixed | |
| 51 | + */ | |
| 52 | + public function actionView($id) | |
| 53 | + { | |
| 54 | + return $this->render('view', [ | |
| 55 | + 'model' => $this->findModel($id), | |
| 56 | + ]); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Creates a new BlogArticle model. | |
| 61 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 62 | + * @return mixed | |
| 63 | + */ | |
| 64 | + public function actionCreate() | |
| 65 | + { | |
| 66 | + $model = new BlogArticle(); | |
| 67 | + | |
| 68 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 69 | + return $this->redirect(['view', 'id' => $model->id]); | |
| 70 | + } else { | |
| 71 | + return $this->render('create', [ | |
| 72 | + 'model' => $model, | |
| 73 | + ]); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Updates an existing BlogArticle model. | |
| 79 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 80 | + * @param integer $id | |
| 81 | + * @return mixed | |
| 82 | + */ | |
| 83 | + public function actionUpdate($id) | |
| 84 | + { | |
| 85 | + $model = $this->findModel($id); | |
| 86 | + | |
| 87 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 88 | + return $this->redirect(['view', 'id' => $model->id]); | |
| 89 | + } else { | |
| 90 | + return $this->render('update', [ | |
| 91 | + 'model' => $model, | |
| 92 | + ]); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Deletes an existing BlogArticle model. | |
| 98 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 99 | + * @param integer $id | |
| 100 | + * @return mixed | |
| 101 | + */ | |
| 102 | + public function actionDelete($id) | |
| 103 | + { | |
| 104 | + $this->findModel($id)->delete(); | |
| 105 | + | |
| 106 | + return $this->redirect(['index']); | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Finds the BlogArticle model based on its primary key value. | |
| 111 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 112 | + * @param integer $id | |
| 113 | + * @return BlogArticle the loaded model | |
| 114 | + * @throws NotFoundHttpException if the model cannot be found | |
| 115 | + */ | |
| 116 | + protected function findModel($id) | |
| 117 | + { | |
| 118 | + if (($model = BlogArticle::findOne($id)) !== null) { | |
| 119 | + return $model; | |
| 120 | + } else { | |
| 121 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 122 | + } | |
| 123 | + } | |
| 124 | +} | ... | ... |
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\web\Controller; | |
| 9 | +use yii\web\NotFoundHttpException; | |
| 10 | +use yii\filters\VerbFilter; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * BlogCategoryController implements the CRUD actions for BlogCategory model. | |
| 14 | + */ | |
| 15 | +class BlogCategoryController 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 BlogCategory models. | |
| 34 | + * @return mixed | |
| 35 | + */ | |
| 36 | + public function actionIndex() | |
| 37 | + { | |
| 38 | + $searchModel = new BlogCategorySearch(); | |
| 39 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| 40 | + | |
| 41 | + return $this->render('index', [ | |
| 42 | + 'searchModel' => $searchModel, | |
| 43 | + 'dataProvider' => $dataProvider, | |
| 44 | + ]); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Displays a single BlogCategory model. | |
| 49 | + * @param integer $id | |
| 50 | + * @return mixed | |
| 51 | + */ | |
| 52 | + public function actionView($id) | |
| 53 | + { | |
| 54 | + return $this->render('view', [ | |
| 55 | + 'model' => $this->findModel($id), | |
| 56 | + ]); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Creates a new BlogCategory model. | |
| 61 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 62 | + * @return mixed | |
| 63 | + */ | |
| 64 | + public function actionCreate() | |
| 65 | + { | |
| 66 | + $model = new BlogCategory(); | |
| 67 | + | |
| 68 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 69 | + return $this->redirect(['view', 'id' => $model->id]); | |
| 70 | + } else { | |
| 71 | + return $this->render('create', [ | |
| 72 | + 'model' => $model, | |
| 73 | + ]); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Updates an existing BlogCategory model. | |
| 79 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 80 | + * @param integer $id | |
| 81 | + * @return mixed | |
| 82 | + */ | |
| 83 | + public function actionUpdate($id) | |
| 84 | + { | |
| 85 | + $model = $this->findModel($id); | |
| 86 | + | |
| 87 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 88 | + return $this->redirect(['view', 'id' => $model->id]); | |
| 89 | + } else { | |
| 90 | + return $this->render('update', [ | |
| 91 | + 'model' => $model, | |
| 92 | + ]); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Deletes an existing BlogCategory model. | |
| 98 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 99 | + * @param integer $id | |
| 100 | + * @return mixed | |
| 101 | + */ | |
| 102 | + public function actionDelete($id) | |
| 103 | + { | |
| 104 | + $this->findModel($id)->delete(); | |
| 105 | + | |
| 106 | + return $this->redirect(['index']); | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Finds the BlogCategory model based on its primary key value. | |
| 111 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 112 | + * @param integer $id | |
| 113 | + * @return BlogCategory the loaded model | |
| 114 | + * @throws NotFoundHttpException if the model cannot be found | |
| 115 | + */ | |
| 116 | + protected function findModel($id) | |
| 117 | + { | |
| 118 | + if (($model = BlogCategory::findOne($id)) !== null) { | |
| 119 | + return $model; | |
| 120 | + } else { | |
| 121 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 122 | + } | |
| 123 | + } | |
| 124 | +} | ... | ... |
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 | + * @return mixed | |
| 35 | + */ | |
| 36 | + public function actionIndex() | |
| 37 | + { | |
| 38 | + $searchModel = new BlogTagSearch(); | |
| 39 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| 40 | + | |
| 41 | + return $this->render('index', [ | |
| 42 | + 'searchModel' => $searchModel, | |
| 43 | + 'dataProvider' => $dataProvider, | |
| 44 | + ]); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Displays a single BlogTag model. | |
| 49 | + * @param integer $id | |
| 50 | + * @return mixed | |
| 51 | + */ | |
| 52 | + public function actionView($id) | |
| 53 | + { | |
| 54 | + return $this->render('view', [ | |
| 55 | + 'model' => $this->findModel($id), | |
| 56 | + ]); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Creates a new BlogTag model. | |
| 61 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
| 62 | + * @return mixed | |
| 63 | + */ | |
| 64 | + public function actionCreate() | |
| 65 | + { | |
| 66 | + $model = new BlogTag(); | |
| 67 | + | |
| 68 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 69 | + return $this->redirect(['view', 'id' => $model->id]); | |
| 70 | + } else { | |
| 71 | + return $this->render('create', [ | |
| 72 | + 'model' => $model, | |
| 73 | + ]); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Updates an existing BlogTag model. | |
| 79 | + * If update is successful, the browser will be redirected to the 'view' page. | |
| 80 | + * @param integer $id | |
| 81 | + * @return mixed | |
| 82 | + */ | |
| 83 | + public function actionUpdate($id) | |
| 84 | + { | |
| 85 | + $model = $this->findModel($id); | |
| 86 | + | |
| 87 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 88 | + return $this->redirect(['view', 'id' => $model->id]); | |
| 89 | + } else { | |
| 90 | + return $this->render('update', [ | |
| 91 | + 'model' => $model, | |
| 92 | + ]); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Deletes an existing BlogTag model. | |
| 98 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
| 99 | + * @param integer $id | |
| 100 | + * @return mixed | |
| 101 | + */ | |
| 102 | + public function actionDelete($id) | |
| 103 | + { | |
| 104 | + $this->findModel($id)->delete(); | |
| 105 | + | |
| 106 | + return $this->redirect(['index']); | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Finds the BlogTag model based on its primary key value. | |
| 111 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
| 112 | + * @param integer $id | |
| 113 | + * @return BlogTag the loaded model | |
| 114 | + * @throws NotFoundHttpException if the model cannot be found | |
| 115 | + */ | |
| 116 | + protected function findModel($id) | |
| 117 | + { | |
| 118 | + if (($model = BlogTag::findOne($id)) !== null) { | |
| 119 | + return $model; | |
| 120 | + } else { | |
| 121 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
| 122 | + } | |
| 123 | + } | |
| 124 | +} | ... | ... |
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 yii\db\ActiveRecord; | |
| 6 | + use common\modules\language\behaviors\LanguageBehavior; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * This is the model class for table "blog_article". | |
| 10 | + * | |
| 11 | + * @property integer $id | |
| 12 | + * @property string $image | |
| 13 | + * @property integer $created_at | |
| 14 | + * @property integer $updated_at | |
| 15 | + * @property integer $deleted_at | |
| 16 | + * @property integer $sort | |
| 17 | + * @property boolean $status | |
| 18 | + * @property integer $author_id | |
| 19 | + * @property BlogArticleLang[] $blogArticleLangs | |
| 20 | + * @property Language[] $languages | |
| 21 | + * @property BlogArticleToArticle[] $blogArticleToArticles | |
| 22 | + * @property BlogArticleToArticle[] $blogArticleToArticles0 | |
| 23 | + * @property BlogArticle[] $relatedBlogArticles | |
| 24 | + * @property BlogArticle[] $blogArticles | |
| 25 | + * @property BlogArticleToCategory[] $blogArticleToCategories | |
| 26 | + * @property BlogCategory[] $blogCategories | |
| 27 | + * @property BlogArticleToProduct[] $blogArticleToProducts | |
| 28 | + * @property Product[] $products | |
| 29 | + * @property BlogArticleToTag[] $blogArticleToTags | |
| 30 | + * @property BlogTag[] $blogTags | |
| 31 | + */ | |
| 32 | + class BlogArticle extends ActiveRecord | |
| 33 | + { | |
| 34 | + /** | |
| 35 | + * @inheritdoc | |
| 36 | + */ | |
| 37 | + public static function tableName() | |
| 38 | + { | |
| 39 | + return 'blog_article'; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public function behaviors() | |
| 43 | + { | |
| 44 | + return [ | |
| 45 | + 'language' => [ | |
| 46 | + 'class' => LanguageBehavior::className(), | |
| 47 | + ], | |
| 48 | + ]; | |
| 49 | + } | |
| 50 | + /** | |
| 51 | + * @inheritdoc | |
| 52 | + */ | |
| 53 | + public function rules() | |
| 54 | + { | |
| 55 | + return [ | |
| 56 | + [ | |
| 57 | + [ | |
| 58 | + 'created_at', | |
| 59 | + 'updated_at', | |
| 60 | + 'deleted_at', | |
| 61 | + 'sort', | |
| 62 | + 'author_id', | |
| 63 | + ], | |
| 64 | + 'integer', | |
| 65 | + ], | |
| 66 | + [ | |
| 67 | + [ 'status' ], | |
| 68 | + 'boolean', | |
| 69 | + ], | |
| 70 | + [ | |
| 71 | + [ 'image' ], | |
| 72 | + 'string', | |
| 73 | + 'max' => 255, | |
| 74 | + ], | |
| 75 | + ]; | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @inheritdoc | |
| 80 | + */ | |
| 81 | + public function attributeLabels() | |
| 82 | + { | |
| 83 | + return [ | |
| 84 | + 'id' => 'ID', | |
| 85 | + 'image' => 'Image', | |
| 86 | + 'created_at' => 'Created At', | |
| 87 | + 'updated_at' => 'Updated At', | |
| 88 | + 'deleted_at' => 'Deleted At', | |
| 89 | + 'sort' => 'Sort', | |
| 90 | + 'status' => 'Status', | |
| 91 | + 'author_id' => 'Author ID', | |
| 92 | + ]; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @return \yii\db\ActiveQuery | |
| 97 | + */ | |
| 98 | + public function getBlogArticleLangs() | |
| 99 | + { | |
| 100 | + return $this->hasMany(BlogArticleLang::className(), [ 'blog_article_id' => 'id' ]); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @return \yii\db\ActiveQuery | |
| 105 | + */ | |
| 106 | + public function getLanguages() | |
| 107 | + { | |
| 108 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | |
| 109 | + ->viaTable('blog_article_lang', [ 'blog_article_id' => 'id' ]); | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * @return \yii\db\ActiveQuery | |
| 114 | + */ | |
| 115 | + public function getBlogArticleToArticles() | |
| 116 | + { | |
| 117 | + return $this->hasMany(BlogArticleToArticle::className(), [ 'blog_article_id' => 'id' ]); | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * @return \yii\db\ActiveQuery | |
| 122 | + */ | |
| 123 | + public function getBlogArticleToArticles0() | |
| 124 | + { | |
| 125 | + return $this->hasMany(BlogArticleToArticle::className(), [ 'related_blog_article_id' => 'id' ]); | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * @return \yii\db\ActiveQuery | |
| 130 | + */ | |
| 131 | + public function getRelatedBlogArticles() | |
| 132 | + { | |
| 133 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'related_blog_article_id' ]) | |
| 134 | + ->viaTable('blog_article_to_article', [ 'blog_article_id' => 'id' ]); | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * @return \yii\db\ActiveQuery | |
| 139 | + */ | |
| 140 | + public function getBlogArticles() | |
| 141 | + { | |
| 142 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | |
| 143 | + ->viaTable('blog_article_to_article', [ 'related_blog_article_id' => 'id' ]); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * @return \yii\db\ActiveQuery | |
| 148 | + */ | |
| 149 | + public function getBlogArticleToCategories() | |
| 150 | + { | |
| 151 | + return $this->hasMany(BlogArticleToCategory::className(), [ 'blog_article_id' => 'id' ]); | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * @return \yii\db\ActiveQuery | |
| 156 | + */ | |
| 157 | + public function getBlogCategories() | |
| 158 | + { | |
| 159 | + return $this->hasMany(BlogCategory::className(), [ 'id' => 'blog_category_id' ]) | |
| 160 | + ->viaTable('blog_article_to_category', [ 'blog_article_id' => 'id' ]); | |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * @return \yii\db\ActiveQuery | |
| 165 | + */ | |
| 166 | + public function getBlogArticleToProducts() | |
| 167 | + { | |
| 168 | + return $this->hasMany(BlogArticleToProduct::className(), [ 'blog_article_id' => 'id' ]); | |
| 169 | + } | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * @return \yii\db\ActiveQuery | |
| 173 | + */ | |
| 174 | + public function getProducts() | |
| 175 | + { | |
| 176 | + return $this->hasMany(Product::className(), [ 'id' => 'product_id' ]) | |
| 177 | + ->viaTable('blog_article_to_product', [ 'blog_article_id' => 'id' ]); | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * @return \yii\db\ActiveQuery | |
| 182 | + */ | |
| 183 | + public function getBlogArticleToTags() | |
| 184 | + { | |
| 185 | + return $this->hasMany(BlogArticleToTag::className(), [ 'blog_article_id' => 'id' ]); | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * @return \yii\db\ActiveQuery | |
| 190 | + */ | |
| 191 | + public function getBlogTags() | |
| 192 | + { | |
| 193 | + return $this->hasMany(BlogTag::className(), [ 'id' => 'blog_tag_id' ]) | |
| 194 | + ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); | |
| 195 | + } | |
| 196 | + } | ... | ... |
| 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 | + * | |
| 23 | + * @property BlogArticle $blogArticle | |
| 24 | + * @property Language $language | |
| 25 | + */ | |
| 26 | +class BlogArticleLang extends ActiveRecord | |
| 27 | +{ | |
| 28 | + /** | |
| 29 | + * @inheritdoc | |
| 30 | + */ | |
| 31 | + public static function tableName() | |
| 32 | + { | |
| 33 | + return 'blog_article_lang'; | |
| 34 | + } | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * @inheritdoc | |
| 38 | + */ | |
| 39 | + public function rules() | |
| 40 | + { | |
| 41 | + return [ | |
| 42 | + [['blog_article_id', 'language_id'], 'required'], | |
| 43 | + [['blog_article_id', 'language_id'], 'integer'], | |
| 44 | + [['body', 'body_preview'], 'string'], | |
| 45 | + [['title', 'alias', 'meta_title', 'meta_description', 'h1', 'seo_text'], 'string', 'max' => 255], | |
| 46 | + [['alias'], 'unique'], | |
| 47 | + [['blog_article_id', 'language_id'], 'unique', 'targetAttribute' => ['blog_article_id', 'language_id'], 'message' => 'The combination of Blog Article ID and Language ID has already been taken.'], | |
| 48 | + [['blog_article_id'], 'exist', 'skipOnError' => true, 'targetClass' => BlogArticle::className(), 'targetAttribute' => ['blog_article_id' => 'id']], | |
| 49 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | |
| 50 | + ]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @inheritdoc | |
| 55 | + */ | |
| 56 | + public function attributeLabels() | |
| 57 | + { | |
| 58 | + return [ | |
| 59 | + 'id' => 'ID', | |
| 60 | + 'blog_article_id' => 'Blog Article ID', | |
| 61 | + 'language_id' => 'Language ID', | |
| 62 | + 'title' => 'Title', | |
| 63 | + 'body' => 'Body', | |
| 64 | + 'body_preview' => 'Body Preview', | |
| 65 | + 'alias' => 'Alias', | |
| 66 | + 'meta_title' => 'Meta Title', | |
| 67 | + 'meta_description' => 'Meta Description', | |
| 68 | + 'h1' => 'H1', | |
| 69 | + 'seo_text' => 'Seo Text', | |
| 70 | + ]; | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * @return \yii\db\ActiveQuery | |
| 75 | + */ | |
| 76 | + public function getBlogArticle() | |
| 77 | + { | |
| 78 | + return $this->hasOne(BlogArticle::className(), ['id' => 'blog_article_id']); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @return \yii\db\ActiveQuery | |
| 83 | + */ | |
| 84 | + public function getLanguage() | |
| 85 | + { | |
| 86 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
| 87 | + } | |
| 88 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | +use yii\base\Model; | |
| 7 | +use yii\data\ActiveDataProvider; | |
| 8 | +use common\modules\blog\models\BlogArticle; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * BlogArticleSearch represents the model behind the search form about `common\modules\blog\models\BlogArticle`. | |
| 12 | + */ | |
| 13 | +class BlogArticleSearch extends BlogArticle | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @inheritdoc | |
| 17 | + */ | |
| 18 | + public function rules() | |
| 19 | + { | |
| 20 | + return [ | |
| 21 | + [['id', 'created_at', 'updated_at', 'deleted_at', 'sort', 'author_id'], 'integer'], | |
| 22 | + [['image'], 'safe'], | |
| 23 | + [['status'], 'boolean'], | |
| 24 | + ]; | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @inheritdoc | |
| 29 | + */ | |
| 30 | + public function behaviors() | |
| 31 | + { | |
| 32 | + return []; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @inheritdoc | |
| 37 | + */ | |
| 38 | + public function scenarios() | |
| 39 | + { | |
| 40 | + // bypass scenarios() implementation in the parent class | |
| 41 | + return Model::scenarios(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Creates data provider instance with search query applied | |
| 46 | + * | |
| 47 | + * @param array $params | |
| 48 | + * | |
| 49 | + * @return ActiveDataProvider | |
| 50 | + */ | |
| 51 | + public function search($params) | |
| 52 | + { | |
| 53 | + $query = BlogArticle::find(); | |
| 54 | + | |
| 55 | + // add conditions that should always apply here | |
| 56 | + | |
| 57 | + $dataProvider = new ActiveDataProvider([ | |
| 58 | + 'query' => $query, | |
| 59 | + ]); | |
| 60 | + | |
| 61 | + $this->load($params); | |
| 62 | + | |
| 63 | + if (!$this->validate()) { | |
| 64 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 65 | + // $query->where('0=1'); | |
| 66 | + return $dataProvider; | |
| 67 | + } | |
| 68 | + | |
| 69 | + // grid filtering conditions | |
| 70 | + $query->andFilterWhere([ | |
| 71 | + 'id' => $this->id, | |
| 72 | + 'created_at' => $this->created_at, | |
| 73 | + 'updated_at' => $this->updated_at, | |
| 74 | + 'deleted_at' => $this->deleted_at, | |
| 75 | + 'sort' => $this->sort, | |
| 76 | + 'status' => $this->status, | |
| 77 | + 'author_id' => $this->author_id, | |
| 78 | + ]); | |
| 79 | + | |
| 80 | + $query->andFilterWhere(['like', 'image', $this->image]); | |
| 81 | + | |
| 82 | + return $dataProvider; | |
| 83 | + } | |
| 84 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | + use yii\db\ActiveRecord; | |
| 6 | + use common\modules\language\behaviors\LanguageBehavior; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * This is the model class for table "blog_category". | |
| 10 | + * | |
| 11 | + * @property integer $id | |
| 12 | + * @property integer $sort | |
| 13 | + * @property string $image | |
| 14 | + * @property integer $parent_id | |
| 15 | + * @property boolean $status | |
| 16 | + * @property BlogArticleToCategory[] $blogArticleToCategories | |
| 17 | + * @property BlogArticle[] $blogArticles | |
| 18 | + * @property BlogCategoryLang[] $blogCategoryLangs | |
| 19 | + * @property Language[] $languages | |
| 20 | + */ | |
| 21 | + class BlogCategory extends ActiveRecord | |
| 22 | + { | |
| 23 | + /** | |
| 24 | + * @inheritdoc | |
| 25 | + */ | |
| 26 | + public static function tableName() | |
| 27 | + { | |
| 28 | + return 'blog_category'; | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @inheritdoc | |
| 33 | + */ | |
| 34 | + public function behaviors() | |
| 35 | + { | |
| 36 | + return [ | |
| 37 | + 'language' => [ | |
| 38 | + 'class' => LanguageBehavior::className(), | |
| 39 | + ], | |
| 40 | + ]; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @inheritdoc | |
| 45 | + */ | |
| 46 | + public function rules() | |
| 47 | + { | |
| 48 | + return [ | |
| 49 | + [ | |
| 50 | + [ | |
| 51 | + 'sort', | |
| 52 | + 'parent_id', | |
| 53 | + ], | |
| 54 | + 'integer', | |
| 55 | + ], | |
| 56 | + [ | |
| 57 | + [ 'status' ], | |
| 58 | + 'boolean', | |
| 59 | + ], | |
| 60 | + [ | |
| 61 | + [ 'image' ], | |
| 62 | + 'string', | |
| 63 | + 'max' => 255, | |
| 64 | + ], | |
| 65 | + ]; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @inheritdoc | |
| 70 | + */ | |
| 71 | + public function attributeLabels() | |
| 72 | + { | |
| 73 | + return [ | |
| 74 | + 'id' => 'ID', | |
| 75 | + 'sort' => 'Sort', | |
| 76 | + 'image' => 'Image', | |
| 77 | + 'parent_id' => 'Parent ID', | |
| 78 | + 'status' => 'Status', | |
| 79 | + ]; | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * @return \yii\db\ActiveQuery | |
| 84 | + */ | |
| 85 | + public function getBlogArticleToCategories() | |
| 86 | + { | |
| 87 | + return $this->hasMany(BlogArticleToCategory::className(), [ 'blog_category_id' => 'id' ]); | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * @return \yii\db\ActiveQuery | |
| 92 | + */ | |
| 93 | + public function getBlogArticles() | |
| 94 | + { | |
| 95 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | |
| 96 | + ->viaTable('blog_article_to_category', [ 'blog_category_id' => 'id' ]); | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * @return \yii\db\ActiveQuery | |
| 101 | + */ | |
| 102 | + public function getBlogCategoryLangs() | |
| 103 | + { | |
| 104 | + return $this->hasMany(BlogCategoryLang::className(), [ 'blog_category_id' => 'id' ]); | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * @return \yii\db\ActiveQuery | |
| 109 | + */ | |
| 110 | + public function getLanguages() | |
| 111 | + { | |
| 112 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | |
| 113 | + ->viaTable('blog_category_lang', [ 'blog_category_id' => 'id' ]); | |
| 114 | + } | |
| 115 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * This is the model class for table "blog_category_lang". | |
| 9 | + * | |
| 10 | + * @property integer $id | |
| 11 | + * @property integer $blog_category_id | |
| 12 | + * @property integer $language_id | |
| 13 | + * @property string $title | |
| 14 | + * @property string $alias | |
| 15 | + * @property string $description | |
| 16 | + * @property string $meta_title | |
| 17 | + * @property string $meta_description | |
| 18 | + * @property string $h1 | |
| 19 | + * @property string $seo_text | |
| 20 | + * | |
| 21 | + * @property BlogCategory $blogCategory | |
| 22 | + * @property Language $language | |
| 23 | + */ | |
| 24 | +class BlogCategoryLang extends \yii\db\ActiveRecord | |
| 25 | +{ | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public static function tableName() | |
| 30 | + { | |
| 31 | + return 'blog_category_lang'; | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @inheritdoc | |
| 36 | + */ | |
| 37 | + public function rules() | |
| 38 | + { | |
| 39 | + return [ | |
| 40 | + [['blog_category_id', 'language_id'], 'required'], | |
| 41 | + [['blog_category_id', 'language_id'], 'integer'], | |
| 42 | + [['description'], 'string'], | |
| 43 | + [['title', 'alias', 'meta_title', 'meta_description', 'h1', 'seo_text'], 'string', 'max' => 255], | |
| 44 | + [['alias'], 'unique'], | |
| 45 | + [['blog_category_id', 'language_id'], 'unique', 'targetAttribute' => ['blog_category_id', 'language_id'], 'message' => 'The combination of Blog Category ID and Language ID has already been taken.'], | |
| 46 | + [['blog_category_id'], 'exist', 'skipOnError' => true, 'targetClass' => BlogCategory::className(), 'targetAttribute' => ['blog_category_id' => 'id']], | |
| 47 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | |
| 48 | + ]; | |
| 49 | + } | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @inheritdoc | |
| 53 | + */ | |
| 54 | + public function attributeLabels() | |
| 55 | + { | |
| 56 | + return [ | |
| 57 | + 'id' => 'ID', | |
| 58 | + 'blog_category_id' => 'Blog Category ID', | |
| 59 | + 'language_id' => 'Language ID', | |
| 60 | + 'title' => 'Title', | |
| 61 | + 'alias' => 'Alias', | |
| 62 | + 'description' => 'Description', | |
| 63 | + 'meta_title' => 'Meta Title', | |
| 64 | + 'meta_description' => 'Meta Description', | |
| 65 | + 'h1' => 'H1', | |
| 66 | + 'seo_text' => 'Seo Text', | |
| 67 | + ]; | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * @return \yii\db\ActiveQuery | |
| 72 | + */ | |
| 73 | + public function getBlogCategory() | |
| 74 | + { | |
| 75 | + return $this->hasOne(BlogCategory::className(), ['id' => 'blog_category_id']); | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @return \yii\db\ActiveQuery | |
| 80 | + */ | |
| 81 | + public function getLanguage() | |
| 82 | + { | |
| 83 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
| 84 | + } | |
| 85 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | +use yii\base\Model; | |
| 7 | +use yii\data\ActiveDataProvider; | |
| 8 | +use common\modules\blog\models\BlogCategory; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * BlogCategorySearch represents the model behind the search form about `common\modules\blog\models\BlogCategory`. | |
| 12 | + */ | |
| 13 | +class BlogCategorySearch extends BlogCategory | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @inheritdoc | |
| 17 | + */ | |
| 18 | + public function rules() | |
| 19 | + { | |
| 20 | + return [ | |
| 21 | + [['id', 'sort', 'parent_id'], 'integer'], | |
| 22 | + [['image'], 'safe'], | |
| 23 | + [['status'], 'boolean'], | |
| 24 | + ]; | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @inheritdoc | |
| 29 | + */ | |
| 30 | + public function behaviors() | |
| 31 | + { | |
| 32 | + return []; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @inheritdoc | |
| 37 | + */ | |
| 38 | + public function scenarios() | |
| 39 | + { | |
| 40 | + // bypass scenarios() implementation in the parent class | |
| 41 | + return Model::scenarios(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Creates data provider instance with search query applied | |
| 46 | + * | |
| 47 | + * @param array $params | |
| 48 | + * | |
| 49 | + * @return ActiveDataProvider | |
| 50 | + */ | |
| 51 | + public function search($params) | |
| 52 | + { | |
| 53 | + $query = BlogCategory::find(); | |
| 54 | + | |
| 55 | + // add conditions that should always apply here | |
| 56 | + | |
| 57 | + $dataProvider = new ActiveDataProvider([ | |
| 58 | + 'query' => $query, | |
| 59 | + ]); | |
| 60 | + | |
| 61 | + $this->load($params); | |
| 62 | + | |
| 63 | + if (!$this->validate()) { | |
| 64 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 65 | + // $query->where('0=1'); | |
| 66 | + return $dataProvider; | |
| 67 | + } | |
| 68 | + | |
| 69 | + // grid filtering conditions | |
| 70 | + $query->andFilterWhere([ | |
| 71 | + 'id' => $this->id, | |
| 72 | + 'sort' => $this->sort, | |
| 73 | + 'parent_id' => $this->parent_id, | |
| 74 | + 'status' => $this->status, | |
| 75 | + ]); | |
| 76 | + | |
| 77 | + $query->andFilterWhere(['like', 'image', $this->image]); | |
| 78 | + | |
| 79 | + return $dataProvider; | |
| 80 | + } | |
| 81 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | + use yii\db\ActiveRecord; | |
| 6 | + use common\modules\language\behaviors\LanguageBehavior; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * This is the model class for table "blog_tag". | |
| 10 | + * | |
| 11 | + * @property integer $id | |
| 12 | + * @property BlogArticleToTag[] $blogArticleToTags | |
| 13 | + * @property BlogArticle[] $blogArticles | |
| 14 | + * @property BlogTagLang[] $blogTagLangs | |
| 15 | + * @property Language[] $languages | |
| 16 | + */ | |
| 17 | + class BlogTag extends \yii\db\ActiveRecord | |
| 18 | + { | |
| 19 | + /** | |
| 20 | + * @inheritdoc | |
| 21 | + */ | |
| 22 | + public static function tableName() | |
| 23 | + { | |
| 24 | + return 'blog_tag'; | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @inheritdoc | |
| 29 | + */ | |
| 30 | + public function behaviors() | |
| 31 | + { | |
| 32 | + return [ | |
| 33 | + 'language' => [ | |
| 34 | + 'class' => LanguageBehavior::className(), | |
| 35 | + ], | |
| 36 | + ]; | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @inheritdoc | |
| 41 | + */ | |
| 42 | + public function rules() | |
| 43 | + { | |
| 44 | + return [ | |
| 45 | + [ | |
| 46 | + [ 'id' ], | |
| 47 | + 'integer', | |
| 48 | + ], | |
| 49 | + ]; | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @inheritdoc | |
| 54 | + */ | |
| 55 | + public function attributeLabels() | |
| 56 | + { | |
| 57 | + return [ | |
| 58 | + 'id' => 'ID', | |
| 59 | + ]; | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @return \yii\db\ActiveQuery | |
| 64 | + */ | |
| 65 | + public function getBlogArticleToTags() | |
| 66 | + { | |
| 67 | + return $this->hasMany(BlogArticleToTag::className(), [ 'blog_tag_id' => 'id' ]); | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * @return \yii\db\ActiveQuery | |
| 72 | + */ | |
| 73 | + public function getBlogArticles() | |
| 74 | + { | |
| 75 | + return $this->hasMany(BlogArticle::className(), [ 'id' => 'blog_article_id' ]) | |
| 76 | + ->viaTable('blog_article_to_tag', [ 'blog_tag_id' => 'id' ]); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @return \yii\db\ActiveQuery | |
| 81 | + */ | |
| 82 | + public function getBlogTagLangs() | |
| 83 | + { | |
| 84 | + return $this->hasMany(BlogTagLang::className(), [ 'blog_tag_id' => 'id' ]); | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * @return \yii\db\ActiveQuery | |
| 89 | + */ | |
| 90 | + public function getLanguages() | |
| 91 | + { | |
| 92 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | |
| 93 | + ->viaTable('blog_tag_lang', [ 'blog_tag_id' => 'id' ]); | |
| 94 | + } | |
| 95 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * This is the model class for table "blog_tag_lang". | |
| 9 | + * | |
| 10 | + * @property integer $id | |
| 11 | + * @property integer $blog_tag_id | |
| 12 | + * @property integer $language_id | |
| 13 | + * @property string $label | |
| 14 | + * | |
| 15 | + * @property BlogTag $blogTag | |
| 16 | + * @property Language $language | |
| 17 | + */ | |
| 18 | +class BlogTagLang extends \yii\db\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 | + [['blog_tag_id', 'language_id'], 'required'], | |
| 35 | + [['blog_tag_id', 'language_id'], 'integer'], | |
| 36 | + [['label'], 'string', 'max' => 255], | |
| 37 | + [['blog_tag_id', 'language_id'], 'unique', 'targetAttribute' => ['blog_tag_id', 'language_id'], 'message' => 'The combination of Blog Tag ID and Language ID has already been taken.'], | |
| 38 | + [['blog_tag_id'], 'exist', 'skipOnError' => true, 'targetClass' => BlogTag::className(), 'targetAttribute' => ['blog_tag_id' => 'id']], | |
| 39 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | |
| 40 | + ]; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @inheritdoc | |
| 45 | + */ | |
| 46 | + public function attributeLabels() | |
| 47 | + { | |
| 48 | + return [ | |
| 49 | + 'id' => 'ID', | |
| 50 | + 'blog_tag_id' => 'Blog Tag ID', | |
| 51 | + 'language_id' => 'Language ID', | |
| 52 | + 'label' => 'Label', | |
| 53 | + ]; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @return \yii\db\ActiveQuery | |
| 58 | + */ | |
| 59 | + public function getBlogTag() | |
| 60 | + { | |
| 61 | + return $this->hasOne(BlogTag::className(), ['id' => 'blog_tag_id']); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * @return \yii\db\ActiveQuery | |
| 66 | + */ | |
| 67 | + public function getLanguage() | |
| 68 | + { | |
| 69 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
| 70 | + } | |
| 71 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\blog\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | +use yii\base\Model; | |
| 7 | +use yii\data\ActiveDataProvider; | |
| 8 | +use common\modules\blog\models\BlogTag; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * BlogTagSearch represents the model behind the search form about `common\modules\blog\models\BlogTag`. | |
| 12 | + */ | |
| 13 | +class BlogTagSearch extends BlogTag | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @inheritdoc | |
| 17 | + */ | |
| 18 | + public function rules() | |
| 19 | + { | |
| 20 | + return [ | |
| 21 | + [['id'], 'integer'], | |
| 22 | + ]; | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * @inheritdoc | |
| 27 | + */ | |
| 28 | + public function behaviors() | |
| 29 | + { | |
| 30 | + return []; | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * @inheritdoc | |
| 35 | + */ | |
| 36 | + public function scenarios() | |
| 37 | + { | |
| 38 | + // bypass scenarios() implementation in the parent class | |
| 39 | + return Model::scenarios(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Creates data provider instance with search query applied | |
| 44 | + * | |
| 45 | + * @param array $params | |
| 46 | + * | |
| 47 | + * @return ActiveDataProvider | |
| 48 | + */ | |
| 49 | + public function search($params) | |
| 50 | + { | |
| 51 | + $query = BlogTag::find(); | |
| 52 | + | |
| 53 | + // add conditions that should always apply here | |
| 54 | + | |
| 55 | + $dataProvider = new ActiveDataProvider([ | |
| 56 | + 'query' => $query, | |
| 57 | + ]); | |
| 58 | + | |
| 59 | + $this->load($params); | |
| 60 | + | |
| 61 | + if (!$this->validate()) { | |
| 62 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 63 | + // $query->where('0=1'); | |
| 64 | + return $dataProvider; | |
| 65 | + } | |
| 66 | + | |
| 67 | + // grid filtering conditions | |
| 68 | + $query->andFilterWhere([ | |
| 69 | + 'id' => $this->id, | |
| 70 | + ]); | |
| 71 | + | |
| 72 | + return $dataProvider; | |
| 73 | + } | |
| 74 | +} | ... | ... |
| 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\BlogArticle */ | |
| 8 | +/* @var $form yii\widgets\ActiveForm */ | |
| 9 | +?> | |
| 10 | + | |
| 11 | +<div class="blog-article-form"> | |
| 12 | + | |
| 13 | + <?php $form = ActiveForm::begin(); ?> | |
| 14 | + | |
| 15 | + <?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?> | |
| 16 | + | |
| 17 | + <?= $form->field($model, 'created_at')->textInput() ?> | |
| 18 | + | |
| 19 | + <?= $form->field($model, 'updated_at')->textInput() ?> | |
| 20 | + | |
| 21 | + <?= $form->field($model, 'deleted_at')->textInput() ?> | |
| 22 | + | |
| 23 | + <?= $form->field($model, 'sort')->textInput() ?> | |
| 24 | + | |
| 25 | + <?= $form->field($model, 'status')->checkbox() ?> | |
| 26 | + | |
| 27 | + <?= $form->field($model, 'author_id')->textInput() ?> | |
| 28 | + | |
| 29 | + <div class="form-group"> | |
| 30 | + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
| 31 | + </div> | |
| 32 | + | |
| 33 | + <?php ActiveForm::end(); ?> | |
| 34 | + | |
| 35 | +</div> | ... | ... |
| 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 | + 'action' => ['index'], | |
| 15 | + 'method' => 'get', | |
| 16 | + ]); ?> | |
| 17 | + | |
| 18 | + <?= $form->field($model, 'id') ?> | |
| 19 | + | |
| 20 | + <?= $form->field($model, 'image') ?> | |
| 21 | + | |
| 22 | + <?= $form->field($model, 'created_at') ?> | |
| 23 | + | |
| 24 | + <?= $form->field($model, 'updated_at') ?> | |
| 25 | + | |
| 26 | + <?= $form->field($model, 'deleted_at') ?> | |
| 27 | + | |
| 28 | + <?php // echo $form->field($model, 'sort') ?> | |
| 29 | + | |
| 30 | + <?php // echo $form->field($model, 'status')->checkbox() ?> | |
| 31 | + | |
| 32 | + <?php // echo $form->field($model, 'author_id') ?> | |
| 33 | + | |
| 34 | + <div class="form-group"> | |
| 35 | + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | |
| 36 | + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | |
| 37 | + </div> | |
| 38 | + | |
| 39 | + <?php ActiveForm::end(); ?> | |
| 40 | + | |
| 41 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | + | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\modules\blog\models\BlogArticle */ | |
| 8 | + | |
| 9 | +$this->title = 'Create Blog Article'; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Articles', 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-article-create"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <?= $this->render('_form', [ | |
| 18 | + 'model' => $model, | |
| 19 | + ]) ?> | |
| 20 | + | |
| 21 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\grid\GridView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $searchModel common\modules\blog\models\BlogArticleSearch */ | |
| 8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
| 9 | + | |
| 10 | +$this->title = 'Blog Articles'; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-article-index"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
| 17 | + | |
| 18 | + <p> | |
| 19 | + <?= Html::a('Create Blog Article', ['create'], ['class' => 'btn btn-success']) ?> | |
| 20 | + </p> | |
| 21 | + <?= GridView::widget([ | |
| 22 | + 'dataProvider' => $dataProvider, | |
| 23 | + 'filterModel' => $searchModel, | |
| 24 | + 'columns' => [ | |
| 25 | + ['class' => 'yii\grid\SerialColumn'], | |
| 26 | + | |
| 27 | + 'id', | |
| 28 | + 'image', | |
| 29 | + 'created_at', | |
| 30 | + 'updated_at', | |
| 31 | + 'deleted_at', | |
| 32 | + // 'sort', | |
| 33 | + // 'status:boolean', | |
| 34 | + // 'author_id', | |
| 35 | + | |
| 36 | + ['class' => 'yii\grid\ActionColumn'], | |
| 37 | + ], | |
| 38 | + ]); ?> | |
| 39 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | + | |
| 5 | +/* @var $this yii\web\View */ | |
| 6 | +/* @var $model common\modules\blog\models\BlogArticle */ | |
| 7 | + | |
| 8 | +$this->title = 'Update Blog Article: ' . $model->id; | |
| 9 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Articles', 'url' => ['index']]; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | |
| 11 | +$this->params['breadcrumbs'][] = 'Update'; | |
| 12 | +?> | |
| 13 | +<div class="blog-article-update"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <?= $this->render('_form', [ | |
| 18 | + 'model' => $model, | |
| 19 | + ]) ?> | |
| 20 | + | |
| 21 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\widgets\DetailView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\modules\blog\models\BlogArticle */ | |
| 8 | + | |
| 9 | +$this->title = $model->id; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Articles', 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-article-view"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <p> | |
| 18 | + <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
| 19 | + <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | |
| 20 | + 'class' => 'btn btn-danger', | |
| 21 | + 'data' => [ | |
| 22 | + 'confirm' => 'Are you sure you want to delete this item?', | |
| 23 | + 'method' => 'post', | |
| 24 | + ], | |
| 25 | + ]) ?> | |
| 26 | + </p> | |
| 27 | + | |
| 28 | + <?= DetailView::widget([ | |
| 29 | + 'model' => $model, | |
| 30 | + 'attributes' => [ | |
| 31 | + 'id', | |
| 32 | + 'image', | |
| 33 | + 'created_at', | |
| 34 | + 'updated_at', | |
| 35 | + 'deleted_at', | |
| 36 | + 'sort', | |
| 37 | + 'status:boolean', | |
| 38 | + 'author_id', | |
| 39 | + ], | |
| 40 | + ]) ?> | |
| 41 | + | |
| 42 | +</div> | ... | ... |
| 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\BlogCategory */ | |
| 8 | +/* @var $form yii\widgets\ActiveForm */ | |
| 9 | +?> | |
| 10 | + | |
| 11 | +<div class="blog-category-form"> | |
| 12 | + | |
| 13 | + <?php $form = ActiveForm::begin(); ?> | |
| 14 | + | |
| 15 | + <?= $form->field($model, 'sort')->textInput() ?> | |
| 16 | + | |
| 17 | + <?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?> | |
| 18 | + | |
| 19 | + <?= $form->field($model, 'parent_id')->textInput() ?> | |
| 20 | + | |
| 21 | + <?= $form->field($model, 'status')->checkbox() ?> | |
| 22 | + | |
| 23 | + <div class="form-group"> | |
| 24 | + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
| 25 | + </div> | |
| 26 | + | |
| 27 | + <?php ActiveForm::end(); ?> | |
| 28 | + | |
| 29 | +</div> | ... | ... |
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 yii\helpers\Html; | |
| 4 | + | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\modules\blog\models\BlogCategory */ | |
| 8 | + | |
| 9 | +$this->title = 'Create Blog Category'; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Categories', 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-category-create"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <?= $this->render('_form', [ | |
| 18 | + 'model' => $model, | |
| 19 | + ]) ?> | |
| 20 | + | |
| 21 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\grid\GridView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $searchModel common\modules\blog\models\BlogCategorySearch */ | |
| 8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
| 9 | + | |
| 10 | +$this->title = 'Blog Categories'; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-category-index"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
| 17 | + | |
| 18 | + <p> | |
| 19 | + <?= Html::a('Create Blog Category', ['create'], ['class' => 'btn btn-success']) ?> | |
| 20 | + </p> | |
| 21 | + <?= GridView::widget([ | |
| 22 | + 'dataProvider' => $dataProvider, | |
| 23 | + 'filterModel' => $searchModel, | |
| 24 | + 'columns' => [ | |
| 25 | + ['class' => 'yii\grid\SerialColumn'], | |
| 26 | + | |
| 27 | + 'id', | |
| 28 | + 'sort', | |
| 29 | + 'image', | |
| 30 | + 'parent_id', | |
| 31 | + 'status:boolean', | |
| 32 | + | |
| 33 | + ['class' => 'yii\grid\ActionColumn'], | |
| 34 | + ], | |
| 35 | + ]); ?> | |
| 36 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | + | |
| 5 | +/* @var $this yii\web\View */ | |
| 6 | +/* @var $model common\modules\blog\models\BlogCategory */ | |
| 7 | + | |
| 8 | +$this->title = 'Update Blog Category: ' . $model->id; | |
| 9 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Categories', 'url' => ['index']]; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | |
| 11 | +$this->params['breadcrumbs'][] = 'Update'; | |
| 12 | +?> | |
| 13 | +<div class="blog-category-update"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <?= $this->render('_form', [ | |
| 18 | + 'model' => $model, | |
| 19 | + ]) ?> | |
| 20 | + | |
| 21 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\widgets\DetailView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\modules\blog\models\BlogCategory */ | |
| 8 | + | |
| 9 | +$this->title = $model->id; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Categories', 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-category-view"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <p> | |
| 18 | + <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
| 19 | + <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | |
| 20 | + 'class' => 'btn btn-danger', | |
| 21 | + 'data' => [ | |
| 22 | + 'confirm' => 'Are you sure you want to delete this item?', | |
| 23 | + 'method' => 'post', | |
| 24 | + ], | |
| 25 | + ]) ?> | |
| 26 | + </p> | |
| 27 | + | |
| 28 | + <?= DetailView::widget([ | |
| 29 | + 'model' => $model, | |
| 30 | + 'attributes' => [ | |
| 31 | + 'id', | |
| 32 | + 'sort', | |
| 33 | + 'image', | |
| 34 | + 'parent_id', | |
| 35 | + 'status:boolean', | |
| 36 | + ], | |
| 37 | + ]) ?> | |
| 38 | + | |
| 39 | +</div> | ... | ... |
| 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\BlogTag */ | |
| 8 | +/* @var $form yii\widgets\ActiveForm */ | |
| 9 | +?> | |
| 10 | + | |
| 11 | +<div class="blog-tag-form"> | |
| 12 | + | |
| 13 | + <?php $form = ActiveForm::begin(); ?> | |
| 14 | + | |
| 15 | + <?= $form->field($model, 'id')->textInput() ?> | |
| 16 | + | |
| 17 | + <div class="form-group"> | |
| 18 | + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
| 19 | + </div> | |
| 20 | + | |
| 21 | + <?php ActiveForm::end(); ?> | |
| 22 | + | |
| 23 | +</div> | ... | ... |
| 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 yii\helpers\Html; | |
| 4 | + | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\modules\blog\models\BlogTag */ | |
| 8 | + | |
| 9 | +$this->title = 'Create Blog Tag'; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Tags', 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-tag-create"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <?= $this->render('_form', [ | |
| 18 | + 'model' => $model, | |
| 19 | + ]) ?> | |
| 20 | + | |
| 21 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\grid\GridView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $searchModel common\modules\blog\models\BlogTagSearch */ | |
| 8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
| 9 | + | |
| 10 | +$this->title = 'Blog Tags'; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-tag-index"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
| 17 | + | |
| 18 | + <p> | |
| 19 | + <?= Html::a('Create Blog Tag', ['create'], ['class' => 'btn btn-success']) ?> | |
| 20 | + </p> | |
| 21 | + <?= GridView::widget([ | |
| 22 | + 'dataProvider' => $dataProvider, | |
| 23 | + 'filterModel' => $searchModel, | |
| 24 | + 'columns' => [ | |
| 25 | + ['class' => 'yii\grid\SerialColumn'], | |
| 26 | + | |
| 27 | + 'id', | |
| 28 | + | |
| 29 | + ['class' => 'yii\grid\ActionColumn'], | |
| 30 | + ], | |
| 31 | + ]); ?> | |
| 32 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | + | |
| 5 | +/* @var $this yii\web\View */ | |
| 6 | +/* @var $model common\modules\blog\models\BlogTag */ | |
| 7 | + | |
| 8 | +$this->title = 'Update Blog Tag: ' . $model->id; | |
| 9 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Tags', 'url' => ['index']]; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | |
| 11 | +$this->params['breadcrumbs'][] = 'Update'; | |
| 12 | +?> | |
| 13 | +<div class="blog-tag-update"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <?= $this->render('_form', [ | |
| 18 | + 'model' => $model, | |
| 19 | + ]) ?> | |
| 20 | + | |
| 21 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\helpers\Html; | |
| 4 | +use yii\widgets\DetailView; | |
| 5 | + | |
| 6 | +/* @var $this yii\web\View */ | |
| 7 | +/* @var $model common\modules\blog\models\BlogTag */ | |
| 8 | + | |
| 9 | +$this->title = $model->id; | |
| 10 | +$this->params['breadcrumbs'][] = ['label' => 'Blog Tags', 'url' => ['index']]; | |
| 11 | +$this->params['breadcrumbs'][] = $this->title; | |
| 12 | +?> | |
| 13 | +<div class="blog-tag-view"> | |
| 14 | + | |
| 15 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 16 | + | |
| 17 | + <p> | |
| 18 | + <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
| 19 | + <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | |
| 20 | + 'class' => 'btn btn-danger', | |
| 21 | + 'data' => [ | |
| 22 | + 'confirm' => 'Are you sure you want to delete this item?', | |
| 23 | + 'method' => 'post', | |
| 24 | + ], | |
| 25 | + ]) ?> | |
| 26 | + </p> | |
| 27 | + | |
| 28 | + <?= DetailView::widget([ | |
| 29 | + 'model' => $model, | |
| 30 | + 'attributes' => [ | |
| 31 | + 'id', | |
| 32 | + ], | |
| 33 | + ]) ?> | |
| 34 | + | |
| 35 | +</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> | ... | ... |
console/migrations/m161031_160156_blog.php renamed to console/migrations/blog/m161101_142334_blog_article.php
100644 → 100755
| 1 | 1 | <?php |
| 2 | - | |
| 3 | - use yii\db\Migration; | |
| 4 | - | |
| 5 | - class m161031_160156_blog extends Migration | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_142334_blog_article extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 6 | 8 | { |
| 7 | - | |
| 8 | - public function up() | |
| 9 | - { | |
| 10 | - $this->createTable( | |
| 11 | - 'blog_article', | |
| 12 | - [ | |
| 13 | - 'id' => $this->primaryKey(), | |
| 14 | - 'image' => $this->string(255), | |
| 15 | - 'created_at' => $this->integer(), | |
| 16 | - 'updated_at' => $this->integer(), | |
| 17 | - 'deleted_at' => $this->integer(), | |
| 18 | - 'sort' => $this->integer(), | |
| 19 | - 'status' => $this->boolean(), | |
| 20 | - 'author_id' => $this->integer(), | |
| 21 | - ] | |
| 22 | - ); | |
| 23 | - | |
| 24 | - $this->createTable( | |
| 25 | - 'blog_article_lang', | |
| 26 | - [ | |
| 27 | - 'title' => $this->string(255), | |
| 28 | - 'body' => $this->text(), | |
| 29 | - 'body_preview' => $this->text(), | |
| 30 | - 'alias' => $this->string(255), | |
| 31 | - 'meta_title' => $this->string(255), | |
| 32 | - 'meta_description' => $this->string(255), | |
| 33 | - 'h1' => $this->string(255), | |
| 34 | - 'seo_text' => $this->string(255), | |
| 35 | - ] | |
| 36 | - ); | |
| 37 | - } | |
| 38 | - | |
| 39 | - public function down() | |
| 40 | - { | |
| 41 | - | |
| 42 | - } | |
| 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 | + ); | |
| 43 | 25 | } |
| 26 | + | |
| 27 | + public function down() | |
| 28 | + { | |
| 29 | + $this->dropTable('blog_article'); | |
| 30 | + } | |
| 31 | +} | ... | ... |
console/migrations/blog/m161101_142752_blog_article_lang.php
0 → 100755
| 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 → 100755
| 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 → 100755
| 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 → 100755
| 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 → 100755
| 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 → 100755
| 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 → 100755
| 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 → 100755
| 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 → 100755
| 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 | +} | ... | ... |