public function actionList($id) { $superior = SiteCategory::findOne(['id' => $id, 'site_id' => $this->module->siteId, 'status' => SiteCategory::STATUS_ENABLED]); if (!$superior) { throw new NotFoundHttpException(\Yii::t($this->module->messageCategory, 'no matched data')); } $query = $superior->getItems()->where(['site_id' => $this->module->siteId, 'status' => [SiteArticle::STATUS_RELEASED, SiteArticle::STATUS_FEATURED]])->orderby('status desc, created_at desc'); $pagination = new Pagination(['totalCount' => $query->count()]); $items = $query->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->accessed()->render($this->action->id, ['superior' => $superior, 'items' => $items, 'pagination' => $pagination]); }
public function actionList($type = 'all', $stype = null, $sword = null) { $query = SiteCategory::find()->where(['site_id' => $this->module->siteId])->orderby('created_at'); if ($type !== 'all') { $query->andWhere(['type' => $type]); } if ($sword !== null) { $query->andWhere(['like', "{$stype}", $sword]); } $pagination = new Pagination(['totalCount' => $query->count()]); $items = $query->offset($pagination->offset)->limit($pagination->limit)->all(); $typeItems = ArrayHelper::merge(['all' => \Yii::t($this->module->messageCategory, '{attribute} {action}', ['attribute' => \Yii::t($this->module->messageCategory, 'type'), 'action' => \Yii::t($this->module->messageCategory, 'filtering')])], SiteCategory::defaultAttributeItems('type')); return $this->render($this->action->id, ['type' => $type, 'stype' => $stype, 'sword' => $sword, 'items' => $items, 'pagination' => $pagination, 'typeItems' => $typeItems]); }
/** * Get cache model * * @since 0.0.1 * @return {object} */ protected function getCacheTarget($type) { switch ($type) { case static::TYPE_CATEGORY: $cache_id = $this->category_id; $classname = SiteCategory::classname(); break; case static::TYPE_ARTICLE: $cache_id = $this->article_id; $classname = SiteArticle::classname(); break; } if (!$cache_id && $this->getOldAttribute('type') == $type) { $cache_id = $this->getOldAttribute('target_id'); } return $classname::findOne(['id' => $cache_id, 'site_id' => $this->site_id]); }
/** * Get its belongs category * * @since 0.0.1 * @return {object} */ public function getCategory() { return $this->hasOne(SiteCategory::classname(), ['id' => 'category_id']); }
public function actionList($cid = 0, $type = 'all', $status = 'all', $stype = null, $sword = null) { $query = SiteArticle::find()->alias('a')->where(['a.site_id' => $this->module->siteId])->orderby('a.status desc, a.created_at desc'); if ($cid) { $query->andWhere(['a.category_id' => $cid]); } if ($type != 'all') { $query->joinWith('category b')->andWhere(['b.type' => $type]); } if ($status != 'all') { $query->andWhere(['a.status' => $status]); } if ($sword !== null) { $query->andWhere(['like', "a.{$stype}", $sword]); } $pagination = new Pagination(['totalCount' => $query->count()]); $items = $query->offset($pagination->offset)->limit($pagination->limit)->all(); $categoryItems = ArrayHelper::merge([0 => \Yii::t($this->module->messageCategory, '{attribute} {action}', ['attribute' => \Yii::t($this->module->messageCategory, 'category'), 'action' => \Yii::t($this->module->messageCategory, 'filtering')])], ArrayHelper::map(SiteCategory::find()->select(['id', 'name'])->where(['site_id' => $this->module->siteId])->orderby('created_at desc')->all(), 'id', 'name')); $categoryTypeItems = ArrayHelper::merge(['all' => \Yii::t($this->module->messageCategory, '{attribute} {action}', ['attribute' => \Yii::t($this->module->messageCategory, 'type'), 'action' => \Yii::t($this->module->messageCategory, 'filtering')])], SiteCategory::defaultAttributeItems('type')); $statusItems = ArrayHelper::merge(['all' => \Yii::t($this->module->messageCategory, '{attribute} {action}', ['attribute' => \Yii::t($this->module->messageCategory, 'status'), 'action' => \Yii::t($this->module->messageCategory, 'filtering')])], SiteArticle::defaultAttributeItems('status')); return $this->render($this->action->id, ['cid' => $cid, 'type' => $type, 'status' => $status, 'stype' => $stype, 'sword' => $sword, 'items' => $items, 'pagination' => $pagination, 'categoryItems' => $categoryItems, 'categoryTypeItems' => $categoryTypeItems, 'statusItems' => $statusItems]); }