models/CommentModel.php
public static function getTree($entity, $entityId, $maxLevel = null)
    {
        $query = static::find()
            ->alias('c')
            ->approved()
            ->andWhere([
                'c.entityId' => $entityId,
                'c.entity' => $entity,
            ])
            ->orderBy(['c.parentId' => SORT_ASC, 'c.createdAt' => SORT_ASC])
            ->with(['author']);

        if ($maxLevel > 0) {
            $query->andWhere(['<=', 'c.level', $maxLevel]);
        }

        $models = $query->all();

        if (!empty($models)) {
            $models = static::buildTree($models);
        }

        return $models;
    }
public static function getTree($entity, $entityId, $maxLevel = null)
    {
        $query = static::find()
            ->alias('c')
            ->approved()
            ->andWhere([
                'c.entityId' => $entityId,
                'c.entity' => $entity,
            ])
            ->orderBy(['c.parentId' => SORT_ASC, 'c.createdAt' => SORT_ASC])
            ->with(['author']);

        if ($maxLevel > 0) {
            $query->andWhere(['<=', 'c.level', $maxLevel]);
        }

        $models = $query->all();

        if (!empty($models)) {
            $models = static::buildTree($models);
        }

        return $models;
    }
public static function getTree ( $ entity , $ entityId , $ maxLevel = null ) { $ query = static :: find ( ) -> alias ( 'c' ) -> approved ( ) -> andWhere ( [ 'c.entityId' => $ entityId , 'c.entity' => $ entity , ] ) -> orderBy ( [ 'c.parentId' => SORT_ASC , 'c.createdAt' => SORT_ASC ] ) -> with ( [ 'author' ] ) ; if ( $ maxLevel > 0 ) { $ query -> andWhere ( [ '<=' , 'c.level' , $ maxLevel ] ) ; } $ models = $ query -> all ( ) ; if ( ! empty ( $ models ) ) { $ models = static :: buildTree ( $ models ) ; } return $ models ; }
Get comments tree.

@param string $entity
@param string $entityId
@param null $maxLevel

@return array|ActiveRecord[]
Get comments tree .