Exemplo n.º 1
0
 public function run()
 {
     //return;
     if (Yii::$app->user->isGuest) {
         return;
     }
     $rowsFav = UserFantasy::getFavFantasies(Yii::$app->user->id);
     if (count($rowsFav) == 0) {
         return;
     }
     return $this->render('user_bookmark_fantasies', ['rowsFav' => $rowsFav]);
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $pagesize)
 {
     $query = UserFantasy::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => $pagesize, 'pageSizeParam' => false]]);
     $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, 'user_id' => $this->user_id]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 public function getFantasyInFav()
 {
     if (Yii::$app->user->isGuest) {
         $res = false;
     } else {
         $res = UserFantasy::getInfo(Yii::$app->user->id, $this->id, $this->gameId);
     }
     return $res;
 }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserFantasies()
 {
     return $this->hasMany(UserFantasy::className(), ['user_id' => 'id']);
 }
Exemplo n.º 6
0
 /**
  * добавляет/удаляет фантазию в/из избранные пользователя
  * @return mixed
  */
 public function actionToFav()
 {
     $fantasy_id = intval(Yii::$app->request->post('id', '0'));
     $game = intval(Yii::$app->request->post('game', '0'));
     //echo $fantasy_id;
     if (Yii::$app->user->isGuest || $fantasy_id == 0 || $game == 0) {
         return;
     }
     $userFantasyId = UserFantasy::getInfo(Yii::$app->user->id, $fantasy_id, $game);
     if ($userFantasyId === false) {
         UserFantasy::addInfo(Yii::$app->user->id, $fantasy_id, $game);
     } else {
         UserFantasy::delInfo($userFantasyId);
     }
     echo 'ok';
     return;
 }