/** * Fetches the games this user owns * * @see getGames() * @throws SteamCondenserException if an error occurs while parsing the * data */ private function fetchGames() { $gamesData = $this->getData($this->getBaseUrl() . '/games?xml=1'); $this->games = array(); $this->playtimes = array(); foreach ($gamesData->games->game as $gameData) { $appId = (int) $gameData->appID; $game = SteamGame::create($appId, $gameData); $this->games[$appId] = $game; $recent = (double) $gameData->hoursLast2Weeks; $total = (double) str_replace(',', '', $gameData->hoursOnRecord); $playtimes = array((int) ($recent * 60), (int) ($total * 60)); $this->playtimes[$appId] = $playtimes; } }
/** * Creates a <var>GameStats</var> object and fetches data from the Steam * Community for the given user and game * * @param string $steamId The custom URL or the 64bit Steam ID of the user * @param string $gameId The app ID or friendly name of the game * @throws SteamCondenserException if the stats cannot be fetched */ protected function __construct($steamId, $gameId) { $this->user = SteamId::create($steamId, false); $url = self::_getBaseUrl($steamId, $gameId) . '?xml=all'; $this->xmlData = $this->getData($url); if ($this->xmlData->error != null && !empty($this->xmlData->error)) { throw new SteamCondenserException((string) $this->xmlData->error); } $this->privacyState = (string) $this->xmlData->privacyState; if ($this->isPublic()) { preg_match('#http://steamcommunity.com/+app/+([1-9][0-9]*)#', (string) $this->xmlData->game->gameLink, $appId); $this->game = SteamGame::create((int) $appId[1], $this->xmlData->game); $this->hoursPlayed = (string) $this->xmlData->stats->hoursPlayed; } }