public function getListByCategory($slug, $fields = [], $with = [], $page = false, $pageSize = false, $order = '')
{
$category = Category::getInstance()->getBySlug($slug);
$model = self::$model->find()->select($fields)->where(['type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE, 'meta_id' => $category['id']])->join('RIGHT JOIN', Relationship::tableName() . ' relation', 'content_id=id');
$countModel = clone $model;
$pagination = new Pagination(['totalCount' => $countModel->count(), 'pageSize' => $pageSize]);
if ($page) {
$pagination->setPage($page, true);
}
switch (strtoupper($order)) {
case 'VIEW':
$model->orderBy('view_total DESC');
break;
case 'COMMENT':
$model->orderBy('comment_total DESC');
break;
case 'CREATED':
$model->orderBy('created_at DESC');
break;
case 'UPDATED':
$model->orderBy('updated_at DESC');
break;
}
return ['data' => $model->with($with)->limit($pagination->getLimit())->offset($pagination->getOffset())->all(), 'pagination' => $pagination];
}