Exemple #1
0
 /**
  * @param string $slug
  * @return mixed
  */
 public function actionSlugrubric($slug)
 {
     $rubric = ContentRubrics::find()->where(['=', 'slug', $slug])->andWhere(['=', 'section_id', 7])->one();
     if (!isset($rubric->id)) {
         return $this->redirect('/methods');
     }
     $query = Content::find()->where(['=', 'section_id', 7])->andWhere(['=', '`contentmanager_content`.`lang_id`', Lang::getCurrent()->id])->andWhere(['=', 'published', true])->andWhere(['=', 'rubric_id', $rubric->id])->orderBy('date DESC');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 3]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('rubric', ['models' => $models, 'pages' => $pages, 'rubric' => $rubric, 'rubrics' => ContentRubrics::findBySection(7)]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ContentRubrics::find()->with('section');
     if (isset(Yii::$app->controller->module->sectionId)) {
         $params['ContentRubricsSearch']['section_id'] = Yii::$app->controller->module->sectionId;
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'section_id' => $this->section_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * @param $section_id
  * @return array|null
  */
 public static function findBySection($section_id)
 {
     return ContentRubrics::find()->where(['=', 'section_id', $section_id])->all();
 }