Commit fd5e93c2822b728adca597ce562526eec4524ff0
1 parent
faff2c48
Artbox comment premoderate
Showing
4 changed files
with
32 additions
and
9 deletions
Show diff stats
Module.php
... | ... | @@ -62,7 +62,14 @@ |
62 | 62 | * |
63 | 63 | * @var bool |
64 | 64 | */ |
65 | - public static $enableRating = true; | |
65 | + public $enableRating = true; | |
66 | + | |
67 | + /** | |
68 | + * Whether to enable comment premoderate or not. | |
69 | + * | |
70 | + * @var bool | |
71 | + */ | |
72 | + public $enablePremoderate = true; | |
66 | 73 | |
67 | 74 | /** |
68 | 75 | * Initializes the module. |
... | ... | @@ -76,7 +83,7 @@ |
76 | 83 | if ($this->commentModelClass === null) { |
77 | 84 | $this->commentModelClass = CommentModel::className(); |
78 | 85 | } |
79 | - if (self::$enableRating && $this->ratingModelClass === null) { | |
86 | + if ($this->enableRating && $this->ratingModelClass === null) { | |
80 | 87 | $this->ratingModelClass = RatingModel::className(); |
81 | 88 | } |
82 | 89 | if (\Yii::$app instanceof Application) { | ... | ... |
controllers/DefaultController.php
... | ... | @@ -79,7 +79,7 @@ |
79 | 79 | if ($model->load(\Yii::$app->request->post())) { |
80 | 80 | $model->setAttributes($entity_data); |
81 | 81 | if ($model->save()) { |
82 | - if (empty($model->parent_id) && $module::$enableRating) { | |
82 | + if (empty($model->parent_id) && $module->enableRating) { | |
83 | 83 | $ratingModelClass = $module->ratingModelClass; |
84 | 84 | /** |
85 | 85 | * @var RatingModel $rating | ... | ... |
models/CommentModel.php
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | |
5 | 5 | use artbox\webcomment\behaviors\ParentBehavior; |
6 | 6 | use artbox\webcomment\models\interfaces\CommentInterface; |
7 | + use artbox\webcomment\Module; | |
7 | 8 | use yii\behaviors\AttributeBehavior; |
8 | 9 | use yii\behaviors\BlameableBehavior; |
9 | 10 | use yii\behaviors\TimestampBehavior; |
... | ... | @@ -131,11 +132,6 @@ |
131 | 132 | 'integer', |
132 | 133 | ], |
133 | 134 | [ |
134 | - [ 'status' ], | |
135 | - 'default', | |
136 | - 'value' => 0, | |
137 | - ], | |
138 | - [ | |
139 | 135 | [ 'parent_id' ], |
140 | 136 | 'exist', |
141 | 137 | 'targetAttribute' => 'id', |
... | ... | @@ -168,6 +164,26 @@ |
168 | 164 | }, |
169 | 165 | ], |
170 | 166 | [ |
167 | + 'class' => AttributeBehavior::className(), | |
168 | + 'attributes' => [ | |
169 | + ActiveRecord::EVENT_BEFORE_INSERT => 'status', | |
170 | + ], | |
171 | + 'value' => function () { | |
172 | + /** | |
173 | + * @var Module $module | |
174 | + */ | |
175 | + $module = \Yii::$app->getModule('artbox-comment'); | |
176 | + if (!$module) { | |
177 | + Module::registerMe(); | |
178 | + } | |
179 | + if ($module->enablePremoderate) { | |
180 | + return self::STATUS_HIDDEN; | |
181 | + } else { | |
182 | + return self::STATUS_ACTIVE; | |
183 | + } | |
184 | + }, | |
185 | + ], | |
186 | + [ | |
171 | 187 | 'class' => ParentBehavior::className(), |
172 | 188 | ], |
173 | 189 | ]; | ... | ... |
widgets/CommentWidget.php
... | ... | @@ -254,7 +254,7 @@ |
254 | 254 | ) ? CommentModel::SCENARIO_GUEST : CommentModel::SCENARIO_USER, |
255 | 255 | ] |
256 | 256 | ); |
257 | - if ($module::$enableRating) { | |
257 | + if ($module->enableRating) { | |
258 | 258 | $ratingModelClass = $module->ratingModelClass; |
259 | 259 | $ratingModel = $this->createRating($ratingModelClass); |
260 | 260 | } else { | ... | ... |