Esempio n. 1
0
 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]);
 }
Esempio n. 2
0
 public function actionEdit($id = 0)
 {
     if (!$id) {
         $item = new SiteCategory();
         $item->scenario = 'add';
         $item->site_id = $this->module->siteId;
     } else {
         $item = SiteCategory::findOne(['id' => $id, 'site_id' => $this->module->siteId]);
         if (!$item) {
             throw new NotFoundHttpException(\Yii::t($this->module->messageCategory, 'no matched data'));
         }
         $item->scenario = 'edit';
     }
     if (\Yii::$app->request->isPost && $item->load(\Yii::$app->request->post())) {
         if ($item->commonHandler()) {
             \Yii::$app->session->setFlash('item', '0|' . \Yii::t($this->module->messageCategory, 'operation succeeded'));
             return $this->redirect(['category/list']);
         }
         \Yii::$app->session->setFlash('item', '1|' . $item->firstErrorInfirstErrors);
     }
     return $this->render($this->action->id, ['item' => $item]);
 }