/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PokerFantasy::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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, 'event_id' => $this->event_id, 'users_count' => $this->users_count, 'deposit' => $this->deposit, 'prize_pool' => $this->prize_pool]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $fantasy_type = 'all', $only_active = true) { $query = PokerFantasy::find()->joinWith('event'); $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, 'event_id' => $this->event_id, 'users_count' => $this->users_count, 'deposit' => $this->deposit, 'prize_pool' => $this->prize_pool]); $query->andFilterWhere(['like', 'name', $this->name]); switch ($fantasy_type) { case self::FANTASY_LIST_NOW: $query->andFilterWhere(['<', 'start', time()]); $query->andFilterWhere(['>', 'end', time()]); break; case self::FANTASY_LIST_FUTURE: $query->andFilterWhere(['>', 'start', time()]); break; case self::FANTASY_LIST_MY: if (!Yii::$app->user->isGuest) { $fantasyIds = UserFantasy::getFavFantasyIds(Yii::$app->user->id, Transaction::TR_GAME_POKER); //echo'<pre>';print_r($fantasyIds);echo'</pre>';//die; //$query->andFilterWhere([ $this->tableName(). '.id' =>$fantasyIds]); if (count($fantasyIds) == 0) { $fantasyIds = [0]; } $query->andFilterWhere(['IN', $this->tableName() . '.id', $fantasyIds]); } break; } if ($only_active == true) { $query->andFilterWhere(['=', 'status', self::FANTASY_ACTIVE]); } return $dataProvider; }