Пример #1
0
 public function getInfos(&$dataProvider)
 {
     $arFantasies = [];
     foreach ($dataProvider->models as $model) {
         $arFantasies[$model->game][] = $model->fantasy_id;
     }
     //echo'<pre>';print_r($arFantasies);echo'</pre>';//die;
     foreach ($arFantasies as $game => $fanrasies) {
         switch ($game) {
             case GamesParams::GAME_DOTA:
                 $fantasyModel = new DotaFantasy();
                 $draftModel = new DotaDraft();
                 break;
             case GamesParams::GAME_POKER:
                 $fantasyModel = new PokerFantasy();
                 $draftModel = new PokerDraft();
                 break;
         }
         $fantasiesList = $fantasyModel->getFantasiesFromIds($fanrasies);
         $drafts_counts = $draftModel->getDraftsCount($fanrasies);
         //echo'<pre>';print_r($drafts_counts);echo'</pre>';//die;
         foreach ($dataProvider->models as $model) {
             if ($model->game == $game) {
                 foreach ($fantasiesList as $item) {
                     if ($item['id'] == $model->fantasy_id) {
                         $model->info = $item;
                     }
                 }
                 foreach ($drafts_counts as $id => $item) {
                     if ($id == $model->fantasy_id) {
                         $model->info['drafts_counts'] = $item;
                     }
                 }
             }
         }
     }
     return $dataProvider;
 }
 private function showFantasyList($meta_type = 'poker-main')
 {
     $current_action = Yii::$app->controller->action->id;
     $fantasy_type = Yii::$app->request->get('type', 'all');
     //echo $fantasy_type;
     $params = [];
     $searchModel = new PokerFantasySearch();
     $dataProvider = $searchModel->search($params, $fantasy_type);
     //echo'<pre>';print_r(Yii::$app->user->id);echo'</pre>';die;
     $fantasy_ids = [];
     foreach ($dataProvider->models as $model) {
         $fantasy_ids[] = $model->id;
     }
     $PokerDraft = new PokerDraft();
     if (count($fantasy_ids)) {
         $drafts_counts = $PokerDraft->getDraftsCount($fantasy_ids);
     } else {
         $drafts_counts = [];
     }
     //echo'<pre>';print_r($drafts_counts);echo'</pre>';die;
     if (Yii::$app->user->isGuest) {
         $user_rates = [];
     } else {
         $user_rates = $PokerDraft->getUserRateList(Yii::$app->user->id);
     }
     //echo'<pre>';print_r($user_rates);echo'</pre>';die;
     $meta_info = MetaInfo::getMetaInfo($meta_type);
     return $this->render('fantasy-list', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'current_action' => $current_action, 'fantasy_type' => $fantasy_type, 'user_rates' => $user_rates, 'drafts_counts' => $drafts_counts, 'meta_info' => $meta_info]);
 }