Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SummonerModel
- {
- private $LeagueAPIWrapper;
- function __construct($server)
- {
- $this->LeagueAPIWrapper = new LeagueAPIWrapper($server);
- }
- public function ActiveGame($pseudo)
- {
- $tmpArray = $data = array();
- $spectator = $this->LeagueAPIWrapper->getSpectatorGameInfo($pseudo);
- if(isset($spectator->success))
- return $spectator;
- foreach ($spectator->game->teamOne->array as $value)
- {
- array_push($tmpArray, (array)$value + $this->getLeagueForPlayer($value->summonerId));
- }
- foreach ($spectator->game->teamTwo->array as $value)
- {
- array_push($tmpArray, (array)$value + $this->getLeagueForPlayer($value->summonerId));
- }
- foreach ($spectator->game->playerChampionSelections->array as $key => $value)
- {
- array_push($data, array_merge($tmpArray[$key], (array)$value));
- }
- unset($tmpArray);
- return $data;
- }
- /* return Array
- (
- [tier] => SILVER
- [rank] => V
- [wins] => 51
- [leaguePoints] => 100
- [miniSeries] => stdClass Object
- (
- [target] => 2
- [wins] => 1
- [losses] => 0
- [timeLeftToPlayMillis] => 2405883781
- [progress] => WNN 1 victoire 2 non joué
- )
- )
- */
- private function getLeagueForPlayer($summonerId)
- {
- $league = $this->LeagueAPIWrapper->getLeague($summonerId);
- if(array_key_exists('error', $league) || !isset($league->$summonerId))
- return array(
- 'tier' => 'unranked'
- );
- foreach ($league->$summonerId->entries as $value)
- {
- if($value->playerOrTeamId == $summonerId && $value->queueType == 'RANKED_SOLO_5x5')
- return array(
- 'tier' => $value->tier,
- 'rank' => $value->rank,
- 'wins' => $value->wins,
- 'leaguePoints' => $value->leaguePoints,
- 'miniSeries' => (isset($value->miniSeries))? $value->miniSeries : ''
- );
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement