/** * Displays a single Status model. * @param string $slug * @return mixed */ public function actionSlug($slug) { $model = Content::find()->where(['slug' => $slug])->one(); if (!is_null($model)) { $latestPosts = Content::find()->where(['section_id' => $model->section_id])->orderBy('date DESC')->all(); return $this->render('single', ['model' => $model, 'latestPosts' => $latestPosts]); } else { return $this->redirect('/index'); } }
/** * @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)]); }
public function publishContent() { $records = Content::find()->where(['!=', 'published', true])->where(['<', 'publication_date', $this->time])->all(); if (empty($records)) { return null; } foreach ($records as $record) { $record->published = true; $record->date = $record->publication_date; $record->save(); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Content::find()->orderBy(['id' => SORT_DESC])->with('section', 'rubric', 'author'); if (isset(Yii::$app->controller->module->sectionId)) { $params['ContentSearch']['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, 'date' => $this->date, 'lang_id' => $this->lang_id, 'rubric_id' => $this->rubric_id, 'section_id' => $this->section_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * @param integer $section_id * @param null|integer $limit * @return array|\yii\db\ActiveRecord[] */ public static function findLatestBySection($section_id, $limit = null, $all = null) { $ans = Content::find()->where(['section_id' => $section_id]); if (!$all) { $ans->andWhere(['=', 'published', true]); } $ans->orderBy('date DESC'); if ($limit) { $ans->limit($limit); } return $ans->all(); }