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