Esempio n. 1
0
 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()));
 }
Esempio n. 2
0
 public static function getSummoner($object, $summonerNames)
 {
     $em = $object->getDoctrine()->getManager();
     $summonerQuery = "";
     $summoners = array();
     if (count($summonerNames) == 1) {
         $summonerNames = array($summonerNames);
     }
     foreach ($summonerNames as $summonerName) {
         $summoner = null;
         if ($object->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
             $user = $object->container->get('security.context')->getToken()->getUser();
             if ($summonerName != "") {
                 $summoner = $em->getRepository("MiirSummonerBundle:Summoner")->findOneByName($summonerName);
                 if ($summoner == null) {
                     $summoner = $em->getRepository("MiirSummonerBundle:Summoner")->findOneByCleanName($summonerName);
                 }
             } else {
                 $summoner = $user->getSummoner();
             }
         } else {
             if ($summonerName != "") {
                 $summoner = $em->getRepository("MiirSummonerBundle:Summoner")->findOneByName($summonerName);
                 if ($summoner == null) {
                     $summoner = $em->getRepository("MiirSummonerBundle:Summoner")->findOneByCleanName($summonerName);
                 }
             } else {
                 return false;
             }
         }
         if ($summoner !== null) {
             $summoners[] = $summoner;
         } else {
             $summonerQuery .= $summonerName . ",";
         }
     }
     if (count($summoners) != count($summonerNames)) {
         $summonerQuery = str_replace(" ", "%20", $summonerQuery);
         try {
             $data = file_get_contents("https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/" . $summonerQuery . "?api_key=40e8765f-7faf-4b4c-b9cf-83bb8727a3d5");
             $datasSummoner = array_values(GameController::object_to_array(json_decode($data)));
         } catch (\Exception $e) {
             echo $e->getMessage();
         }
         $idQuery = "";
         foreach ($datasSummoner as $dataSummoner) {
             $idQuery .= $dataSummoner['id'] . ",";
         }
         if ($dataSummoner['summonerLevel'] == 30) {
             try {
                 $data = file_get_contents("https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/" . $idQuery . "/entry?api_key=40e8765f-7faf-4b4c-b9cf-83bb8727a3d5");
                 $datasLeague = GameController::object_to_array(json_decode($data));
             } catch (\Exception $e) {
                 echo $e->getMessage();
             }
         }
         foreach ($datasSummoner as $dataSummoner) {
             $dataLeague = isset($datasLeague[$dataSummoner['id']]) ? $datasLeague[$dataSummoner['id']] : array();
             $summoner = new self($dataSummoner, $dataLeague);
             $summoners[] = $summoner;
             $em->persist($summoner);
         }
         $em->flush();
     }
     if (count($summoners) == 1) {
         return $summoners[0];
     }
     return $summoners;
 }
Esempio n. 3
0
 public static function setStatsSummoner($object, $summoners)
 {
     $em = $object->getDoctrine()->getManager();
     if (count($summoners) == 1) {
         $summoners = array($summoners);
     }
     foreach ($summoners as $summoner) {
         if (count($summoner->getStats()) == 0) {
             $data = null;
             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();
                 $data == null;
             }
             $data = $data == null ? array() : GameController::object_to_array(json_decode($data));
             if ($data != null) {
                 foreach ($data['champions'] as $stats) {
                     if ($stats['id'] != 0) {
                         $champion = $em->getRepository("MiirGameBundle:Champion")->findOneByIdChampion($stats['id']);
                         $statSummoner = new self($summoner, $champion, $stats['stats']);
                         $em->persist($statSummoner);
                     }
                 }
             }
         }
         $em->flush();
     }
 }