Advertisement
villers

Untitled

Jan 15th, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2.  
  3. class SumonerModel
  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.         $data = array();
  15.         $data2 = array();
  16.         $spectator = $this->LeagueAPIWrapper->getSpectatorGameInfo($pseudo);
  17.  
  18.         if(isset($spectator->success))
  19.             return $spectator;
  20.  
  21.         foreach ($spectator->game->teamOne->array as $value)
  22.         {
  23.             array_push($data, (array)$value + $this->getLeagueForPlayer($value->summonerId));
  24.         }
  25.  
  26.         foreach ($spectator->game->teamTwo->array as $value)
  27.         {
  28.             array_push($data, (array)$value + $this->getLeagueForPlayer($value->summonerId));
  29.         }
  30.  
  31.         foreach ($spectator->game->playerChampionSelections->array as $key => $value)
  32.         {
  33.             array_push($data2, array_merge($data[$key], (array)$value));
  34.         }
  35.  
  36.         print_r($data2);
  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