/** * @return \yii\db\ActiveQuery */ public function getEventPlayersList() { return $this->hasMany(DotaEventPlayer::className(), ['event_id' => 'id'])->with('player'); }
/** * @return \yii\db\ActiveQuery */ public function getEventPlayer() { return $this->hasOne(DotaEventPlayer::className(), ['account_id' => 'account_id']); }
/** * проверяем изменения в игроках */ public function checkPlayers($model) { $array_identical = false; if (count($model->dotaEventPlayers) != count($model->player_id)) { $array_identical = false; } else { foreach ($model->dotaEventPlayers as $model1) { //echo'<pre>';print_r($model->player_id);echo'</pre>';die; //echo'<pre>';print_r($model1->player_id);echo'</pre>';die; $array_identical = false; foreach ($model->player_id as $value) { $array_identical = false; if ($model1->account_id == $value) { if ($model->price_md_p[$model1->account_id] == $model1->price_md && $model->price_pd[$model1->account_id] == $model1->price_pd) { $array_identical = true; } else { $array_identical = false; } } if ($array_identical === false) { break; } } if ($array_identical === false) { break; } } } if ($array_identical == false) { foreach ($model->dotaEventPlayers as $model1) { $model1->delete(); } foreach ($model->player_id as $player_id) { if ($model->price_md_p[$player_id] != 0 || $model->price_pd[$player_id] != 0) { $model_n = new DotaEventPlayer(); $model_n->event_id = $model->id; $model_n->account_id = $player_id; if ($model->price_md_p[$player_id] != 0) { $model_n->price_md = $model->price_md_p[$player_id]; } if ($model->price_pd[$player_id] != 0) { $model_n->price_pd = $model->price_pd[$player_id]; } $model_n->save(); } } } }
public function actionAddNewRate() { //$current_action = Yii::$app->controller->action->id; $fantasy_id = (int) Yii::$app->request->post('id', 0); //$draft_id = (int)Yii::$app->request->post('draft_id', 0); $fantasy = DotaFantasy::findOne($fantasy_id); if ($fantasy === null) { return; } $draft_id = $fantasy->draft_id; $params = DotaParams::loadParams(); //echo'<pre>';var_dump($fantasy->draft_id);echo'</pre>';//die; $data = ['params' => $params, 'draft_id' => $draft_id, 'fantasy_id' => $fantasy_id, 'fantasyModel' => $fantasy, 'game_name' => GamesParams::GAME_DOTA_NAME]; switch ($fantasy->draft_id) { case DotaFantasySearch::DOTA_PLAYERS_DRAFT_ID: $view = 'add-new-rate-form-players'; $playersList = DotaEventPlayer::loadPlayersListOnFantasy($fantasy_id); $data['playersList'] = $playersList; break; case DotaFantasySearch::DOTA_HEROES_DRAFT_ID: $view = 'add-new-rate-form-heroes'; $heroesList = DotaEventHero::loadHeroesListOnFantasy($fantasy_id); $data['heroesList'] = $heroesList; break; case DotaFantasySearch::DOTA_MIXED_DRAFT_ID: $view = 'add-new-rate-form-mixed'; $playersList = DotaEventPlayer::loadPlayersListOnFantasy($fantasy_id); $heroesList = DotaEventHero::loadHeroesListOnFantasy($fantasy_id); $data['playersList'] = $playersList; $data['heroesList'] = $heroesList; break; default: $view = ''; break; } //echo'<pre>'; print_r('actionAddNewRate');echo'</pre>';die; if ($fantasy_id == 0 || $draft_id == 0 || $view == '') { return; } return $this->renderPartial($view, $data); }
public static function updateDotaEventPlayerStat() { $params = DotaParams::loadParams(); $events = DotaEvent::getActualEventsList(); $event_ids = ArrayHelper::map($events, 'id', 'id'); $playersInEvents = DotaEventPlayerStat::getPlayersInEvents($event_ids); //echo'<pre>';print_r($playersInEvents);echo'</pre>';die; $DotaEventLeague = new DotaEventLeague(); $LeaguesInEvents = $DotaEventLeague->getLeaguesInEvents($event_ids); //echo'<pre>';print_r($event_ids);echo'</pre>';//die; //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';die; $league_ids = []; foreach ($LeaguesInEvents as $event) { foreach ($event as $leagueid) { $league_ids[] = $leagueid; } } $played_matches = DotaMatchHistoryPlayers::getCountPlayedMatches($league_ids); //echo'<pre>';print_r($played_matches);echo'</pre>';die; $PlayersInLeagues = DotaLeaguePlayersStat::getPlayersInLeagues($league_ids); $PlayersInEvents = DotaEventPlayer::getPlayersInEvents(); $account_ids = []; foreach ($PlayersInEvents as $event) { foreach ($event as $player) { $account_ids[] = $player; } } $account_ids = array_unique($account_ids); $player_roles = DotaPlayer::getPlayersRolesList($account_ids); //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';//die; //echo'<pre>';print_r($PlayersInLeagues);echo'</pre>';//die; //echo'<pre>';print_r($PlayersInEvents);echo'</pre>';//die; $summaries = []; foreach ($LeaguesInEvents as $event_id => $event) { foreach ($event as $leagueid) { if (isset($PlayersInLeagues[$leagueid])) { foreach ($PlayersInLeagues[$leagueid] as $account_id => $playersInLeague) { if (isset($PlayersInEvents[$event_id][$account_id])) { $summaries[$event_id][$account_id] = $playersInLeague; } } } } } $data_for_insert = []; //echo'<pre>';print_r($summaries);echo'</pre>';die; foreach ($summaries as $event_id => $players) { foreach ($players as $account_id => $player) { $kills = $deaths = $assists = $gold_per_min = $xp_per_min = $level = 0; $kills += $player['kills']; $deaths += $player['deaths']; $assists += $player['assists']; $gold_per_min += $player['gold_per_min']; $xp_per_min += $player['xp_per_min']; $level += $player['level']; if (isset($playersInEvents[$event_id][$account_id])) { //если есть запись по игроку в event, то обновляем ее $data = ['`kills`' => $kills, '`deaths`' => $deaths, '`assists`' => $assists, '`gold_per_min`' => $gold_per_min, '`xp_per_min`' => $xp_per_min, '`level`' => $level, '`matches`' => isset($played_matches[$account_id]) ? $played_matches[$account_id] : 0]; $where = ['`id` = ' . $playersInEvents[$event_id][$account_id]]; DotaEventPlayerStat::updateRow($data, $where); } else { $data = [$event_id, $account_id, $kills, $deaths, $assists, $gold_per_min, $xp_per_min, $level, isset($played_matches[$account_id]) ? $played_matches[$account_id] : 0]; $data_for_insert[] = "(" . implode(',', $data) . ")"; } } } if (count($data_for_insert) > 0) { DotaEventPlayerStat::addRows($data_for_insert); } // перерасчет кол-ва очков у каждого игрока foreach ($summaries as $event_id => $players) { DotaEventPlayerStat::calculateScoresForEvent($event_id); } return true; }