Example #1
0
 public function actionArticle($id)
 {
     if (!\Yii::$app->user->can('articles.view')) {
         $this->accessDenied();
     }
     $model = Article::findOne($id);
     if ($model->parent->root != $this->_rootid) {
         $model = null;
     }
     if (!$model) {
         throw new NotFoundHttpException(\Yii::t('yii', 'Page not found.'));
     }
     return $this->render('article', ['model' => $model]);
 }
Example #2
0
 public function getArticles($status = Article::STATUS_PUBLIC)
 {
     return $this->hasMany(Article::className(), ['parentid' => 'id'])->where(['<=', 'status', $status])->orderBy(['position' => SORT_ASC, 'updated_at' => SORT_DESC]);
 }
Example #3
0
 /**
  * Finds the Article model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Article the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($this->_model = Article::findOne($id)) !== null) {
         return $this->_model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Displays a single Category model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     return $this->render('view', ['model' => $model, 'categories' => new \yii\data\ArrayDataProvider(['allModels' => $model->children(1)->checkRoot(Yii::$app->settings->get('articles.root'))->all()]), 'articles' => new ActiveDataProvider(['query' => \simplator\articles\models\Article::find()->where(['parentid' => $model->id])->orderBy(['updated_at' => SORT_DESC])])]);
 }
Example #5
0
 /**
  * Check pathes
  * @param integer $limit 
  */
 public static function checkPathes($limit = 0)
 {
     $module = \Yii::$app->getModule('articles');
     $count = Category::find()->count();
     if ($count < 1) {
         $category = new Category();
         $category->title = $module->title;
         $category->name = $module->id;
         $category->genPath();
         $category->makeRoot();
         \Yii::$app->settings->set('articles.root', $category->id);
     }
     $categories = Category::find()->where(['path' => NULL])->all();
     foreach ($categories as $category) {
         $category->scenario = 'check';
         $category->save();
     }
     $articles = Article::find()->where(['path' => NULL])->all();
     foreach ($articles as $article) {
         $article->save();
     }
 }
Example #6
0
 public function getArticle()
 {
     return $this->hasOne(Article::className(), ['id' => 'articleid']);
 }