Advertisement
villers

Untitled

Jan 16th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.  
  3. class SummonerModel
  4. {
  5.     private $LeagueAPIWrapper;
  6.  
  7.     function __construct($server)
  8.     {
  9.         $this->LeagueAPIWrapper = new LeagueAPIWrapper($server);
  10.     }
  11.  
  12.     public function ActiveGame($pseudo)
  13.     {
  14.         $tmpArray = $data = array();
  15.         $spectator = $this->LeagueAPIWrapper->getSpectatorGameInfo($pseudo);
  16.  
  17.         if(isset($spectator->success))
  18.             return $spectator;
  19.  
  20.         foreach ($spectator->game->teamOne->array as $value)
  21.         {
  22.             array_push($tmpArray, (array)$value + $this->getLeagueForPlayer($value->summonerId));
  23.         }
  24.  
  25.         foreach ($spectator->game->teamTwo->array as $value)
  26.         {
  27.             array_push($tmpArray, (array)$value + $this->getLeagueForPlayer($value->summonerId));
  28.         }
  29.  
  30.         foreach ($spectator->game->playerChampionSelections->array as $key => $value)
  31.         {
  32.             array_push($data, array_merge($tmpArray[$key], (array)$value));
  33.         }
  34.  
  35.         unset($tmpArray);
  36.         return $data;
  37.     }
  38.  
  39.     /* return Array
  40.     (
  41.         [tier] => SILVER
  42.         [rank] => V
  43.         [wins] => 51
  44.         [leaguePoints] => 100
  45.         [miniSeries] => stdClass Object
  46.             (
  47.                 [target] => 2
  48.                 [wins] => 1
  49.                 [losses] => 0
  50.                 [timeLeftToPlayMillis] => 2405883781
  51.                 [progress] => WNN                      1 victoire 2 non joué
  52.             )
  53.  
  54.     )
  55.     */
  56.     private function getLeagueForPlayer($summonerId)
  57.     {
  58.         $league = $this->LeagueAPIWrapper->getLeague($summonerId);
  59.         if(array_key_exists('error', $league) || !isset($league->$summonerId))
  60.             return array(
  61.                 'tier' => 'unranked'
  62.             );
  63.  
  64.         foreach ($league->$summonerId->entries as $value)
  65.         {
  66.             if($value->playerOrTeamId == $summonerId && $value->queueType == 'RANKED_SOLO_5x5')
  67.                 return array(
  68.                     'tier' => $value->tier,
  69.                     'rank' => $value->rank,
  70.                     'wins' => $value->wins,
  71.                     'leaguePoints' => $value->leaguePoints,
  72.                     'miniSeries' => (isset($value->miniSeries))? $value->miniSeries : ''
  73.                 );
  74.            
  75.         }
  76.     }
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement