public function getComments($offset = 0)
    {
        // find all not equal threads for selected model
        $rows = Yii::$app->db
            ->createCommand('SELECT DISTINCT thread '.
                'FROM comment '.
                'WHERE parent_id=:parent_id AND model=:model AND status=:status '.
                'ORDER BY thread DESC '.
                'LIMIT '. Yii::$app->params['commentsPerPage'] .' OFFSET '. $offset)
            ->bindValues([
                ':parent_id' => $this->id,
                ':model' => self::COMMENT_FOR , 
                ':status' => Comment::STATUS_APPROVED,
            ])
            ->queryAll();
        // keep threads
        $a = []; foreach($rows as $row) $a[] = $row['thread'];
        // select all comments of kept threads
        return Comment::find()
            ->where('status=' . Comment::STATUS_APPROVED)
            ->andWhere(['in', 'thread', $a])
            ->orderBy('thread DESC, created_at ASC')
            ->all();
    }
public function getComments($offset = 0)
    {
        // find all not equal threads for selected model
        $rows = Yii::$app->db
            ->createCommand('SELECT DISTINCT thread '.
                'FROM comment '.
                'WHERE parent_id=:parent_id AND model=:model AND status=:status '.
                'ORDER BY thread DESC '.
                'LIMIT '. Yii::$app->params['commentsPerPage'] .' OFFSET '. $offset)
            ->bindValues([
                ':parent_id' => $this->id,
                ':model' => self::COMMENT_FOR , 
                ':status' => Comment::STATUS_APPROVED,
            ])
            ->queryAll();
        // keep threads
        $a = []; foreach($rows as $row) $a[] = $row['thread'];
        // select all comments of kept threads
        return Comment::find()
            ->where('status=' . Comment::STATUS_APPROVED)
            ->andWhere(['in', 'thread', $a])
            ->orderBy('thread DESC, created_at ASC')
            ->all();
    }
public function getComments ( $ offset = 0 ) { // find all not equal threads for selected model $ rows = Yii :: $ app -> db -> createCommand ( 'SELECT DISTINCT thread ' . 'FROM comment ' . 'WHERE parent_id=:parent_id AND model=:model AND status=:status ' . 'ORDER BY thread DESC ' . 'LIMIT ' . Yii :: $ app -> params [ 'commentsPerPage' ] . ' OFFSET ' . $ offset ) -> bindValues ( [ ':parent_id' => $ this -> id , ':model' => self :: COMMENT_FOR , ':status' => Comment :: STATUS_APPROVED , ] ) -> queryAll ( ) ; // keep threads $ a = [ ] ; foreach ( $ rows as $ row ) $ a [ ] = $ row [ 'thread' ] ; // select all comments of kept threads return Comment :: find ( ) -> where ( 'status=' . Comment :: STATUS_APPROVED ) -> andWhere ( [ 'in' , 'thread' , $ a ] ) -> orderBy ( 'thread DESC, created_at ASC' ) -> all ( ) ; }
Get LIMITed comments with OFFSET for selected model.
@return objects of comments
Get LIMITed comments with OFFSET for selected model .