コード例 #1
0
ファイル: SitemapComponent.php プロジェクト: kashirin/kscms
 public function getArticles()
 {
     $articles = ArticleRecord::find()->select('article.seourl as url, article.name, structure.seourl as s_url, structure.label')->leftJoin('structure', '`structure`.`id` = `article`.`parent_id`')->where(['article.active' => ArticleRecord::STATUS_IS_ACTIVE])->andWhere(['<', 'article.active_from', time()])->with('structure')->asArray()->all();
     $menu = Yii::$app->mainMenu->getMainMenu();
     $arts = [];
     foreach ($articles as $art) {
         if (!isset($arts[$art['s_url']])) {
             $arts[$art['s_url']] = [];
         }
         $arts[$art['s_url']][] = $art;
     }
     foreach ($menu as $k => $first_level) {
         if (isset($arts[$first_level['url']])) {
             $menu[$k]['articles'] = $arts[$first_level['url']];
         }
         $cnt = 0;
         if ($first_level['children']) {
             foreach ($first_level['children'] as $l => $second_level) {
                 if (isset($arts[$second_level['url']])) {
                     $menu[$k]['children'][$l]['articles'] = $arts[$second_level['url']];
                     $cnt++;
                 }
             }
         }
         if (!$cnt) {
             unset($menu[$k]);
         }
     }
     return $menu;
 }
コード例 #2
0
ファイル: ArticleController.php プロジェクト: kashirin/kscms
 /**
  * Finds the ArticleRecord model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ArticleRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ArticleRecord::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #3
0
ファイル: SiteController.php プロジェクト: kashirin/kscms
 protected function _tryToGetContent($seourl)
 {
     $seourl = htmlspecialchars($seourl);
     if (!$seourl) {
         return ['type' => 'homepage', 'model' => null];
     }
     // find in  static pages
     $structureModel = new StructureRecord();
     $page = $structureModel->find()->where(['seourl' => $seourl])->one();
     if ($page) {
         $allowed = Yii::$app->mainMenu->checkContentPageCode($page->code);
         if ($allowed) {
             return ['type' => 'page', 'model' => $page];
         }
     }
     // find in  static articles
     $articleModel = new ArticleRecord();
     $article = $articleModel->find()->where(['seourl' => $seourl, 'active' => ArticleRecord::STATUS_IS_ACTIVE])->andWhere('active_from < ' . time())->one();
     if ($article) {
         return ['type' => 'article', 'model' => $article];
     }
     return false;
 }
コード例 #4
0
ファイル: ArticleSearch.php プロジェクト: kashirin/kscms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     if (!isset($params['parent_id'])) {
         throw new \Exception('Property parent_id must be setted');
     }
     $query = ArticleRecord::find()->where(['parent_id' => $params['parent_id']]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'active_from' => $this->active_from, 'sort' => $this->sort, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview_text', $this->preview_text])->andFilterWhere(['like', 'detail_text', $this->detail_text])->andFilterWhere(['like', 'soc_text', $this->soc_text])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'seourl', $this->seourl])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'file', $this->file]);
     return $dataProvider;
 }
コード例 #5
0
ファイル: TopnewsWidget.php プロジェクト: kashirin/kscms
 protected function _initItems()
 {
     $this->_items = ArticleRecord::find()->where(['active' => ArticleRecord::STATUS_IS_ACTIVE])->andWhere(['<', 'active_from', time()])->orderBy(['active_from' => SORT_DESC])->limit(5)->all();
 }
コード例 #6
0
ファイル: LastnewsWidget.php プロジェクト: kashirin/kscms
 protected function _initItems()
 {
     $this->_items = ArticleRecord::find()->select('article.*')->leftJoin('structure', '`structure`.`id` = `article`.`parent_id`')->where(['article.active' => ArticleRecord::STATUS_IS_ACTIVE])->andWhere(['<', 'article.active_from', time()])->andWhere(['structure.code' => $this->parentCode])->orderBy(['article.active_from' => SORT_DESC])->with('structure')->limit($this->count)->all();
 }