Exemplo n.º 1
0
 /**
  *Find and show news list
  *
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionNewsList()
 {
     $this->layout = Constants::LAYOUT_MAIN;
     $query = News::find();
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => News::PAGE_SIZE]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('front/list', ['models' => $models, 'pages' => $pages]);
 }
Exemplo n.º 2
0
 /**
  * Lists all News models.
  * @return mixed
  */
 public function actionIndex()
 {
     // Выводим новости в обратном порядке
     $query = News::find()->where(['status_id' => Yii::$app->params['status']['active']])->orderBy('created_at DESC');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Yii::$app->params['news']['pageSize']]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', ['models' => $models, 'pages' => $pages]);
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'weight' => $this->weight, 'status_id' => $this->status_id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'preview', $this->preview])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'category_id', $this->category_id])->andFilterWhere(['like', 'tag', $this->tag]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $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, 'at_top' => $this->at_top, 'create_at' => $this->create_at]);
     $query->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Exemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'date_public' => $this->date_public, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'removed' => $this->removed, 'locked' => $this->locked]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'annotation', $this->annotation])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'layout', $this->layout]);
     return $dataProvider;
 }
Exemplo n.º 6
0
 /**
  * Отображение детальной новости
  * @param string $code символьный идентификатор новости
  * @param string $section символьный идентификатор категории новости
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionDetail($code, $section)
 {
     $model = News::find()->published()->andWhere(["code" => $code])->one();
     if (!$model) {
         throw new NotFoundHttpException();
     }
     $sectionModel = NewsSection::find()->published()->andWhere(["code" => $section])->one();
     $this->view->addBreadCrumbs($sectionModel->getBreadCrumbsItems($sectionModel, function ($model) {
         return ['/news/news/index', 'section' => $model->code];
     }));
     $this->view->addBreadCrumb(["label" => $model->title, "url" => Url::toRoute(["/news/news/detail", "code" => $code, "section" => $section])]);
     $this->view->registerMetaTags($model);
     return $this->render('detail', ["model" => $model, "detailImageWidth" => $this->detailImageWidth]);
 }