diff --git a/Module.php b/Module.php index 412d833..56fc799 100755 --- a/Module.php +++ b/Module.php @@ -62,7 +62,14 @@ * * @var bool */ - public static $enableRating = true; + public $enableRating = true; + + /** + * Whether to enable comment premoderate or not. + * + * @var bool + */ + public $enablePremoderate = true; /** * Initializes the module. @@ -76,7 +83,7 @@ if ($this->commentModelClass === null) { $this->commentModelClass = CommentModel::className(); } - if (self::$enableRating && $this->ratingModelClass === null) { + if ($this->enableRating && $this->ratingModelClass === null) { $this->ratingModelClass = RatingModel::className(); } if (\Yii::$app instanceof Application) { diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index 8d36503..6c7448a 100755 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -79,7 +79,7 @@ if ($model->load(\Yii::$app->request->post())) { $model->setAttributes($entity_data); if ($model->save()) { - if (empty($model->parent_id) && $module::$enableRating) { + if (empty($model->parent_id) && $module->enableRating) { $ratingModelClass = $module->ratingModelClass; /** * @var RatingModel $rating diff --git a/models/CommentModel.php b/models/CommentModel.php index 995f987..9007156 100755 --- a/models/CommentModel.php +++ b/models/CommentModel.php @@ -4,6 +4,7 @@ use artbox\webcomment\behaviors\ParentBehavior; use artbox\webcomment\models\interfaces\CommentInterface; + use artbox\webcomment\Module; use yii\behaviors\AttributeBehavior; use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; @@ -131,11 +132,6 @@ 'integer', ], [ - [ 'status' ], - 'default', - 'value' => 0, - ], - [ [ 'parent_id' ], 'exist', 'targetAttribute' => 'id', @@ -168,6 +164,26 @@ }, ], [ + 'class' => AttributeBehavior::className(), + 'attributes' => [ + ActiveRecord::EVENT_BEFORE_INSERT => 'status', + ], + 'value' => function () { + /** + * @var Module $module + */ + $module = \Yii::$app->getModule('artbox-comment'); + if (!$module) { + Module::registerMe(); + } + if ($module->enablePremoderate) { + return self::STATUS_HIDDEN; + } else { + return self::STATUS_ACTIVE; + } + }, + ], + [ 'class' => ParentBehavior::className(), ], ]; diff --git a/widgets/CommentWidget.php b/widgets/CommentWidget.php index 8872a56..65500c4 100755 --- a/widgets/CommentWidget.php +++ b/widgets/CommentWidget.php @@ -254,7 +254,7 @@ ) ? CommentModel::SCENARIO_GUEST : CommentModel::SCENARIO_USER, ] ); - if ($module::$enableRating) { + if ($module->enableRating) { $ratingModelClass = $module->ratingModelClass; $ratingModel = $this->createRating($ratingModelClass); } else { -- libgit2 0.21.4