Skip to content

Commit 3da2fc5

Browse files
author
Igor Chepurnoy
committed
added ModerationQuery
1 parent 67d9aaf commit 3da2fc5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

models/CommentModel.php

+19-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use yii2mod\comments\Module;
1414
use yii2mod\moderation\enums\Status;
1515
use yii2mod\moderation\ModerationBehavior;
16-
use yii2mod\moderation\ModerationQueryTrait;
16+
use yii2mod\moderation\ModerationQuery;
1717

1818
/**
1919
* Class CommentModel
@@ -38,8 +38,6 @@
3838
*/
3939
class CommentModel extends ActiveRecord
4040
{
41-
use ModerationQueryTrait;
42-
4341
/**
4442
* @var null|array|ActiveRecord[] comment children
4543
*/
@@ -76,7 +74,8 @@ public function rules()
7674
public function validateParentID($attribute)
7775
{
7876
if ($this->{$attribute} !== null) {
79-
$parentCommentExist = static::approved()
77+
$parentCommentExist = static::find()
78+
->approved()
8079
->andWhere([
8180
'id' => $this->{$attribute},
8281
'entity' => $this->entity,
@@ -151,6 +150,14 @@ public function attributeLabels()
151150
];
152151
}
153152

153+
/**
154+
* @return ModerationQuery
155+
*/
156+
public static function find()
157+
{
158+
return new ModerationQuery(get_called_class());
159+
}
160+
154161
/**
155162
* @inheritdoc
156163
*/
@@ -223,10 +230,12 @@ public function getAuthor()
223230
*/
224231
public static function getTree($entity, $entityId, $maxLevel = null)
225232
{
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']);
230239

231240
if ($maxLevel > 0) {
232241
$query->andWhere(['<=', 'level', $maxLevel]);
@@ -345,7 +354,8 @@ public static function getAuthors()
345354
*/
346355
public function getCommentsCount()
347356
{
348-
return (int)static::approved()
357+
return (int)static::find()
358+
->approved()
349359
->andWhere(['entity' => $this->entity, 'entityId' => $this->entityId])
350360
->count();
351361
}

0 commit comments

Comments
 (0)