Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find()->with(['author0', 'tournament']);
     $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, 'date' => $this->date, 'author' => $this->author, 'id_tournament' => $this->id_tournament, 'archive' => $this->archive]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
Esempio n. 2
0
 public function actionIndex()
 {
     //tournament filter initialization
     $tournamentFilter = News::activeTournamentFilter();
     $query = News::find()->where(['archive' => News::ARCHIVE_FALSE])->with(['tournament', 'author0'])->orderBy(['date' => SORT_DESC]);
     if (Yii::$app->request->post() && Yii::$app->request->post('tournamentFilter') != 'all') {
         $query->andWhere(['id_tournament' => Yii::$app->request->post('tournamentFilter')]);
         $selected = Yii::$app->request->post('tournamentFilter');
     } elseif (Yii::$app->request->post() && Yii::$app->request->post('tournamentFilter') == 'all') {
         $selected = 'all';
     } else {
         $selected = null;
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]);
     $news = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', compact('news', 'pages', 'tournamentFilter', 'selected'));
 }
Esempio n. 3
0
 public function destroy(Request $request, $id)
 {
     News::find($id)->categories()->detach();
     News::destroy($id);
     return \Redirect::back();
 }