/**
  * проверяем изменения в лигах
  */
 public function checkLeagues($model)
 {
     $array_identical = false;
     if (count($model->dotaEventLeagues) != count($model->league_ids)) {
         $array_identical = false;
     } else {
         foreach ($model->dotaEventLeagues as $model1) {
             //echo'<pre>';print_r($model_spec);echo'</pre>';//die;
             $array_identical = false;
             foreach ($model->league_ids as $key => $value) {
                 $array_identical = false;
                 if ($model1->leagueid == $value) {
                     $array_identical = true;
                 }
                 if ($array_identical === false) {
                     break;
                 }
             }
             if ($array_identical === false) {
                 break;
             }
         }
     }
     //echo'<pre>';var_dump($array_identical);echo'</pre>';die;
     //echo'<pre>';var_dump($model->league_ids);echo'</pre>';die;
     if ($array_identical == false) {
         foreach ($model->dotaEventLeagues as $model1) {
             $model1->delete();
         }
         foreach ($model->league_ids as $value) {
             $model_n = new DotaEventLeague();
             $model_n->event_id = $model->id;
             $model_n->leagueid = $value;
             $model_n->save();
         }
     }
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEventLeaguesList()
 {
     return $this->hasMany(DotaEventLeague::className(), ['event_id' => 'id'])->with('league');
 }
Exemple #3
0
 public static function updateDotaEventHeroStat()
 {
     $params = DotaParams::loadParams();
     $events = DotaEvent::getActualEventsList();
     $event_ids = ArrayHelper::map($events, 'id', 'id');
     $heroesInEvents = DotaEventHeroStat::getHeroesInEvents($event_ids);
     $DotaEventLeague = new DotaEventLeague();
     $LeaguesInEvents = $DotaEventLeague->getLeaguesInEvents($event_ids);
     //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';die;
     $league_ids = [];
     foreach ($LeaguesInEvents as $event) {
         foreach ($event as $leagueid) {
             $league_ids[] = $leagueid;
         }
     }
     $played_matches = DotaMatchHistoryHeroes::getCountPlayedMatches($league_ids);
     //echo'<pre>';print_r($played_matches);echo'</pre>';die;
     $HeroesInLeagues = DotaLeagueHeroesStat::getHeroesInLeagues($league_ids);
     //echo'<pre>';print_r($HeroesInLeagues);echo'</pre>';die;
     $HeroesInEvents = DotaEventHero::getHeroesInEvents();
     $hero_ids = [];
     foreach ($HeroesInEvents as $event) {
         foreach ($event as $hero) {
             $hero_ids[] = $hero;
         }
     }
     $hero_ids = array_unique($hero_ids);
     //echo'<pre>';print_r($hero_ids);echo'</pre>';die;
     //$player_roles = DotaPlayer::getPlayersRolesList($account_ids);
     //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';//die;
     $summaries = [];
     foreach ($LeaguesInEvents as $event_id => $event) {
         foreach ($event as $leagueid) {
             if (isset($HeroesInLeagues[$leagueid])) {
                 foreach ($HeroesInLeagues[$leagueid] as $hero_id => $heroesInLeague) {
                     if (isset($HeroesInEvents[$event_id][$hero_id])) {
                         $summaries[$event_id][$hero_id] = $heroesInLeague;
                     }
                 }
             }
         }
     }
     $data_for_insert = [];
     //echo'<pre>';print_r($summaries);echo'</pre>';die;
     foreach ($summaries as $event_id => $heroes) {
         foreach ($heroes as $hero_id => $hero) {
             $kills = $deaths = $assists = $gold_per_min = $xp_per_min = $level = $picks = $bans = 0;
             $kills += $hero['kills'];
             $deaths += $hero['deaths'];
             $assists += $hero['assists'];
             $gold_per_min += $hero['gold_per_min'];
             $xp_per_min += $hero['xp_per_min'];
             $level += $hero['level'];
             $picks += $hero['picks'];
             $bans += $hero['bans'];
             if (isset($heroesInEvents[$event_id][$hero_id])) {
                 //если есть запись по игроку в event, то обновляем ее
                 $data = ['`kills`' => $kills, '`deaths`' => $deaths, '`assists`' => $assists, '`gold_per_min`' => $gold_per_min, '`xp_per_min`' => $xp_per_min, '`level`' => $level, '`picks`' => $picks, '`bans`' => $bans, '`matches`' => isset($played_matches[$hero_id]) ? $played_matches[$hero_id] : 0];
                 $where = ['`id` = ' . $heroesInEvents[$event_id][$hero_id]];
                 //echo'<pre>updateRow</pre>';//die;
                 DotaEventHeroStat::updateRow($data, $where);
             } else {
                 $data = [$event_id, $hero_id, $kills, $deaths, $assists, $gold_per_min, $xp_per_min, $level, $picks, $bans, isset($played_matches[$hero_id]) ? $played_matches[$hero_id] : 0];
                 $data_for_insert[] = "(" . implode(',', $data) . ")";
             }
         }
     }
     //echo'<pre>';print_r($data_for_insert);echo'</pre>';die;
     if (count($data_for_insert) > 0) {
         DotaEventHeroStat::addRows($data_for_insert);
     }
     // перерасчет кол-ва очков у каждого героя
     foreach ($summaries as $event_id => $heroes) {
         DotaEventHeroStat::calculateScoresForEvent($event_id);
     }
     return true;
 }