diff --git a/common/models/Book.php b/common/models/Book.php index 4f53eba..aa6d0cc 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'])->where(['status' => true])->orderBy('created_at'); + return $this->hasMany(Comment::className(), ['book_id' => 'id'])->with('activeComments')->where(['status' => true, 'parent_id' => null])->orderBy('created_at'); } } diff --git a/common/models/Comment.php b/common/models/Comment.php index 65dc7e5..c6d0e77 100644 --- a/common/models/Comment.php +++ b/common/models/Comment.php @@ -130,4 +130,8 @@ { return $this->hasMany(Comment::className(), [ 'parent_id' => 'id' ]); } + + public function getActiveComments(){ + return $this->getComments()->where(['status' => true]); + } } diff --git a/frontend/config/main.php b/frontend/config/main.php index b1b1d45..8c45fd0 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -139,6 +139,118 @@ }', ], + 'comments' => [ + 'class' => 'artbox\core\forms\Module', + 'activeRecord' => "common\models\Comment", + 'attributes' => [ + 'name', + 'email', + 'comment', + 'book_id', + 'parent_id' + ], + 'templateForm' => '
Ваш коментар з\'явиться після перевірки модератором
") + $("#comment-form").remove(); + + }', + + ], + 'commentsChild' => [ + 'class' => 'artbox\core\forms\Module', + 'activeRecord' => "common\models\Comment", + 'attributes' => [ + 'name', + 'email', + 'comment', + 'book_id', + 'parent_id' + ], + 'templateForm' => 'Ваш коментар з\'явиться після перевірки модератором
") + $("#answer-form").remove(); + + }', + + ], ], 'components' => [ 'user' => [ diff --git a/frontend/controllers/BookController.php b/frontend/controllers/BookController.php index c3a7bc6..3e56201 100644 --- a/frontend/controllers/BookController.php +++ b/frontend/controllers/BookController.php @@ -99,7 +99,7 @@ } public function actionView($id){ - $model = Book::find()->with('author') ->where(['id' => $id])->one(); + $model = Book::find()->with(['author', 'activeComments']) ->where(['id' => $id])->one(); return $this->render('view', ['model' => $model]); } } \ No newline at end of file diff --git a/frontend/views/book/view.php b/frontend/views/book/view.php index 65274a0..189a463 100644 --- a/frontend/views/book/view.php +++ b/frontend/views/book/view.php @@ -12,6 +12,30 @@ ]; $this->params['breadcrumbs'][] = $model->title; + + /** + * @var \artbox\core\forms\Module $module + * @var \artbox\core\forms\Module $moduleAnswer + */ + $module = \Yii::$app->getModule('comments'); + $module->inputOptions += ['book_id' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => $model->id], + ]]; + $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' => ''], + ]]; ?>