|
13 | 13 | use yii2mod\comments\Module; |
14 | 14 | use yii2mod\moderation\enums\Status; |
15 | 15 | use yii2mod\moderation\ModerationBehavior; |
16 | | -use yii2mod\moderation\ModerationQueryTrait; |
| 16 | +use yii2mod\moderation\ModerationQuery; |
17 | 17 |
|
18 | 18 | /** |
19 | 19 | * Class CommentModel |
|
38 | 38 | */ |
39 | 39 | class CommentModel extends ActiveRecord |
40 | 40 | { |
41 | | - use ModerationQueryTrait; |
42 | | - |
43 | 41 | /** |
44 | 42 | * @var null|array|ActiveRecord[] comment children |
45 | 43 | */ |
@@ -76,7 +74,8 @@ public function rules() |
76 | 74 | public function validateParentID($attribute) |
77 | 75 | { |
78 | 76 | if ($this->{$attribute} !== null) { |
79 | | - $parentCommentExist = static::approved() |
| 77 | + $parentCommentExist = static::find() |
| 78 | + ->approved() |
80 | 79 | ->andWhere([ |
81 | 80 | 'id' => $this->{$attribute}, |
82 | 81 | 'entity' => $this->entity, |
@@ -151,6 +150,14 @@ public function attributeLabels() |
151 | 150 | ]; |
152 | 151 | } |
153 | 152 |
|
| 153 | + /** |
| 154 | + * @return ModerationQuery |
| 155 | + */ |
| 156 | + public static function find() |
| 157 | + { |
| 158 | + return new ModerationQuery(get_called_class()); |
| 159 | + } |
| 160 | + |
154 | 161 | /** |
155 | 162 | * @inheritdoc |
156 | 163 | */ |
@@ -223,10 +230,12 @@ public function getAuthor() |
223 | 230 | */ |
224 | 231 | public static function getTree($entity, $entityId, $maxLevel = null) |
225 | 232 | { |
226 | | - $query = static::approved()->andWhere([ |
227 | | - 'entityId' => $entityId, |
228 | | - 'entity' => $entity, |
229 | | - ])->with(['author']); |
| 233 | + $query = static::find() |
| 234 | + ->approved() |
| 235 | + ->andWhere([ |
| 236 | + 'entityId' => $entityId, |
| 237 | + 'entity' => $entity, |
| 238 | + ])->with(['author']); |
230 | 239 |
|
231 | 240 | if ($maxLevel > 0) { |
232 | 241 | $query->andWhere(['<=', 'level', $maxLevel]); |
@@ -345,7 +354,8 @@ public static function getAuthors() |
345 | 354 | */ |
346 | 355 | public function getCommentsCount() |
347 | 356 | { |
348 | | - return (int)static::approved() |
| 357 | + return (int)static::find() |
| 358 | + ->approved() |
349 | 359 | ->andWhere(['entity' => $this->entity, 'entityId' => $this->entityId]) |
350 | 360 | ->count(); |
351 | 361 | } |
|
0 commit comments