From 6fc26f8f9b69c5c1a7ffc4887cc2ec7f359c58da Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 7 May 2018 16:32:42 +0300 Subject: [PATCH] - slider - events - gallery --- backend/controllers/EventController.php | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/controllers/EventTagController.php | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/controllers/GalleryController.php | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/controllers/SlideController.php | 19 ++++++++++++++++++- backend/views/layouts/menu_items.php | 5 +++++ common/models/Gallery.php | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/GalleryLang.php | 38 ++++++++++++++++++++++++++++++++++++++ common/models/blog/Article.php | 30 +++++++++++++++--------------- common/models/blog/ArticleLang.php | 2 +- common/models/blog/Category.php | 2 +- common/models/blog/Tag.php | 2 +- common/models/event/Event.php | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/event/EventLang.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/event/Tag.php | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/event/TagLang.php | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/slider/Slide.php | 18 ++++++++++++++++++ common/models/slider/SlideLang.php | 11 +++++------ console/migrations/m180507_115504_create_gallery_table.php | 30 ++++++++++++++++++++++++++++++ console/migrations/m180507_120119_create_gallery_lang_table.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m180507_122728_create_event_table.php | 34 ++++++++++++++++++++++++++++++++++ console/migrations/m180507_123248_create_event_lang_table.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m180507_123642_create_event_tag_table.php | 28 ++++++++++++++++++++++++++++ console/migrations/m180507_123737_create_event_tag_lang_table.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m180507_124405_create_event_to_tag_table.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m180507_131039_alter_tables_slide.php | 42 ++++++++++++++++++++++++++++++++++++++++++ frontend/controllers/BlogController.php | 12 ++++++------ frontend/controllers/SiteController.php | 10 +++++----- frontend/views/blog/view.php | 4 ++-- frontend/views/layouts/main.php | 5 +++++ frontend/views/site/index.php | 2 +- 30 files changed, 1600 insertions(+), 39 deletions(-) create mode 100644 backend/controllers/EventController.php create mode 100644 backend/controllers/EventTagController.php create mode 100644 backend/controllers/GalleryController.php create mode 100644 common/models/Gallery.php create mode 100644 common/models/GalleryLang.php create mode 100755 common/models/event/Event.php create mode 100755 common/models/event/EventLang.php create mode 100755 common/models/event/Tag.php create mode 100755 common/models/event/TagLang.php create mode 100644 console/migrations/m180507_115504_create_gallery_table.php create mode 100644 console/migrations/m180507_120119_create_gallery_lang_table.php create mode 100644 console/migrations/m180507_122728_create_event_table.php create mode 100644 console/migrations/m180507_123248_create_event_lang_table.php create mode 100644 console/migrations/m180507_123642_create_event_tag_table.php create mode 100644 console/migrations/m180507_123737_create_event_tag_lang_table.php create mode 100644 console/migrations/m180507_124405_create_event_to_tag_table.php create mode 100644 console/migrations/m180507_131039_alter_tables_slide.php diff --git a/backend/controllers/EventController.php b/backend/controllers/EventController.php new file mode 100644 index 0000000..113960e --- /dev/null +++ b/backend/controllers/EventController.php @@ -0,0 +1,202 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'title' => [ + 'type' => Index::ACTION_COL, + ], + 'tags' => [ + 'type' => Index::RELATION_COL, + 'columnConfig' => [ + 'relationField' => 'title', + ], + ], + 'created_at' => [ + 'type' => Index::DATETIME_COL, + ], + 'sort' => [ + 'type' => Index::POSITION_COL, + ], + 'status' => [ + 'type' => Index::STATUS_COL, + ], + ], + 'model' => Event::className(), + 'hasLanguage' => true, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + ], + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), + 'view' => [ + 'class' => View::className(), + 'model' => Event::className(), + 'hasAlias' => true, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ], + [ + 'name' => 'body', + 'type' => Form::WYSIWYG, + ], + [ + 'name' => 'body_preview', + 'type' => Form::TEXTAREA, + ], + ], + 'fields' => [ + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + [ + 'name' => 'tagIds', + 'type' => Form::RELATION, + 'relationAttribute' => 'label', + 'relationName' => 'tags', + 'multiple' => true, + ], + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + $model = Event::find() + ->with('languages') + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function newModel() + { + return new Event(); + } + + public function deleteModel($id) + { + $page = Event::find() + ->with('languages.alias') + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + $langs = call_user_func( + [ + $page, + 'getVariationModels', + ] + ); + foreach ($langs as $lang) { + if ($lang->alias !== null) { + $lang->alias->delete(); + } + } + + return $page->delete(); + } + + protected static function fieldsConfig() + { + return [ + 'model' => Event::className(), + 'hasAlias' => true, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ], + [ + 'name' => 'body', + 'type' => Form::WYSIWYG, + ], + [ + 'name' => 'body_preview', + 'type' => Form::TEXTAREA, + ], + ], + 'fields' => [ + + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + [ + 'name' => 'tagIds', + 'type' => Form::RELATION, + 'relationAttribute' => 'title', + 'relationName' => 'tags', + 'multiple' => true, + ], + [ + 'name' => 'status', + 'type' => Form::BOOL, + ], + [ + 'name' => 'sort', + 'type' => Form::NUMBER, + ], + ], + ]; + } + } \ No newline at end of file diff --git a/backend/controllers/EventTagController.php b/backend/controllers/EventTagController.php new file mode 100644 index 0000000..876530c --- /dev/null +++ b/backend/controllers/EventTagController.php @@ -0,0 +1,149 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'title' => [ + 'type' => Index::ACTION_COL, + ], + 'sort' => [ + 'type' => Index::POSITION_COL, + ], + ], + 'model' => Tag::className(), + 'hasLanguage' => true, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + ], + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), + 'view' => [ + 'class' => View::className(), + 'model' => Tag::className(), + 'hasAlias' => true, + 'hasGallery' => false, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ] + ], + 'fields' => [ + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + $model = Tag::find() + ->with('languages') + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function newModel() + { + return new Tag(); + } + + public function deleteModel($id) + { + $category = Tag::find() + ->with('languages.alias') + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + $langs = call_user_func( + [ + $category, + 'getVariationModels', + ] + ); + foreach ($langs as $lang) { + if ($lang->alias !== null) { + $lang->alias->delete(); + } + } + + return $category->delete(); + } + + protected static function fieldsConfig() + { + return [ + 'model' => Tag::className(), + 'hasAlias' => true, + 'hasGallery' => false, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ] + ], + 'fields' => [ + [ + 'name' => 'sort', + 'type' => Form::NUMBER, + ], + ], + ]; + } + } \ No newline at end of file diff --git a/backend/controllers/GalleryController.php b/backend/controllers/GalleryController.php new file mode 100644 index 0000000..5022b08 --- /dev/null +++ b/backend/controllers/GalleryController.php @@ -0,0 +1,153 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'title' => [ + 'type' => Index::ACTION_COL + ], + 'sort' => [ + 'type' => Index::POSITION_COL, + ], + 'status' => [ + 'type' => Index::STATUS_COL + ] + ], + 'model' => Gallery::className(), + 'hasLanguage' => true, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + ], + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), + 'view' => [ + 'class' => View::className(), + 'model' => Gallery::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ] + ], + 'fields' => [ + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + $model = Gallery::find() + ->with('languages') + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function newModel() + { + return new Gallery(); + } + + public function deleteModel($id) + { + $page = Gallery::find() + ->with('languages') + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + + return $page->delete(); + } + + protected static function fieldsConfig() + { + return [ + 'model' => Gallery::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ], + ], + 'fields' => [ + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + [ + 'name' => 'status', + 'type' => Form::BOOL, + ], + [ + 'name' => 'sort', + 'type' => Form::NUMBER, + ], + ], + ]; + } + } \ No newline at end of file diff --git a/backend/controllers/SlideController.php b/backend/controllers/SlideController.php index 49b5c96..e959ac5 100644 --- a/backend/controllers/SlideController.php +++ b/backend/controllers/SlideController.php @@ -78,7 +78,12 @@ [ 'name' => 'title', 'type' => Form::STRING, - ],[ + ], + [ + 'name' => 'description', + 'type' => Form::TEXTAREA, + ], + [ 'name' => 'link', 'type' => Form::STRING, ], @@ -96,6 +101,10 @@ [ 'name' => 'sort', 'type' => Form::NUMBER, + ], + [ + 'name' => 'background_id', + 'type' => Form::IMAGE, ] ], ], @@ -163,6 +172,10 @@ 'type' => Form::STRING, ], [ + 'name' => 'description', + 'type' => Form::TEXTAREA, + ], + [ 'name' => 'link', 'type' => Form::STRING, ], @@ -170,6 +183,10 @@ ], 'fields' => [ [ + 'name' => 'background_id', + 'type' => Form::IMAGE, + ], + [ 'name' => 'status', 'type' => Form::BOOL, ], diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index 439680a..24c01c8 100755 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -45,6 +45,11 @@ 'url' => [ '/page-category/index' ], ], + [ + 'label' => \Yii::t('core', 'Gallery'), + 'url' => [ '/gallery/index' ], + + ], ], ], diff --git a/common/models/Gallery.php b/common/models/Gallery.php new file mode 100644 index 0000000..05e3ec1 --- /dev/null +++ b/common/models/Gallery.php @@ -0,0 +1,105 @@ + [ + 'class' => VariationBehavior::className(), + 'variationsRelation' => 'languages', + 'defaultVariationRelation' => 'language', + 'variationOptionReferenceAttribute' => 'language_id', + 'optionModelClass' => Language::className(), + 'defaultVariationOptionReference' => function () { + return Language::getCurrent()->id; + }, + 'optionQueryFilter' => function (ActiveQuery $query) { + $query->where( + [ + 'status' => true, + ] + ); + }, + ], + 'positionBehavior' => [ + 'class' => PositionBehavior::className(), + 'positionAttribute' => 'sort', + ], + ]; + } + + public static function tableName() + { + return 'gallery'; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguages() + { + return $this->hasMany(GalleryLang::className(), [ 'gallery_id' => 'id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasDefaultVariationRelation(); + } + + public function attributeLabels() + { + return [ + 'title' => \Yii::t('core', 'Title'), + 'status' => \Yii::t('core', 'Status'), + 'sort' => \Yii::t('core', 'Sort'), + 'image_id' => \Yii::t('core', 'Image'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getImage() + { + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); + } + + + } \ No newline at end of file diff --git a/common/models/GalleryLang.php b/common/models/GalleryLang.php new file mode 100644 index 0000000..c0c2085 --- /dev/null +++ b/common/models/GalleryLang.php @@ -0,0 +1,38 @@ + \Yii::t('core', 'Title'), + ]; + } + } \ No newline at end of file diff --git a/common/models/blog/Article.php b/common/models/blog/Article.php index 34d8789..b452227 100755 --- a/common/models/blog/Article.php +++ b/common/models/blog/Article.php @@ -18,22 +18,22 @@ /** * This is the model class for table "blog_article". * - * @property integer $id - * @property Image $image - * @property integer $created_at - * @property integer $updated_at - * @property integer $deleted_at - * @property integer $sort - * @property boolean $status - * @property integer $author_id - * @property integer $image_id + * @property integer $id + * @property Image $image + * @property integer $created_at + * @property integer $updated_at + * @property integer $deleted_at + * @property integer $sort + * @property boolean $status + * @property integer $author_id + * @property integer $image_id * @property ArticleLang[] $blogArticleLangs - * @property Language[] $languages - * @property Article[] $relatedBlogArticles - * @property Article[] $articles - * @property Category[] $categories - * @property Category $category - * @property Tag[] $tags + * @property Language[] $languages + * @property \common\models\blog\Article[] $relatedBlogArticles + * @property \common\models\blog\Article[] $articles + * @property Category[] $categories + * @property Category $category + * @property Tag[] $tags * * from VariationBehavior * @method ActiveQuery hasDefaultVariationRelation(); */ diff --git a/common/models/blog/ArticleLang.php b/common/models/blog/ArticleLang.php index 8dd5d8f..6a25288 100755 --- a/common/models/blog/ArticleLang.php +++ b/common/models/blog/ArticleLang.php @@ -19,7 +19,7 @@ * @property string $meta_description * @property string $h1 * @property string $seo_text - * @property Article $article + * @property Article $article * @property Language $language * @property Alias $alias */ diff --git a/common/models/blog/Category.php b/common/models/blog/Category.php index af7db14..599a984 100755 --- a/common/models/blog/Category.php +++ b/common/models/blog/Category.php @@ -18,7 +18,7 @@ * @property integer $sort * @property integer $parent_id * @property boolean $status - * @property Article[] $articles + * @property Article[] $articles * @property CategoryLang[] $blogCategoryLangs * @property Language[] $languages * @property Category $parent diff --git a/common/models/blog/Tag.php b/common/models/blog/Tag.php index ab5185c..6c5e3ed 100755 --- a/common/models/blog/Tag.php +++ b/common/models/blog/Tag.php @@ -14,7 +14,7 @@ * This is the model class for table "blog_tag". * * @property integer $id - * @property Article[] $articles + * @property Article[] $articles * @property TagLang[] $blogTagLangs * @property Language[] $languages * * * from VariationBehavior diff --git a/common/models/event/Event.php b/common/models/event/Event.php new file mode 100755 index 0000000..6418f05 --- /dev/null +++ b/common/models/event/Event.php @@ -0,0 +1,184 @@ + [ + 'class' => VariationBehavior::className(), + 'variationsRelation' => 'languages', + 'defaultVariationRelation' => 'language', + 'variationOptionReferenceAttribute' => 'language_id', + 'optionModelClass' => Language::className(), + 'defaultVariationOptionReference' => function () { + return Language::getCurrent()->id; + }, + 'optionQueryFilter' => function (ActiveQuery $query) { + $query->where( + [ + 'status' => true, + ] + ); + }, + ], + 'positionBehavior' => [ + 'class' => PositionBehavior::className(), + 'positionAttribute' => 'sort', + ], + 'linkTagBehavior' => [ + 'class' => LinkManyBehavior::className(), + 'relation' => 'tags', + 'relationReferenceAttribute' => 'tagIds', + ], + 'timestamp' => [ + 'class' => TimestampBehavior::className(), + ], + ]; + } + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'created_at', + 'updated_at', + 'deleted_at', + 'sort', + 'author_id', + 'image_id', + ], + 'integer', + ], + [ + [ 'status' ], + 'boolean', + ], + + [ + [ + 'tagIds', + ], + 'safe', + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'image' => 'Image', + 'created_at' => 'Created At', + 'updated_at' => \Yii::t('core', 'Updated At'), + 'deleted_at' => 'Deleted At', + 'sort' => \Yii::t('core', 'Sort'), + 'status' => \Yii::t('core', 'Status'), + 'author_id' => 'Author ID', + 'title' => \Yii::t('core', 'Title'), + 'tags' => \Yii::t('core', 'Tags'), + + 'image_id' => \Yii::t('core', 'Image'), + 'tagIds' => \Yii::t('core', 'Tags'), + ]; + } + + public function getLanguages() + { + return $this->hasMany(EventLang::className(), [ 'event_id' => 'id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasDefaultVariationRelation(); + } + + + public function getRoute() + { + return Json::encode( + [ + 'event/view', + 'id' => $this->id, + ] + ); + } + + + + + + /** + * @return \yii\db\ActiveQuery + */ + public function getImage() + { + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); + } + + + + + /** + * @return \yii\db\ActiveQuery + */ + public function getTags() + { + return $this->hasMany(Tag::className(), [ 'id' => 'event_tag_id' ]) + ->viaTable('event_to_tag', [ 'event_id' => 'id' ]); + } + } diff --git a/common/models/event/EventLang.php b/common/models/event/EventLang.php new file mode 100755 index 0000000..d800281 --- /dev/null +++ b/common/models/event/EventLang.php @@ -0,0 +1,82 @@ + 80, + ], + + ]; + } + + public function attributeLabels() + { + return [ + 'title' => \Yii::t('core', 'Title'), + 'body' => \Yii::t('core', 'Body'), + 'body_preview' => \Yii::t('core', 'Body Preview'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getAlias() + { + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]); + } + } diff --git a/common/models/event/Tag.php b/common/models/event/Tag.php new file mode 100755 index 0000000..1c0b7c0 --- /dev/null +++ b/common/models/event/Tag.php @@ -0,0 +1,124 @@ + [ + 'class' => VariationBehavior::className(), + 'variationsRelation' => 'languages', + 'defaultVariationRelation' => 'language', + 'variationOptionReferenceAttribute' => 'language_id', + 'optionModelClass' => Language::className(), + 'defaultVariationOptionReference' => function () { + return Language::getCurrent()->id; + }, + 'optionQueryFilter' => function (ActiveQuery $query) { + $query->where( + [ + 'status' => true, + ] + ); + }, + ], + 'positionBehavior' => [ + 'class' => PositionBehavior::className(), + 'positionAttribute' => 'sort', + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'id', + 'sort', + ], + 'integer', + ], + ]; + } + public function getRoute() + { + return Json::encode( + [ + 'event/tag', + 'id' => $this->id, + ] + ); + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'label' => \Yii::t('core', 'Label'), + 'sort' => \Yii::t('core', 'Sort'), + ]; + } + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguages() + { + return $this->hasMany(TagLang::className(), [ 'blog_tag_id' => 'id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasDefaultVariationRelation(); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getArticles() + { + return $this->hasMany(Event::className(), [ 'id' => 'event_id' ]) + ->viaTable('event_to_tag', [ 'event_tag_id' => 'id' ]); + } + } diff --git a/common/models/event/TagLang.php b/common/models/event/TagLang.php new file mode 100755 index 0000000..fa5b0b7 --- /dev/null +++ b/common/models/event/TagLang.php @@ -0,0 +1,77 @@ + 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'blog_tag_id' => 'Blog Tag ID', + 'language_id' => 'Language ID', + 'title' => \Yii::t('core', 'Title'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTag() + { + return $this->hasOne(Tag::className(), [ 'id' => 'event_tag_id' ]); + } + + public function getAlias() + { + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); + } + } diff --git a/common/models/slider/Slide.php b/common/models/slider/Slide.php index f1fd3f1..36343cd 100644 --- a/common/models/slider/Slide.php +++ b/common/models/slider/Slide.php @@ -2,6 +2,7 @@ namespace common\models\slider; + use artbox\core\models\Image; use artbox\core\models\Language; use yii\db\ActiveQuery; use yii\db\ActiveRecord; @@ -72,6 +73,14 @@ [ 'status' ], 'boolean', ], + [ + [ 'background_id' ], + 'required', + ], + [ + [ 'background_id' ], + 'integer', + ], ]; } @@ -86,6 +95,7 @@ 'sort' => \Yii::t('core', 'Sort'), 'title' => \Yii::t('core', 'Title'), 'link' => \Yii::t('core', 'Link'), + 'background_id' => \Yii::t('core', 'Background'), ]; } @@ -110,4 +120,12 @@ return $this->hasMany(SlideLang::className(), [ 'slide_id' => 'id' ]) ->inverseOf('slide'); } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBackground() + { + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); + } } diff --git a/common/models/slider/SlideLang.php b/common/models/slider/SlideLang.php index dc5962b..ef311e3 100644 --- a/common/models/slider/SlideLang.php +++ b/common/models/slider/SlideLang.php @@ -39,12 +39,6 @@ [ 'image_id', ], - 'required', - ], - [ - [ - 'image_id', - ], 'integer', ], [ @@ -55,6 +49,10 @@ 'string', 'max' => 255, ], + [ + [ 'description' ], + 'string' + ] ]; } @@ -69,6 +67,7 @@ 'link' => Yii::t('core', 'Link'), 'image_id' => Yii::t('core', 'Image'), 'title' => Yii::t('core', 'Title'), + 'description' => Yii::t('core', 'Description'), ]; } diff --git a/console/migrations/m180507_115504_create_gallery_table.php b/console/migrations/m180507_115504_create_gallery_table.php new file mode 100644 index 0000000..11ef446 --- /dev/null +++ b/console/migrations/m180507_115504_create_gallery_table.php @@ -0,0 +1,30 @@ +createTable('gallery', [ + 'id' => $this->primaryKey(), + 'image_id' => $this->integer(), + 'sort' => $this->integer(), + 'status' => $this->boolean(), + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('gallery'); + } +} diff --git a/console/migrations/m180507_120119_create_gallery_lang_table.php b/console/migrations/m180507_120119_create_gallery_lang_table.php new file mode 100644 index 0000000..b06373a --- /dev/null +++ b/console/migrations/m180507_120119_create_gallery_lang_table.php @@ -0,0 +1,56 @@ +createTable('gallery_lang', [ + 'gallery_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string(), + 'PRIMARY KEY(gallery_id, language_id)', + ]); + + + + $this->addForeignKey( + 'gallery_lang_fk', + 'gallery_lang', + 'language_id', + 'language', + 'id', + 'RESTRICT', + 'CASCADE' + ); + + $this->addForeignKey( + 'gallery_fk', + 'gallery_lang', + 'gallery_id', + 'gallery', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('gallery_lang_fk', 'gallery_lang'); + $this->dropForeignKey('gallery_fk', 'gallery_lang'); + $this->dropTable('gallery_lang'); + } +} diff --git a/console/migrations/m180507_122728_create_event_table.php b/console/migrations/m180507_122728_create_event_table.php new file mode 100644 index 0000000..70d52fd --- /dev/null +++ b/console/migrations/m180507_122728_create_event_table.php @@ -0,0 +1,34 @@ +createTable('event', [ + 'id' => $this->primaryKey(), + 'image_id' => $this->integer(), + 'created_at' => $this->integer(), + 'updated_at' => $this->integer(), + 'deleted_at' => $this->integer(), + 'sort' => $this->integer(), + 'status' => $this->boolean(), + 'author_id' => $this->integer(), + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('event'); + } +} diff --git a/console/migrations/m180507_123248_create_event_lang_table.php b/console/migrations/m180507_123248_create_event_lang_table.php new file mode 100644 index 0000000..b1bf5bf --- /dev/null +++ b/console/migrations/m180507_123248_create_event_lang_table.php @@ -0,0 +1,79 @@ +createTable('event_lang', [ + 'id' => $this->primaryKey(), + 'event_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string(255), + 'body' => $this->text(), + 'body_preview' => $this->text(), + 'alias_id' => $this->integer(), + ]); + + $this->createIndex( + 'event_lang_uk', + 'event_lang', + [ + 'event_id', + 'language_id', + ], + true + ); + + $this->createIndex( + 'event_alias_uk', + 'event_lang', + 'alias_id', + true + ); + + /** + * Add foreign keys in blog_articles and language tables + */ + $this->addForeignKey( + 'event_fk', + 'event_lang', + 'event_id', + 'event', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'event_lang_fk', + 'event_lang', + 'language_id', + 'language', + 'id', + 'RESTRICT', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('event_lang_fk', 'event_lang'); + $this->dropForeignKey('event_fk', 'event_lang'); + $this->dropIndex('event_alias_uk', 'event_lang'); + $this->dropIndex('event_lang_uk', 'event_lang'); + $this->dropTable('event_lang'); + } +} diff --git a/console/migrations/m180507_123642_create_event_tag_table.php b/console/migrations/m180507_123642_create_event_tag_table.php new file mode 100644 index 0000000..0437893 --- /dev/null +++ b/console/migrations/m180507_123642_create_event_tag_table.php @@ -0,0 +1,28 @@ +createTable('event_tag', [ + 'id' => $this->primaryKey(), + 'sort' => $this->integer() + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('event_tag'); + } +} diff --git a/console/migrations/m180507_123737_create_event_tag_lang_table.php b/console/migrations/m180507_123737_create_event_tag_lang_table.php new file mode 100644 index 0000000..520d2e3 --- /dev/null +++ b/console/migrations/m180507_123737_create_event_tag_lang_table.php @@ -0,0 +1,68 @@ +createTable('event_tag_lang', [ + 'id' => $this->primaryKey(), + 'event_tag_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'alias_id' => $this->integer(), + 'label' => $this->string(255), + ]); + + $this->createIndex( + 'event_tag_lang_uk', + 'event_tag_lang', + [ + 'event_tag_id', + 'language_id', + ], + true + ); + + $this->createIndex('event_tag_lang_auk', 'event_tag_lang', 'alias_id', true); + + $this->addForeignKey( + 'event_tag_lang_fk', + 'event_tag_lang', + 'language_id', + 'language', + 'id', + 'RESTRICT', + 'CASCADE' + ); + + $this->addForeignKey( + 'event_tag_fk', + 'event_tag_lang', + 'event_tag_id', + 'event_tag', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('event_tag_fk', 'event_tag_lang'); + $this->dropForeignKey('event_tag_lang_fk', 'event_tag_lang'); + $this->dropIndex('event_tag_lang_uk', 'event_tag_lang'); + $this->dropTable('event_tag_lang'); + } +} diff --git a/console/migrations/m180507_124405_create_event_to_tag_table.php b/console/migrations/m180507_124405_create_event_to_tag_table.php new file mode 100644 index 0000000..a5953ca --- /dev/null +++ b/console/migrations/m180507_124405_create_event_to_tag_table.php @@ -0,0 +1,66 @@ +createTable('event_to_tag', [ + 'event_id' => $this->integer() + ->notNull(), + 'event_tag_id' => $this->integer() + ->notNull(), + ]); + + /** + * Create indexes and foreign keys for junction table + */ + $this->createIndex( + 'event_to_tag_uk', + 'event_to_tag', + [ + 'event_id', + 'event_tag_id', + ], + true + ); + + $this->addForeignKey( + 'event_to_tag_tag_fk', + 'event_to_tag', + 'event_tag_id', + 'event_tag', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'event_to_tag_art_fk', + 'event_to_tag', + 'event_id', + 'event', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('event_to_tag_art_fk', 'event_to_tag'); + $this->dropForeignKey('event_to_tag_tag_fk', 'event_to_tag'); + $this->dropIndex('event_to_tag_uk', 'event_to_tag'); + $this->dropTable('event_to_tag'); + } +} diff --git a/console/migrations/m180507_131039_alter_tables_slide.php b/console/migrations/m180507_131039_alter_tables_slide.php new file mode 100644 index 0000000..6611a61 --- /dev/null +++ b/console/migrations/m180507_131039_alter_tables_slide.php @@ -0,0 +1,42 @@ +addColumn('slide', 'background_id', $this->integer()); + $this->addColumn('slide_lang', 'description', $this->text()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('slide', 'background_id'); + $this->dropColumn('slide_lang', 'description'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m180507_131039_alter_tables_slide cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/frontend/controllers/BlogController.php b/frontend/controllers/BlogController.php index 4838273..f182664 100755 --- a/frontend/controllers/BlogController.php +++ b/frontend/controllers/BlogController.php @@ -40,12 +40,12 @@ $dataProvider = new ActiveDataProvider( [ 'query' => Article::find() - ->orderBy( + ->orderBy( [ 'created_at' => SORT_DESC, ] ) - ->with( + ->with( [ 'categories.language', ] @@ -225,16 +225,16 @@ * @var Article | null $model */ $model = Article::find() - ->where([ 'id' => $id ]) - ->with( + ->where([ 'id' => $id ]) + ->with( [ 'language', 'categories.language', 'tags.language', ] ) - ->andWhere([ 'status' => true ]) - ->one(); + ->andWhere([ 'status' => true ]) + ->one(); if (empty($model)) { throw new NotFoundHttpException(\Yii::t('app', 'Article not found')); diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 7eaa6aa..192433f 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -53,11 +53,11 @@ { $slides = Slide::find()->with('language')->where(['status' => true])->orderBy('sort')->all(); $articles = Article::find() - ->with('language') - ->where([ 'status' => true ]) - ->orderBy('sort DESC') - ->limit(4) - ->all(); + ->with('language') + ->where([ 'status' => true ]) + ->orderBy('sort DESC') + ->limit(4) + ->all(); return $this->render('index', [ 'slides' => $slides, 'articles' => $articles diff --git a/frontend/views/blog/view.php b/frontend/views/blog/view.php index a1a0caf..e5ea3df 100755 --- a/frontend/views/blog/view.php +++ b/frontend/views/blog/view.php @@ -7,9 +7,9 @@ use yii\web\View; /** - * @var View $this + * @var View $this * @var Article $model - * @var Tag[] $tags + * @var Tag[] $tags */ $this->params[ 'breadcrumbs' ][] = [ diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index c219683..1f66c77 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -250,6 +250,11 @@ _________________________________________________________ --> } else { echo ' href="/en"'; } ?>>en + >ua diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index a366135..91d32ce 100755 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -2,7 +2,7 @@ /* @var $this yii\web\View * @var \common\models\slider\Slide[] $slides; - * @var \common\models\blog\Article[] $articles + * @var \common\models\blog\Article[] $articles */ use artbox\core\helpers\ImageHelper; -- libgit2 0.21.4