/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @param string|null $language * @param string|null $sourceId * @param string|null $category_id * @param string|null $backUrl * @return mixed * @throws NotFoundHttpException */ public function actionCreate($sourceId = null, $category_id = null, $language = null, $backUrl = null) { $model = new Post(); $model->loadDefaultValues(); $model->status = Post::STATUS_PUBLISHED; $model->language = $language ? $language : Yii::$app->language; if (isset($category_id) && ($category = Category::findOne($category_id))) { /** @var Category $category */ $model->category_id = $category->id; $model->language = $category->language; } if ($sourceId && $language) { $sourceModel = $this->findModel($sourceId); $relevantCategory = Category::findOne(['path' => $sourceModel->category->path, 'language' => $language]); $model->category_id = $relevantCategory ? $relevantCategory->id : null; $model->language = $language; $model->translation_id = $sourceModel->translation_id; $model->alias = $sourceModel->alias; $model->published_at = $sourceModel->published_at; $model->status = $sourceModel->status; $model->preview_text = $sourceModel->preview_text; $model->detail_text = $sourceModel->detail_text; $model->metakey = $sourceModel->metakey; $model->metadesc = $sourceModel->metadesc; } else { $sourceModel = null; } 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, 'sourceModel' => $sourceModel]); } }
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 loadModel($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', 'translations', 'parent']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['{{%grom_category}}.id' => $this->id, '{{%grom_category}}.parent_id' => $this->parent_id, '{{%grom_category}}.created_at' => $this->created_at, '{{%grom_category}}.updated_at' => $this->updated_at, '{{%grom_category}}.status' => $this->status, '{{%grom_category}}.created_by' => $this->created_by, '{{%grom_category}}.updated_by' => $this->updated_by, '{{%grom_category}}.lft' => $this->lft, '{{%grom_category}}.rgt' => $this->rgt, '{{%grom_category}}.level' => $this->level, '{{%grom_category}}.ordering' => $this->ordering, '{{%grom_category}}.hits' => $this->hits, '{{%grom_category}}.lock' => $this->lock]); if ($this->published_at_timestamp) { $query->andWhere('{{%grom_category}}.published_at >= :timestamp_from', ['timestamp_from' => $this->published_at_timestamp]); } if ($this->published_at_to_timestamp) { $query->andWhere('{{%grom_category}}.published_at <= :timestamp_to', ['timestamp_to' => $this->published_at_to_timestamp]); } $query->andFilterWhere(['like', '{{%grom_category}}.language', $this->language])->andFilterWhere(['like', '{{%grom_category}}.title', $this->title])->andFilterWhere(['like', '{{%grom_category}}.alias', $this->alias])->andFilterWhere(['like', '{{%grom_category}}.path', $this->path])->andFilterWhere(['like', '{{%grom_category}}.preview_text', $this->preview_text])->andFilterWhere(['like', '{{%grom_category}}.preview_image', $this->preview_image])->andFilterWhere(['like', '{{%grom_category}}.detail_text', $this->detail_text])->andFilterWhere(['like', '{{%grom_category}}.detail_image', $this->detail_image])->andFilterWhere(['like', '{{%grom_category}}.metakey', $this->metakey])->andFilterWhere(['like', '{{%grom_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(['{{%grom_tag}}.id' => $this->tags]); } return $dataProvider; }
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]); }
protected function launch() { if ($this->category && !$this->category instanceof Category) { $this->category = Category::findOne(intval($this->category)); } if (!empty($this->category)) { $this->language = null; } else { $this->language or $this->language = Yii::$app->language; } 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]); }
/** * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка * Если путь ведет к предку, то достраиваем путь категории $categoryId * @param $categoryId * @param $menuMap \gromver\platform\basic\components\MenuMap * @return null|string */ private function findCategoryMenuPath($categoryId, $menuMap) { /** @var Category $category */ if (!isset($this->_categoryPaths[$menuMap->language][$categoryId])) { if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/news/frontend/category/view', ['id' => $categoryId]))) { $this->_categoryPaths[$menuMap->language][$categoryId] = $path; } elseif (($category = Category::findOne($categoryId)) && !$category->isRoot() && ($path = $this->findCategoryMenuPath($category->parent_id, $menuMap))) { $this->_categoryPaths[$menuMap->language][$categoryId] = $path . '/' . $category->alias; } else { $this->_categoryPaths[$menuMap->language][$categoryId] = false; } } return $this->_categoryPaths[$menuMap->language][$categoryId]; }
/** * 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.')); } }