Beispiel #1
0
 /**
  * Calls the api for information about this champion and creates entity.
  * Using static cache to be sure we don't add a champion twice.
  *
  * @param array $variables
  * @return object 
  */
 public function import(array $variables)
 {
     $championId = $variables['championId'];
     $region = $variables['region'];
     if (!isset(self::$champions[$championId])) {
         $this->api->setRegion($region);
         $data = $this->api->call('static_data', 'champion_details', ['id' => $championId], ['champData' => "all"]);
         $champion_class = $this->factory->getEntityClass('champion');
         $champion = new $champion_class();
         $champion->setDistantId($data->id)->setName($data->name)->setTitle($data->title)->setImage($data->image->full)->setTags(implode(',', $data->tags));
         $this->em->persist($champion);
         self::$champions[$championId] = $champion;
     }
     return self::$champions[$championId];
 }
Beispiel #2
0
 /**
  * Calls the api for information about this item and creates entity.
  * Using static cache to be sure we don't add an item twice.
  *
  * @param array $variables
  * @return object 
  */
 public function import(array $variables)
 {
     $itemId = $variables['itemId'];
     $region = $variables['region'];
     $version = $variables['version'];
     list($a, $b) = explode('.', $version);
     $version = $a . '.' . $b . '.1';
     if (!isset(self::$items[$itemId])) {
         $this->api->setRegion($region);
         $data = $this->api->call('static_data', 'item_details', ['id' => $itemId], ['itemData' => "all", 'version' => $version]);
         if (!isset($data->tags)) {
             $data->tags = [];
         }
         if (!isset($data->effect)) {
             $data->effect = [];
         }
         $item_class = $this->factory->getEntityClass('item');
         $item = new $item_class();
         $item->setDistantId($data->id)->setName($data->name)->setDescription($data->description)->setImage($data->image->full)->setTags(implode(',', $data->tags))->setCost($data->gold->total)->setStats(serialize($data->stats))->setEffects(serialize($data->effect));
         $this->em->persist($item);
         self::$items[$itemId] = $item;
     }
     return self::$items[$itemId];
 }
Beispiel #3
0
 /**
  * Calls the api for information about this game and create proper entites
  *
  * @param array $variables
  * @return is_object(var)
  */
 public function import(array $variables)
 {
     $region = $variables['region'];
     $matchId = $variables['matchId'];
     // -- Game
     $game_class = $this->factory->getEntityClass('game');
     $champion_class = $this->factory->getEntityClass('champion');
     $item_class = $this->factory->getEntityClass('item');
     $game = $this->em->getRepository($game_class)->findOneByDistantId($matchId);
     if ($game) {
         return;
     }
     $this->api->setRegion($variables['region']);
     $data = $this->api->call('match', 'details', ['matchId' => $matchId]);
     $createdAt = new \DateTime();
     $createdAt->setTimestamp($data->matchCreation);
     $game = new $game_class();
     $game->setDistantId($matchId)->setRegion($region)->setDuration($data->matchDuration)->setQueueType($data->queueType)->setVersion($data->matchVersion);
     // -- Bans
     foreach ($data->teams as $team) {
         if (!isset($team->bans)) {
             break;
         }
         foreach ($team->bans as $ban) {
             $champion = $this->em->getRepository($champion_class)->findOneByDistantId($ban->championId);
             if (!$champion) {
                 $champion = $this->factory->getImporter('champion')->import(['region' => 'na', 'championId' => (int) $ban->championId]);
             }
             $game->addBans($champion);
         }
     }
     $this->em->persist($game);
     // -- Summoners
     $summoner_class = $this->factory->getEntityClass('summoner');
     $summoners = [];
     foreach ($data->participantIdentities as $k => $pi) {
         if (true || !isset($pi->player)) {
             $summoners[$pi->participantId] = null;
             continue;
         }
         $summoner = $this->em->getRepository($summoner_class)->findOneByDistantId($pi->player->summonerId);
         if (!$summoner) {
             $summoner = new $summoner_class();
             $summoner->setDistantId($pi->player->summonerId)->setName($pi->player->summonerName);
             $this->em->persist($summoner);
         }
         $summoners[$pi->participantId] = $summoner;
     }
     $participant_class = $this->factory->getEntityClass('participant');
     foreach ($data->participants as $p) {
         // -- Champion
         $champion = $this->em->getRepository($champion_class)->findOneByDistantId($p->championId);
         if (!$champion) {
             $champion = $this->factory->getImporter('champion')->import(['region' => 'na', 'championId' => (int) $p->championId]);
         }
         // -- Participant
         $participant = new $participant_class();
         $participant->setGame($game)->setChampion($champion)->setWinner($p->stats->winner)->setKills($p->stats->kills)->setDeaths($p->stats->deaths)->setAssists($p->stats->assists)->setGold($p->stats->goldEarned)->setDamageTaken($p->stats->totalDamageTaken)->setDamageDealt($p->stats->totalDamageDealtToChampions);
         if (!is_null($summoners[$p->participantId])) {
             $participant->setSummoner($summoners[$p->participantId]);
         }
         // -- Items
         foreach (range(0, 6) as $i) {
             $field = "item" . $i;
             if ($p->stats->{$field} == 0) {
                 continue;
             }
             $item = $this->em->getRepository($item_class)->findOneByDistantId($p->stats->{$field});
             if (!$item) {
                 $item = $this->factory->getImporter('item')->import(['region' => 'na', 'itemId' => (int) $p->stats->{$field}, 'version' => $data->matchVersion]);
             }
             $participant->addItems($item);
         }
         $this->em->persist($participant);
     }
     return $game;
 }