コード例 #1
0
ファイル: SummonerController.php プロジェクト: Mi-ir/lolwin
 public function viewAction($summonerName = "")
 {
     $summoner = Summoner::getSummoner($this, $summonerName);
     if (!$summoner) {
         return new Response("PAS DE SUMMONER");
     }
     $em = $this->getDoctrine()->getManager();
     //        if (time() - $summoner->getUpdate()->getTimestamp() > 3600) {
     try {
         $data = file_get_contents("https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/" . $summoner->getIdSummoner() . "/ranked?season=SEASON2015&api_key=40e8765f-7faf-4b4c-b9cf-83bb8727a3d5");
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     $stats = isset($data) ? GameController::object_to_array(json_decode($data)) : array();
     if (count($stats) != 0) {
         foreach ($stats['champions'] as $statChampion) {
             if ($statChampion['id'] != 0) {
                 $champion = $em->getRepository("MiirGameBundle:Champion")->findOneByIdChampion($statChampion['id']);
                 $statSummoner = $summoner->getStat($this, $champion);
                 if ($statSummoner != null) {
                     $statSummoner->update($statChampion['stats']);
                 } else {
                     $summoner->addStat(new StatsSummoner($summoner, $champion, $statChampion['stats']));
                 }
             }
         }
     }
     $em->persist($summoner);
     $em->flush();
     $summoner->setUpdate();
     //        }
     return $this->render("MiirSummonerBundle:Summoner:tableStats.html.twig", array("summoner" => $summoner, "stats" => $summoner->getStats()));
 }
コード例 #2
0
ファイル: GameController.php プロジェクト: Mi-ir/lolwin
 public function currentGameAction($summonerName)
 {
     echo $this->get('request')->getLocale();
     $em = $this->getDoctrine()->getManager();
     $summoner = Summoner::getSummoner($this, $summonerName);
     if (!isset($summoner)) {
         return new Response("PAS DE SUMMONER");
     }
     try {
         $data = file_get_contents("https://euw.api.pvp.net/observer-mode/rest/consumer/getSpectatorGameInfo/EUW1/" . $summoner->getIdSummoner() . "?api_key=40e8765f-7faf-4b4c-b9cf-83bb8727a3d5");
     } catch (\Exception $e) {
         return new Response("PAS EN GAME");
     }
     $data = self::object_to_array(json_decode($data));
     foreach ($data['participants'] as $participant) {
         $names[] = $participant['summonerName'];
     }
     $summonersGame = Summoner::getSummoner($this, $names);
     StatsSummoner::setStatsSummoner($this, $summonersGame);
     foreach ($data['participants'] as $participant) {
         foreach ($summonersGame as $summonerGame) {
             $champion = $em->getRepository("MiirGameBundle:Champion")->findOneByIdChampion($participant['championId']);
             $stats = $summonerGame->getStat($this, $champion);
             if ($participant['summonerId'] == $summonerGame->getIdSummoner()) {
                 $summoners[$participant['teamId']][] = array("player" => array("summoner" => $summonerGame, "stats" => $stats), "champion" => $champion);
             }
         }
     }
     return $this->render("MiirGameBundle:Game:currentGame.html.twig", array("summoners" => $summoners));
 }