示例#1
0
 public function loadCategoryModel($id)
 {
     if (!($model = Category::findOne($id))) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested category does not exist.'));
     }
     return $model;
 }
示例#2
0
 /**
  * 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($language = null, $sourceId = null, $category_id = null, $backUrl = null)
 {
     $model = new Post();
     $model->loadDefaultValues();
     $model->status = Post::STATUS_PUBLISHED;
     $model->language = Yii::$app->language;
     if (isset($category_id) && ($category = Category::findOne($category_id))) {
         $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]);
     }
 }
示例#3
0
 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]);
 }
示例#4
0
 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]);
 }
示例#5
0
 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]);
 }
示例#6
0
 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]);
 }
示例#7
0
 /**
  * Находит путь к пункту меню ссылающемуся на категорию $categoryId, либо ее предка
  * Если путь ведет к предку, то достраиваем путь категории $categoryId
  * @param $categoryId
  * @param $menuMap \gromver\platform\frontend\components\MenuMap
  * @return null|string
  */
 private function findCategoryMenuPath($categoryId, $menuMap)
 {
     if (!isset($this->_categoryPaths[$menuMap->language][$categoryId])) {
         if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/news/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.'));
     }
 }