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