forked from syntaxerrors/Steam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in better location handling. Fixing the casing on the player c…
…ontainer. Fixes syntaxerrors#23
- Loading branch information
Travis Blasingame
authored and
Travis Blasingame
committed
Jun 17, 2015
1 parent
643fa5a
commit a92859f
Showing
4 changed files
with
100 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters