@@ -233,20 +233,23 @@ public function getAuthor()
233233 public static function getTree ($ entity , $ entityId , $ maxLevel = null )
234234 {
235235 $ query = static ::find ()
236+ ->alias ('c ' )
236237 ->approved ()
237238 ->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 ' ]);
241244
242245 if ($ maxLevel > 0 ) {
243- $ query ->andWhere (['<= ' , 'level ' , $ maxLevel ]);
246+ $ query ->andWhere (['<= ' , 'c. level ' , $ maxLevel ]);
244247 }
245248
246249 $ models = $ query ->all ();
247250
248251 if (!empty ($ models )) {
249- $ models = self ::buildTree ($ models );
252+ $ models = static ::buildTree ($ models );
250253 }
251254
252255 return $ models ;
@@ -365,7 +368,7 @@ public static function getAuthors()
365368 */
366369 public function getCommentsCount ()
367370 {
368- return (int )static ::find ()
371+ return (int ) static ::find ()
369372 ->approved ()
370373 ->andWhere (['entity ' => $ this ->entity , 'entityId ' => $ this ->entityId ])
371374 ->count ();
@@ -401,7 +404,7 @@ public function beforeModeration()
401404 $ descendantIds = ArrayHelper::getColumn ($ this ->getDescendants ()->asArray ()->all (), 'id ' );
402405
403406 if (!empty ($ descendantIds )) {
404- self ::updateAll (['status ' => $ this ->status ], ['id ' => $ descendantIds ]);
407+ static ::updateAll (['status ' => $ this ->status ], ['id ' => $ descendantIds ]);
405408 }
406409
407410 return true ;
0 commit comments