protected function launch() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->category ? $this->category->children()->published()->orderBy(null) : Category::find()->roots()->published(), 'pagination' => false, 'sort' => ['defaultOrder' => [$this->sort => intval($this->dir)]]]), 'itemLayout' => $this->itemLayout]); }
public function loadCategoryModel($id) { if (!($model = Category::findOne($id))) { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested category does not exist.')); } return $model; }
/** * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); if ($this->excludeRoots) { $query->excludeRoots(); } $query->with(['tags', 'parent']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['{{%news_category}}.id' => $this->id, '{{%news_category}}.parent_id' => $this->parent_id, '{{%news_category}}.created_at' => $this->created_at, '{{%news_category}}.updated_at' => $this->updated_at, '{{%news_category}}.status' => $this->status, '{{%news_category}}.created_by' => $this->created_by, '{{%news_category}}.updated_by' => $this->updated_by, '{{%news_category}}.lft' => $this->lft, '{{%news_category}}.rgt' => $this->rgt, '{{%news_category}}.level' => $this->level, '{{%news_category}}.ordering' => $this->ordering, '{{%news_category}}.hits' => $this->hits, '{{%news_category}}.lock' => $this->lock]); if ($this->published_at_timestamp) { $query->andWhere('{{%news_category}}.published_at >= :timestamp_from', ['timestamp_from' => $this->published_at_timestamp]); } if ($this->published_at_to_timestamp) { $query->andWhere('{{%news_category}}.published_at <= :timestamp_to', ['timestamp_to' => $this->published_at_to_timestamp]); } $query->andFilterWhere(['like', '{{%news_category}}.title', $this->title])->andFilterWhere(['like', '{{%news_category}}.alias', $this->alias])->andFilterWhere(['like', '{{%news_category}}.path', $this->path])->andFilterWhere(['like', '{{%news_category}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%news_category}}.preview_image', $this->preview_image])->andFilterWhere(['like', '{{%news_category}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%news_category}}.detail_image', $this->detail_image])->andFilterWhere(['like', '{{%news_category}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%news_category}}.metadesc', $this->metadesc]); if ($this->excludeCategory && ($category = Category::findOne($this->excludeCategory))) { /** @var $category Category */ $query->excludeCategory($category); } if ($this->tags) { $query->innerJoinWith('tags')->andFilterWhere(['{{%core_tag}}.id' => $this->tags]); } return $dataProvider; }
protected function launch() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->getQuery(), 'pagination' => ['pageSize' => $this->pageSize], 'sort' => ['defaultOrder' => [$this->sort => intval($this->dir)]]]), 'itemLayout' => $this->itemLayout, 'category' => $this->category, 'listViewOptions' => $this->listViewOptions]); }
protected function launch() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } $categoryId = $this->category ? $this->category->id : null; echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => Post::find()->published()->category($categoryId)->day($this->year, $this->month, $this->day)->last(), 'pagination' => false, 'sort' => ['defaultOrder' => [$this->sort => (int) $this->dir]]]), 'itemLayout' => $this->itemLayout, 'prevDayPost' => Post::find()->published()->category($categoryId)->beforeDay($this->year, $this->month, $this->day)->last()->one(), 'nextDayPost' => Post::find()->published()->category($categoryId)->afterDay($this->year, $this->month, $this->day)->last()->one(), 'category' => $this->category, 'year' => $this->year, 'month' => $this->month, 'day' => $this->day, 'listViewOptions' => $this->listViewOptions]); }
protected function launch() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } if (empty($this->category)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Category not found.')); } echo $this->render($this->layout, ['model' => $this->category]); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @param string|null $category_id * @param string|null $backUrl * @return mixed * @throws NotFoundHttpException */ public function actionCreate($category_id = null, $backUrl = null) { $model = new Post(); $model->loadDefaultValues(); $model->status = Post::STATUS_PUBLISHED; if (isset($category_id) && ($category = Category::findOne($category_id))) { /** @var Category $category */ $model->category_id = $category->id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect($backUrl ? $backUrl : ['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.')); } }
/** * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка * Если путь ведет к предку, то достраиваем путь категории $categoryId * @param $categoryId * @param $menuMap \gromver\platform\core\components\MenuMap * @return null|string */ private function findCategoryMenuPath($categoryId, $menuMap) { /** @var Category $category */ if (!isset($this->_categoryPaths[$categoryId])) { if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('news/frontend/category/view', ['id' => $categoryId]))) { $this->_categoryPaths[$categoryId] = $path; } elseif (($category = Category::findOne($categoryId)) && !$category->isRoot() && ($path = $this->findCategoryMenuPath($category->parent_id, $menuMap))) { $this->_categoryPaths[$categoryId] = $path . '/' . $category->alias; } else { $this->_categoryPaths[$categoryId] = false; } } return $this->_categoryPaths[$categoryId]; }