Skip to content

Commit a92859f

Browse files
Travis BlasingameTravis Blasingame
authored andcommitted
Adding in better location handling. Fixing the casing on the player container. Fixes #23
1 parent 643fa5a commit a92859f

File tree

4 files changed

+100
-68
lines changed

4 files changed

+100
-68
lines changed

examples/user/GetPlayerSummaries.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Array
3131
[locCountryCode] => US
3232
[locStateCode] => TX
3333
[locCityId] => 3620
34+
[location] => stdClass Object
35+
(
36+
[country] => United States
37+
[state] => Texas
38+
[city] => Dallas
39+
)
3440
)
3541

3642
)
Lines changed: 92 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,120 @@
11
<?php namespace Syntax\SteamApi\Containers;
22

3-
class Player extends BaseContainer {
3+
class Player extends BaseContainer
4+
{
45

5-
public $steamId;
6+
public $steamId;
67

7-
public $steamIds;
8+
public $steamIds;
89

9-
public $communityVisibilityState;
10+
public $communityVisibilityState;
1011

11-
public $profileState;
12+
public $profileState;
1213

13-
public $personaName;
14+
public $personaName;
1415

15-
public $lastLogoff;
16+
public $lastLogoff;
1617

17-
public $profileUrl;
18+
public $profileUrl;
1819

19-
public $avatar;
20+
public $avatar;
2021

21-
public $avatarMedium;
22+
public $avatarMedium;
2223

23-
public $avatarFull;
24+
public $avatarFull;
2425

25-
public $avatarUrl;
26+
public $avatarUrl;
2627

27-
public $avatarMediumUrl;
28+
public $avatarMediumUrl;
2829

29-
public $avatarFullUrl;
30+
public $avatarFullUrl;
3031

31-
public $personaState;
32+
public $personaState;
3233

33-
public $personaStateId;
34+
public $personaStateId;
3435

35-
public $realName;
36+
public $realName;
3637

37-
public $primaryClanId;
38+
public $primaryClanId;
3839

39-
public $timecreated;
40+
public $timecreated;
4041

41-
public $personaStateFlags;
42+
public $personaStateFlags;
4243

43-
public $locCountryCode;
44+
public $locCountryCode;
4445

45-
public $locStateCode;
46+
public $locStateCode;
4647

47-
public $locCityId;
48+
public $locCityId;
4849

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;
7451

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+
}
9478

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+
}
95120
}

src/Syntax/SteamApi/Resources/countries.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/BaseTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function checkPlayerProperties($friendsList)
6565
$this->assertObjectHasAttributes($attributes, $friendsList[0]);
6666

6767
$attributes = [
68-
'locCountryCode', 'locStateCode', 'locCityId'
68+
'locCountryCode', 'locStateCode', 'locCityId', 'location'
6969
];
7070
$this->assertObjectHasAttributes($attributes, $friendsList[0]);
7171

0 commit comments

Comments
 (0)