예제 #1
0
 /**
  * Добавление новых матчей в КХЛ
  */
 public function actionAddNewMatches()
 {
     $url = Url::to("/home/romanych/football_hockey_bds/khl/khl_2015_2016_08");
     $content = file_get_contents($url);
     //echo $content; exit;
     $thisMatch = [];
     $matchId = 0;
     $chars = preg_split('/div id=\\"detcon\\"/', $content, -1, PREG_SPLIT_NO_EMPTY);
     //разделяем контент на матчи
     $j = count($chars);
     for ($m = 1; $m < $j; $m++) {
         $head = file_get_contents(Url::to("@app/commands/header.html"));
         $match = $head . $chars[$m];
         //добавляем хэдер
         $thisMatch = $this->headOfMatchInArray($match);
         //print_r($thisMatch); exit;
         $game = new Khlmatches();
         $game->host_id = $thisMatch["host"];
         $game->guest_id = $thisMatch["guest"];
         $game->host_g = $thisMatch["host_g"];
         $game->guest_g = $thisMatch["guest_g"];
         $game->prim = $thisMatch["status"];
         try {
             $game->players = implode(",", $thisMatch["sost"][0]);
         } catch (ErrorException $e) {
             $game->players = $e->getMessage();
         }
         try {
             $game->player_off = implode(",", $thisMatch["sost"][1]);
         } catch (ErrorException $e) {
             $game->player_off = $e->getMessage();
         }
         //print_r($thisMatch); exit;
         $game->shot_in_goals_host = self::getIdOfPeriodsAfterIn($thisMatch["shot_in_goals_host"]);
         $game->shot_in_goals_guest = self::getIdOfPeriodsAfterIn($thisMatch["shot_in_goals_guest"]);
         $game->shot_reflected_host = self::getIdOfPeriodsAfterIn($thisMatch["shot_reflected_host"]);
         $game->shot_reflected_guest = self::getIdOfPeriodsAfterIn($thisMatch["shot_reflected_guest"]);
         $game->removal_host = self::getIdOfPeriodsAfterIn($thisMatch["removal_host"]);
         $game->removal_guest = self::getIdOfPeriodsAfterIn($thisMatch["removal_guest"]);
         $game->penalty_time_host = self::getIdOfPeriodsAfterIn($thisMatch["penalty_time_host"]);
         $game->penalty_time_guest = self::getIdOfPeriodsAfterIn($thisMatch["penalty_time_guest"]);
         $game->goals_in_more_host = self::getIdOfPeriodsAfterIn($thisMatch["goals_in_more_host"]);
         $game->goals_in_more_guest = self::getIdOfPeriodsAfterIn($thisMatch["goals_in_more_guest"]);
         $game->goals_in_less_host = self::getIdOfPeriodsAfterIn($thisMatch["goals_in_less_host"]);
         $game->goals_in_less_guest = self::getIdOfPeriodsAfterIn($thisMatch["goals_in_less_guest"]);
         $game->force_dodge_host = self::getIdOfPeriodsAfterIn($thisMatch["force_dodge_host"]);
         $game->force_dodge_guest = self::getIdOfPeriodsAfterIn($thisMatch["force_dodge_guest"]);
         $game->facedown_vic_host = self::getIdOfPeriodsAfterIn($thisMatch["facedown_vic_host"]);
         $game->facedown_vic_guest = self::getIdOfPeriodsAfterIn($thisMatch["facedown_vic_guest"]);
         $game->bet_vic_host = $thisMatch["bet_vic_host"];
         $game->bet_nobody = $thisMatch["bet_nobody"];
         $game->bet_vic_guest = $thisMatch["bet_vic_guest"];
         $game->date = $thisMatch["date"];
         $game->time_beg = $thisMatch["time_beg"];
         $game->judges = $thisMatch["judges"];
         $game->audience = $thisMatch["audience"];
         $game->stadium = $thisMatch["stadium"];
         $gk = [];
         $sub_sec = 0;
         if (isset($thisMatch["gk_substitution"][1])) {
             $game->gk_substitution = implode(',', $thisMatch["gk_substitution"][1]);
             $subs = explode(" ", $game->gk_substitution);
             //var_dump($subs); exit;
             $current_per = explode(":", $subs[3]);
             $sub_sec = (self::onlyDigit($subs[0]) - 1) * 1200 + (int) $current_per[0] * 60 + (int) $current_per[1];
             //var_dump($subs[4]." ".$subs[5]); exit;
             $gk[1][][$sub_sec] = Khlplayers::find()->where("name like('%" . self::clearSubject($subs[4] . " " . $subs[5]) . "%')")->one()->id;
             $gk[1][][3900] = Khlplayers::find()->where("name like('%" . self::clearSubject($subs[6] . " " . $subs[7]) . "%')")->one()->id;
             //var_dump($gk); exit;
         }
         if (isset($thisMatch["gk_substitution"][0])) {
             $game->gk_substitution = implode(',', $thisMatch["gk_substitution"][0]);
             $subs = explode(" ", $game->gk_substitution);
             //var_dump($subs); exit;
             $current_per = explode(":", $subs[3]);
             $sub_sec = (self::onlyDigit($subs[0]) - 1) * 1200 + (int) $current_per[0] * 60 + (int) $current_per[1];
             //var_dump($subs[4]." ".$subs[5]); exit;
             $gk[0][][$sub_sec] = Khlplayers::find()->where("name like('%" . self::clearSubject($subs[4] . " " . $subs[5]) . "%')")->one()->id;
             $gk[0][][3900] = Khlplayers::find()->where("name like('%" . self::clearSubject($subs[6] . " " . $subs[7]) . "%')")->one()->id;
             //var_dump($gk); exit;
         } else {
             $game->gk_substitution = '';
         }
         $game->errors = implode("; ", $thisMatch["errors"]);
         //var_dump($game); exit;
         $game->save(false);
         $matchId = $game->id;
         //var_dump($game->id); exit;
         $arrOfEvents = $this->eventOfMatchInArray($match);
         //print_r($arrOfEvents); exit;
         foreach ($arrOfEvents as $arr) {
             //print_r($arr);
             //$game->save(false); exit;
             $event = new Khlevents();
             if (isset($arr["time"])) {
                 $current_period = explode(":", $arr["time"]);
                 $event->minute = ($arr["period"] - 1) * 1200 + (int) $current_period[0] * 60 + (int) $current_period[1];
             } else {
                 $event->minute = 3900;
             }
             $event->status = $arr["status"];
             $event->is_host = $arr["is_host"];
             try {
                 $event->player_id = (int) $arr["subject"];
             } catch (ErrorException $e) {
                 $event->player_id = 947;
             }
             $event->match_id = $matchId;
             $str = "";
             if (isset($arr["prim2"])) {
                 $i = 0;
                 foreach ($arr["prim2"] as $primtwo) {
                     if ($i) {
                         $str .= " + " . $primtwo;
                     } else {
                         $str .= $primtwo;
                     }
                     $i++;
                 }
                 $prim2 = $str;
             } else {
                 $prim2 = "";
             }
             if (isset($arr["prim5"])) {
                 $prim5 = " + " . $arr["prim5"];
             } else {
                 $prim5 = "";
             }
             if (isset($arr["prim10"])) {
                 $prim10 = " + " . $arr["prim10"];
             } else {
                 $prim10 = "";
             }
             if (isset($arr["prim11"])) {
                 $prim11 = " + " . $arr["prim11"];
             } else {
                 $prim11 = "";
             }
             if (isset($arr["prim"])) {
                 $event->prim = $arr["prim"] . " " . $prim2 . " " . $prim5 . " " . $prim10 . " " . $prim11;
             }
             //$event->prim = $arr["prim2"];
             //echo $event->prim;
             if (isset($arr["assist"])) {
                 $event->assist = implode(",", $arr["assist"]);
             }
             //print_r($gk[0]);
             if ($event->is_host) {
                 if (isset($gk[0][0][$sub_sec]) && key($gk[0][0]) >= $event->minute) {
                     $event->gk = $gk[0][0][$sub_sec];
                 } elseif (isset($gk[0]) && key($gk[0][1]) >= $event->minute) {
                     $event->gk = $gk[0][1][3900];
                 } else {
                     try {
                         $event->gk = Khlplayers::find()->where("name like('%" . self::clearSubject($thisMatch["gk"][0][0][0]) . "%')")->one()->id;
                     } catch (ErrorException $e) {
                         $event->gk = 947;
                     }
                 }
             }
             if ($event->is_host == 0) {
                 //var_dump($thisMatch["gk"]); exit;
                 if (isset($gk[1][0][$sub_sec]) && key($gk[1][0]) >= $event->minute) {
                     $event->gk = $gk[1][0][$sub_sec];
                 } elseif (isset($gk[1]) && key($gk[1][1]) >= $event->minute) {
                     $event->gk = $gk[1][1][3900];
                 } else {
                     try {
                         $event->gk = Khlplayers::find()->where("name like('%" . self::clearSubject($thisMatch["gk"][0][1][0]) . "%')")->one()->id;
                     } catch (ErrorException $e) {
                         $event->gk = 947;
                     }
                 }
             }
             //var_dump($event);
             $event->save(false);
         }
     }
 }
예제 #2
0
 public function actionMatch($id)
 {
     $match = Khlmatches::findOne($id);
     $events_of_match = Khlevents::find()->where(['match_id' => $id])->all();
     return $this->render('match', ['match' => $match, 'events_of_match' => $events_of_match]);
 }