diff --git a/common/models/Book.php b/common/models/Book.php index aa6d0cc..df99341 100644 --- a/common/models/Book.php +++ b/common/models/Book.php @@ -165,7 +165,7 @@ } public function getActiveComments(){ - return $this->hasMany(Comment::className(), ['book_id' => 'id'])->with('activeComments')->where(['status' => true, 'parent_id' => null])->orderBy('created_at'); + return $this->hasMany(Comment::className(), ['entity_id' => 'id'])->andWhere(['entity' => Book::className()])->with('activeComments')->where(['status' => true, 'parent_id' => null])->orderBy('created_at'); } } diff --git a/common/models/Comment.php b/common/models/Comment.php index c6d0e77..3cb1f8c 100644 --- a/common/models/Comment.php +++ b/common/models/Comment.php @@ -46,7 +46,7 @@ return [ [ [ - 'book_id', + 'entity_id', 'parent_id', ], 'default', @@ -54,13 +54,13 @@ ], [ [ - 'book_id', + 'entity_id', 'parent_id', ], 'integer', ], [ - [ 'comment' ], + [ 'comment', 'entity' ], 'string', ], [ @@ -76,13 +76,6 @@ 'max' => 255, ], [ - [ 'book_id' ], - 'exist', - 'skipOnError' => true, - 'targetClass' => Book::className(), - 'targetAttribute' => [ 'book_id' => 'id' ], - ], - [ [ 'parent_id' ], 'exist', 'skipOnError' => true, diff --git a/common/models/blog/Article.php b/common/models/blog/Article.php index 75dc47a..4674de0 100755 --- a/common/models/blog/Article.php +++ b/common/models/blog/Article.php @@ -4,6 +4,7 @@ use artbox\core\models\Image; use artbox\core\models\traits\AliasableTrait; + use common\models\Comment; use yii\behaviors\TimestampBehavior; use yii\db\ActiveRecord; use artbox\core\models\Language; @@ -262,4 +263,8 @@ return $this->hasMany(Tag::className(), [ 'id' => 'blog_tag_id' ]) ->viaTable('blog_article_to_tag', [ 'blog_article_id' => 'id' ]); } + + public function getActiveComments(){ + return $this->hasMany(Comment::className(), ['entity_id' => 'id'])->andWhere(['entity' => Article::className()])->with('activeComments')->where(['status' => true, 'parent_id' => null])->orderBy('created_at'); + } } diff --git a/console/migrations/m180621_144704_alter_table_page.php b/console/migrations/m180621_144704_alter_table_page.php new file mode 100644 index 0000000..5161daa --- /dev/null +++ b/console/migrations/m180621_144704_alter_table_page.php @@ -0,0 +1,31 @@ +dropColumn('page', 'created_at'); + $this->dropColumn('page', 'updated_at'); + $this->addColumn('page', 'created_at', $this->integer()); + $this->addColumn('page', 'updated_at', $this->integer()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m180621_144704_alter_table_page cannot be reverted.\n"; + + return false; + } + +} diff --git a/console/migrations/m180626_065650_alter_table_author.php b/console/migrations/m180626_065650_alter_table_author.php new file mode 100644 index 0000000..53555ef --- /dev/null +++ b/console/migrations/m180626_065650_alter_table_author.php @@ -0,0 +1,40 @@ +addColumn('author', 'avatar', $this->string()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('author', 'avatar'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m180626_065650_alter_table_author cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m180626_133815_alter_table_blog_article.php b/console/migrations/m180626_133815_alter_table_blog_article.php new file mode 100644 index 0000000..345b1ea --- /dev/null +++ b/console/migrations/m180626_133815_alter_table_blog_article.php @@ -0,0 +1,40 @@ +addColumn('blog_article', 'view', $this->integer()->defaultValue(0)); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('blog_article', 'view'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m180626_133815_alter_table_blog_article cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m180627_093149_alter_table_comments.php b/console/migrations/m180627_093149_alter_table_comments.php new file mode 100644 index 0000000..f5289d8 --- /dev/null +++ b/console/migrations/m180627_093149_alter_table_comments.php @@ -0,0 +1,45 @@ +dropForeignKey('comment_book_fk', 'comment'); + $this->dropColumn('comment', 'book_id'); + $this->addColumn('comment', 'entity', $this->string()); + $this->addColumn('comment', 'entity_id', $this->integer()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m180627_093149_alter_table_comments cannot be reverted.\n"; + + return false; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m180627_093149_alter_table_comments cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/frontend/config/main.php b/frontend/config/main.php index f92c48d..159a354 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -146,7 +146,8 @@ 'name', 'email', 'comment', - 'book_id', + 'entity_id', + 'entity', 'parent_id' ], 'templateForm' => '
Додати коментар
{form}', @@ -163,7 +164,8 @@ 'name' => 'Ім\'я', 'email' => 'Пошта', 'comment' => 'коментар', - 'book_id' => false, + 'entity_id' => false, + 'entity' => false, 'parent_id' => false ], @@ -202,7 +204,8 @@ 'name', 'email', 'comment', - 'book_id', + 'entity_id', + 'entity', 'parent_id' ], 'templateForm' => '
Відповісти
{form}', @@ -219,7 +222,8 @@ 'name' => 'Ім\'я', 'email' => 'Пошта', 'comment' => 'коментар', - 'book_id' => false, + 'entity_id' => false, + 'entity' => false, 'parent_id' => false ], diff --git a/frontend/controllers/BlogController.php b/frontend/controllers/BlogController.php index 3cacf6f..f4a9790 100755 --- a/frontend/controllers/BlogController.php +++ b/frontend/controllers/BlogController.php @@ -62,7 +62,8 @@ public function actionView($id) { $model = $this->findModel($id); - + $model->view +=1; + $model->save(); $tags = Tag::find() ->with([ 'language' ]) ->orderBy([ 'sort' => SORT_ASC ]) @@ -211,8 +212,10 @@ ->with( [ 'language', - 'categories.language', - 'tags.language', + 'tags.language.alias', + 'relatedBlogArticles.language.alias', + 'relatedBlogArticles.tags.language.alias', + 'activeComments' ] ) ->andWhere([ 'status' => true ]) diff --git a/frontend/views/blog/_article.php b/frontend/views/blog/_article.php index 104d58c..75ed73c 100755 --- a/frontend/views/blog/_article.php +++ b/frontend/views/blog/_article.php @@ -20,7 +20,7 @@
created_at)?> view?> переглядів - 48 коментарів + activeComments)?> коментарів
tags)){?>
diff --git a/frontend/views/blog/view.php b/frontend/views/blog/view.php index 125b1b1..45344c8 100755 --- a/frontend/views/blog/view.php +++ b/frontend/views/blog/view.php @@ -1,5 +1,6 @@ params[ 'breadcrumbs' ][] = [ @@ -17,207 +20,140 @@ 'url' => [ 'blog/index' ], ]; - $this->params[ 'breadcrumbs' ][] = $model->title; + $this->params[ 'breadcrumbs' ][] = $model->language->title; + + $module = \Yii::$app->getModule('comments'); + $module->inputOptions += ['entity_id' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => $model->id], + ]]; + $module->inputOptions += ['entity' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => \common\models\Book::class], + ]]; + $module->inputOptions += ['parent_id' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => ''], + ]]; + + $moduleAnswer = \Yii::$app->getModule('commentsChild'); + $moduleAnswer->inputOptions += ['book_id' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => $model->id], + ]]; + $moduleAnswer->inputOptions += ['parent_id' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => ''], + ]]; +?> ?> -
+
-
- - - -
- -

title; ?>

- - tags)) { ?> -
\ No newline at end of file diff --git a/frontend/views/book/view.php b/frontend/views/book/view.php index 60145d6..03366e0 100644 --- a/frontend/views/book/view.php +++ b/frontend/views/book/view.php @@ -18,10 +18,14 @@ * @var \artbox\core\forms\Module $moduleAnswer */ $module = \Yii::$app->getModule('comments'); - $module->inputOptions += ['book_id' => [ + $module->inputOptions += ['entity_id' => [ 'type' => 'hiddenInput', 'options' => ['value' => $model->id], ]]; + $module->inputOptions += ['entity' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => \common\models\Book::class], + ]]; $module->inputOptions += ['parent_id' => [ 'type' => 'hiddenInput', 'options' => ['value' => ''], diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index adf302b..2b922d2 100755 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -88,7 +88,7 @@