Commit fd5e93c2822b728adca597ce562526eec4524ff0

Authored by Yarik
1 parent faff2c48

Artbox comment premoderate

@@ -62,7 +62,14 @@ @@ -62,7 +62,14 @@
62 * 62 *
63 * @var bool 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 * Initializes the module. 75 * Initializes the module.
@@ -76,7 +83,7 @@ @@ -76,7 +83,7 @@
76 if ($this->commentModelClass === null) { 83 if ($this->commentModelClass === null) {
77 $this->commentModelClass = CommentModel::className(); 84 $this->commentModelClass = CommentModel::className();
78 } 85 }
79 - if (self::$enableRating && $this->ratingModelClass === null) { 86 + if ($this->enableRating && $this->ratingModelClass === null) {
80 $this->ratingModelClass = RatingModel::className(); 87 $this->ratingModelClass = RatingModel::className();
81 } 88 }
82 if (\Yii::$app instanceof Application) { 89 if (\Yii::$app instanceof Application) {
controllers/DefaultController.php
@@ -79,7 +79,7 @@ @@ -79,7 +79,7 @@
79 if ($model->load(\Yii::$app->request->post())) { 79 if ($model->load(\Yii::$app->request->post())) {
80 $model->setAttributes($entity_data); 80 $model->setAttributes($entity_data);
81 if ($model->save()) { 81 if ($model->save()) {
82 - if (empty($model->parent_id) && $module::$enableRating) { 82 + if (empty($model->parent_id) && $module->enableRating) {
83 $ratingModelClass = $module->ratingModelClass; 83 $ratingModelClass = $module->ratingModelClass;
84 /** 84 /**
85 * @var RatingModel $rating 85 * @var RatingModel $rating
models/CommentModel.php
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 4
5 use artbox\webcomment\behaviors\ParentBehavior; 5 use artbox\webcomment\behaviors\ParentBehavior;
6 use artbox\webcomment\models\interfaces\CommentInterface; 6 use artbox\webcomment\models\interfaces\CommentInterface;
  7 + use artbox\webcomment\Module;
7 use yii\behaviors\AttributeBehavior; 8 use yii\behaviors\AttributeBehavior;
8 use yii\behaviors\BlameableBehavior; 9 use yii\behaviors\BlameableBehavior;
9 use yii\behaviors\TimestampBehavior; 10 use yii\behaviors\TimestampBehavior;
@@ -131,11 +132,6 @@ @@ -131,11 +132,6 @@
131 'integer', 132 'integer',
132 ], 133 ],
133 [ 134 [
134 - [ 'status' ],  
135 - 'default',  
136 - 'value' => 0,  
137 - ],  
138 - [  
139 [ 'parent_id' ], 135 [ 'parent_id' ],
140 'exist', 136 'exist',
141 'targetAttribute' => 'id', 137 'targetAttribute' => 'id',
@@ -168,6 +164,26 @@ @@ -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 'class' => ParentBehavior::className(), 187 'class' => ParentBehavior::className(),
172 ], 188 ],
173 ]; 189 ];
widgets/CommentWidget.php
@@ -254,7 +254,7 @@ @@ -254,7 +254,7 @@
254 ) ? CommentModel::SCENARIO_GUEST : CommentModel::SCENARIO_USER, 254 ) ? CommentModel::SCENARIO_GUEST : CommentModel::SCENARIO_USER,
255 ] 255 ]
256 ); 256 );
257 - if ($module::$enableRating) { 257 + if ($module->enableRating) {
258 $ratingModelClass = $module->ratingModelClass; 258 $ratingModelClass = $module->ratingModelClass;
259 $ratingModel = $this->createRating($ratingModelClass); 259 $ratingModel = $this->createRating($ratingModelClass);
260 } else { 260 } else {