|
1 | 1 | <?php namespace Syntax\SteamApi\Containers; |
2 | 2 |
|
3 | | -class Player extends BaseContainer { |
| 3 | +class Player extends BaseContainer |
| 4 | +{ |
4 | 5 |
|
5 | | - public $steamId; |
| 6 | + public $steamId; |
6 | 7 |
|
7 | | - public $steamIds; |
| 8 | + public $steamIds; |
8 | 9 |
|
9 | | - public $communityVisibilityState; |
| 10 | + public $communityVisibilityState; |
10 | 11 |
|
11 | | - public $profileState; |
| 12 | + public $profileState; |
12 | 13 |
|
13 | | - public $personaName; |
| 14 | + public $personaName; |
14 | 15 |
|
15 | | - public $lastLogoff; |
| 16 | + public $lastLogoff; |
16 | 17 |
|
17 | | - public $profileUrl; |
| 18 | + public $profileUrl; |
18 | 19 |
|
19 | | - public $avatar; |
| 20 | + public $avatar; |
20 | 21 |
|
21 | | - public $avatarMedium; |
| 22 | + public $avatarMedium; |
22 | 23 |
|
23 | | - public $avatarFull; |
| 24 | + public $avatarFull; |
24 | 25 |
|
25 | | - public $avatarUrl; |
| 26 | + public $avatarUrl; |
26 | 27 |
|
27 | | - public $avatarMediumUrl; |
| 28 | + public $avatarMediumUrl; |
28 | 29 |
|
29 | | - public $avatarFullUrl; |
| 30 | + public $avatarFullUrl; |
30 | 31 |
|
31 | | - public $personaState; |
| 32 | + public $personaState; |
32 | 33 |
|
33 | | - public $personaStateId; |
| 34 | + public $personaStateId; |
34 | 35 |
|
35 | | - public $realName; |
| 36 | + public $realName; |
36 | 37 |
|
37 | | - public $primaryClanId; |
| 38 | + public $primaryClanId; |
38 | 39 |
|
39 | | - public $timecreated; |
| 40 | + public $timecreated; |
40 | 41 |
|
41 | | - public $personaStateFlags; |
| 42 | + public $personaStateFlags; |
42 | 43 |
|
43 | | - public $locCountryCode; |
| 44 | + public $locCountryCode; |
44 | 45 |
|
45 | | - public $locStateCode; |
| 46 | + public $locStateCode; |
46 | 47 |
|
47 | | - public $locCityId; |
| 48 | + public $locCityId; |
48 | 49 |
|
49 | | - public function __construct($player) |
50 | | - { |
51 | | - $this->steamId = $player->steamid; |
52 | | - $this->steamIds = (new Id((int)$this->steamId)); |
53 | | - $this->communityVisibilityState = $player->communityvisibilitystate; |
54 | | - $this->profileState = $this->checkIssetField($player, 'profilestate'); |
55 | | - $this->personaName = $player->personaname; |
56 | | - $this->lastLogoff = date('F jS, Y h:ia', $player->lastlogoff); |
57 | | - $this->profileUrl = $player->profileurl; |
58 | | - $this->avatar = $this->getImageForAvatar($player->avatar); |
59 | | - $this->avatarMedium = $this->getImageForAvatar($player->avatarmedium); |
60 | | - $this->avatarFull = $this->getImageForAvatar($player->avatarfull); |
61 | | - $this->avatarUrl = $player->avatar; |
62 | | - $this->avatarMediumUrl = $player->avatarmedium; |
63 | | - $this->avatarFullUrl = $player->avatarfull; |
64 | | - $this->personaState = $this->convertPersonaState($player->personastate); |
65 | | - $this->personaStateId = $player->personastate; |
66 | | - $this->realName = $this->checkIssetField($player, 'realName'); |
67 | | - $this->primaryClanId = $this->checkIssetField($player, 'primaryClanId'); |
68 | | - $this->timecreated = $this->checkIssetField($player, 'timecreated'); |
69 | | - $this->personaStateFlags = $this->checkIssetField($player, 'personaStateFlags'); |
70 | | - $this->locCountryCode = $this->checkIssetField($player, 'locCountryCode'); |
71 | | - $this->locStateCode = $this->checkIssetField($player, 'locStateCode'); |
72 | | - $this->locCityId = $this->checkIssetField($player, 'locCityId'); |
73 | | - } |
| 50 | + public $location; |
74 | 51 |
|
75 | | - protected function convertPersonaState($personaState) |
76 | | - { |
77 | | - switch ($personaState) { |
78 | | - case 0: |
79 | | - return '<span class="text-error">Offline</span>'; |
80 | | - case 1: |
81 | | - return '<span class="text-success">Online</span>'; |
82 | | - case 2: |
83 | | - return '<span class="text-warning">Busy</span>'; |
84 | | - case 3: |
85 | | - return '<span class="text-warning">Away</span>'; |
86 | | - case 4: |
87 | | - return '<span class="text-warning">Snooze</span>'; |
88 | | - case 5: |
89 | | - return 'Looking to Trade'; |
90 | | - case 6: |
91 | | - return 'Looking to Play'; |
92 | | - } |
93 | | - } |
| 52 | + public function __construct($player) |
| 53 | + { |
| 54 | + $this->steamId = $player->steamid; |
| 55 | + $this->steamIds = (new Id((int)$this->steamId)); |
| 56 | + $this->communityVisibilityState = $player->communityvisibilitystate; |
| 57 | + $this->profileState = $this->checkIssetField($player, 'profilestate'); |
| 58 | + $this->personaName = $player->personaname; |
| 59 | + $this->lastLogoff = date('F jS, Y h:ia', $player->lastlogoff); |
| 60 | + $this->profileUrl = $player->profileurl; |
| 61 | + $this->avatar = $this->getImageForAvatar($player->avatar); |
| 62 | + $this->avatarMedium = $this->getImageForAvatar($player->avatarmedium); |
| 63 | + $this->avatarFull = $this->getImageForAvatar($player->avatarfull); |
| 64 | + $this->avatarUrl = $player->avatar; |
| 65 | + $this->avatarMediumUrl = $player->avatarmedium; |
| 66 | + $this->avatarFullUrl = $player->avatarfull; |
| 67 | + $this->personaState = $this->convertPersonaState($player->personastate); |
| 68 | + $this->personaStateId = $player->personastate; |
| 69 | + $this->realName = $this->checkIssetField($player, 'realname'); |
| 70 | + $this->primaryClanId = $this->checkIssetField($player, 'primaryclanid'); |
| 71 | + $this->timecreated = $this->checkIssetField($player, 'timecreated'); |
| 72 | + $this->personaStateFlags = $this->checkIssetField($player, 'personastateflags'); |
| 73 | + $this->locCountryCode = $this->checkIssetField($player, 'loccountrycode'); |
| 74 | + $this->locStateCode = $this->checkIssetField($player, 'locstatecode'); |
| 75 | + $this->locCityId = $this->checkIssetField($player, 'loccityid'); |
| 76 | + $this->location = $this->getLocation(); |
| 77 | + } |
94 | 78 |
|
| 79 | + protected function getLocation() |
| 80 | + { |
| 81 | + $countriesFile = json_decode(\file_get_contents(__DIR__ . '/../Resources/countries.json')); |
| 82 | + $result = new \stdClass; |
| 83 | + |
| 84 | + if ($this->locCountryCode != null) { |
| 85 | + $result->country = $countriesFile->{$this->locCountryCode}->name; |
| 86 | + } |
| 87 | + |
| 88 | + if ($this->locCountryCode != null && $this->locStateCode != null) { |
| 89 | + $result->state = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->name; |
| 90 | + } |
| 91 | + |
| 92 | + if ($this->locCountryCode != null && $this->locStateCode != null && $this->locCityId != null) { |
| 93 | + if (! empty($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities)) { |
| 94 | + $result->city = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities->{$this->locCityId}->name; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + return $result; |
| 99 | + } |
| 100 | + |
| 101 | + protected function convertPersonaState($personaState) |
| 102 | + { |
| 103 | + switch ($personaState) { |
| 104 | + case 0: |
| 105 | + return '<span class="text-error">Offline</span>'; |
| 106 | + case 1: |
| 107 | + return '<span class="text-success">Online</span>'; |
| 108 | + case 2: |
| 109 | + return '<span class="text-warning">Busy</span>'; |
| 110 | + case 3: |
| 111 | + return '<span class="text-warning">Away</span>'; |
| 112 | + case 4: |
| 113 | + return '<span class="text-warning">Snooze</span>'; |
| 114 | + case 5: |
| 115 | + return 'Looking to Trade'; |
| 116 | + case 6: |
| 117 | + return 'Looking to Play'; |
| 118 | + } |
| 119 | + } |
95 | 120 | } |
0 commit comments