@@ -46,6 +46,8 @@ class Player extends BaseContainer {
4646
4747 public $ locCityId ;
4848
49+ public $ location ;
50+
4951 public function __construct ($ player )
5052 {
5153 $ this ->steamId = $ player ->steamid ;
@@ -63,13 +65,36 @@ public function __construct($player)
6365 $ this ->avatarFullUrl = $ player ->avatarfull ;
6466 $ this ->personaState = $ this ->convertPersonaState ($ player ->personastate );
6567 $ this ->personaStateId = $ player ->personastate ;
66- $ this ->realName = $ this ->checkIssetField ($ player , 'realName ' );
67- $ this ->primaryClanId = $ this ->checkIssetField ($ player , 'primaryClanId ' );
68+ $ this ->realName = $ this ->checkIssetField ($ player , 'realname ' );
69+ $ this ->primaryClanId = $ this ->checkIssetField ($ player , 'primaryclanid ' );
6870 $ 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 ' );
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 ;
7398 }
7499
75100 protected function convertPersonaState ($ personaState )
0 commit comments