示例#1
0
 /**
  * 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 = [];
     $this->playtimes = [];
     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 = [(int) ($recent * 60), (int) ($total * 60)];
         $this->playtimes[$appId] = $playtimes;
     }
 }
示例#2
0
 /**
  * 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;
     }
 }
 /**
  * Fetches the games this user owns
  *
  * @see getGames()
  * @throws SteamCondenserException if an error occurs while parsing the
  *         data
  */
 public function fetchGames()
 {
     $params = ['steamid' => $this->getSteamId64(), 'include_appinfo' => 1, 'include_played_free_games' => 1];
     $gamesData = WebApi::getJSONObject('IPlayerService', 'GetOwnedGames', 1, $params);
     foreach ($gamesData->response->games as $gameData) {
         $game = SteamGame::create($gameData);
         $this->games[$game->getAppId()] = $game;
         if (property_exists($gameData, 'playtime_2weeks')) {
             $recent = $gameData->playtime_2weeks;
         } else {
             $recent = 0;
         }
         $total = $gameData->playtime_forever;
         $this->playtimes[$game->getAppId()] = [$recent, $total];
     }
     return $this->games;
 }