@@ -233,20 +233,23 @@ public function getAuthor()
233
233
public static function getTree ($ entity , $ entityId , $ maxLevel = null )
234
234
{
235
235
$ query = static ::find ()
236
+ ->alias ('c ' )
236
237
->approved ()
237
238
->andWhere ([
238
- 'entityId ' => $ entityId ,
239
- 'entity ' => $ entity ,
240
- ])->with (['author ' ]);
239
+ 'c.entityId ' => $ entityId ,
240
+ 'c.entity ' => $ entity ,
241
+ ])
242
+ ->orderBy (['c.parentId ' => SORT_ASC , 'c.createdAt ' => SORT_ASC ])
243
+ ->with (['author ' ]);
241
244
242
245
if ($ maxLevel > 0 ) {
243
- $ query ->andWhere (['<= ' , 'level ' , $ maxLevel ]);
246
+ $ query ->andWhere (['<= ' , 'c. level ' , $ maxLevel ]);
244
247
}
245
248
246
249
$ models = $ query ->all ();
247
250
248
251
if (!empty ($ models )) {
249
- $ models = self ::buildTree ($ models );
252
+ $ models = static ::buildTree ($ models );
250
253
}
251
254
252
255
return $ models ;
@@ -365,7 +368,7 @@ public static function getAuthors()
365
368
*/
366
369
public function getCommentsCount ()
367
370
{
368
- return (int )static ::find ()
371
+ return (int ) static ::find ()
369
372
->approved ()
370
373
->andWhere (['entity ' => $ this ->entity , 'entityId ' => $ this ->entityId ])
371
374
->count ();
@@ -401,7 +404,7 @@ public function beforeModeration()
401
404
$ descendantIds = ArrayHelper::getColumn ($ this ->getDescendants ()->asArray ()->all (), 'id ' );
402
405
403
406
if (!empty ($ descendantIds )) {
404
- self ::updateAll (['status ' => $ this ->status ], ['id ' => $ descendantIds ]);
407
+ static ::updateAll (['status ' => $ this ->status ], ['id ' => $ descendantIds ]);
405
408
}
406
409
407
410
return true ;
0 commit comments