Skip to content

Commit

Permalink
Adding in better location handling. Fixing the casing on the player c…
Browse files Browse the repository at this point in the history
…ontainer. Fixes syntaxerrors#23
  • Loading branch information
Travis Blasingame authored and Travis Blasingame committed Jun 17, 2015
1 parent 643fa5a commit a92859f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 68 deletions.
6 changes: 6 additions & 0 deletions examples/user/GetPlayerSummaries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Array
[locCountryCode] => US
[locStateCode] => TX
[locCityId] => 3620
[location] => stdClass Object
(
[country] => United States
[state] => Texas
[city] => Dallas
)
)

)
159 changes: 92 additions & 67 deletions src/Syntax/SteamApi/Containers/Player.php
Original file line number Diff line number Diff line change
@@ -1,95 +1,120 @@
<?php namespace Syntax\SteamApi\Containers;

class Player extends BaseContainer {
class Player extends BaseContainer
{

public $steamId;
public $steamId;

public $steamIds;
public $steamIds;

public $communityVisibilityState;
public $communityVisibilityState;

public $profileState;
public $profileState;

public $personaName;
public $personaName;

public $lastLogoff;
public $lastLogoff;

public $profileUrl;
public $profileUrl;

public $avatar;
public $avatar;

public $avatarMedium;
public $avatarMedium;

public $avatarFull;
public $avatarFull;

public $avatarUrl;
public $avatarUrl;

public $avatarMediumUrl;
public $avatarMediumUrl;

public $avatarFullUrl;
public $avatarFullUrl;

public $personaState;
public $personaState;

public $personaStateId;
public $personaStateId;

public $realName;
public $realName;

public $primaryClanId;
public $primaryClanId;

public $timecreated;
public $timecreated;

public $personaStateFlags;
public $personaStateFlags;

public $locCountryCode;
public $locCountryCode;

public $locStateCode;
public $locStateCode;

public $locCityId;
public $locCityId;

public function __construct($player)
{
$this->steamId = $player->steamid;
$this->steamIds = (new Id((int)$this->steamId));
$this->communityVisibilityState = $player->communityvisibilitystate;
$this->profileState = $this->checkIssetField($player, 'profilestate');
$this->personaName = $player->personaname;
$this->lastLogoff = date('F jS, Y h:ia', $player->lastlogoff);
$this->profileUrl = $player->profileurl;
$this->avatar = $this->getImageForAvatar($player->avatar);
$this->avatarMedium = $this->getImageForAvatar($player->avatarmedium);
$this->avatarFull = $this->getImageForAvatar($player->avatarfull);
$this->avatarUrl = $player->avatar;
$this->avatarMediumUrl = $player->avatarmedium;
$this->avatarFullUrl = $player->avatarfull;
$this->personaState = $this->convertPersonaState($player->personastate);
$this->personaStateId = $player->personastate;
$this->realName = $this->checkIssetField($player, 'realName');
$this->primaryClanId = $this->checkIssetField($player, 'primaryClanId');
$this->timecreated = $this->checkIssetField($player, 'timecreated');
$this->personaStateFlags = $this->checkIssetField($player, 'personaStateFlags');
$this->locCountryCode = $this->checkIssetField($player, 'locCountryCode');
$this->locStateCode = $this->checkIssetField($player, 'locStateCode');
$this->locCityId = $this->checkIssetField($player, 'locCityId');
}
public $location;

protected function convertPersonaState($personaState)
{
switch ($personaState) {
case 0:
return '<span class="text-error">Offline</span>';
case 1:
return '<span class="text-success">Online</span>';
case 2:
return '<span class="text-warning">Busy</span>';
case 3:
return '<span class="text-warning">Away</span>';
case 4:
return '<span class="text-warning">Snooze</span>';
case 5:
return 'Looking to Trade';
case 6:
return 'Looking to Play';
}
}
public function __construct($player)
{
$this->steamId = $player->steamid;
$this->steamIds = (new Id((int)$this->steamId));
$this->communityVisibilityState = $player->communityvisibilitystate;
$this->profileState = $this->checkIssetField($player, 'profilestate');
$this->personaName = $player->personaname;
$this->lastLogoff = date('F jS, Y h:ia', $player->lastlogoff);
$this->profileUrl = $player->profileurl;
$this->avatar = $this->getImageForAvatar($player->avatar);
$this->avatarMedium = $this->getImageForAvatar($player->avatarmedium);
$this->avatarFull = $this->getImageForAvatar($player->avatarfull);
$this->avatarUrl = $player->avatar;
$this->avatarMediumUrl = $player->avatarmedium;
$this->avatarFullUrl = $player->avatarfull;
$this->personaState = $this->convertPersonaState($player->personastate);
$this->personaStateId = $player->personastate;
$this->realName = $this->checkIssetField($player, 'realname');
$this->primaryClanId = $this->checkIssetField($player, 'primaryclanid');
$this->timecreated = $this->checkIssetField($player, 'timecreated');
$this->personaStateFlags = $this->checkIssetField($player, 'personastateflags');
$this->locCountryCode = $this->checkIssetField($player, 'loccountrycode');
$this->locStateCode = $this->checkIssetField($player, 'locstatecode');
$this->locCityId = $this->checkIssetField($player, 'loccityid');
$this->location = $this->getLocation();
}

protected function getLocation()
{
$countriesFile = json_decode(\file_get_contents(__DIR__ . '/../Resources/countries.json'));
$result = new \stdClass;

if ($this->locCountryCode != null) {
$result->country = $countriesFile->{$this->locCountryCode}->name;
}

if ($this->locCountryCode != null && $this->locStateCode != null) {
$result->state = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->name;
}

if ($this->locCountryCode != null && $this->locStateCode != null && $this->locCityId != null) {
if (! empty($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities)) {
$result->city = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities->{$this->locCityId}->name;
}
}

return $result;
}

protected function convertPersonaState($personaState)
{
switch ($personaState) {
case 0:
return '<span class="text-error">Offline</span>';
case 1:
return '<span class="text-success">Online</span>';
case 2:
return '<span class="text-warning">Busy</span>';
case 3:
return '<span class="text-warning">Away</span>';
case 4:
return '<span class="text-warning">Snooze</span>';
case 5:
return 'Looking to Trade';
case 6:
return 'Looking to Play';
}
}
}
1 change: 1 addition & 0 deletions src/Syntax/SteamApi/Resources/countries.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/BaseTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function checkPlayerProperties($friendsList)
$this->assertObjectHasAttributes($attributes, $friendsList[0]);

$attributes = [
'locCountryCode', 'locStateCode', 'locCityId'
'locCountryCode', 'locStateCode', 'locCityId', 'location'
];
$this->assertObjectHasAttributes($attributes, $friendsList[0]);

Expand Down

0 comments on commit a92859f

Please sign in to comment.