Ejemplo n.º 1
0
 public function sitemap()
 {
     // todo, cache this!
     $path = $this->_getRequest()->urlSprintf('%p%d.%t') . '/users/';
     $return = [];
     foreach (SortFieldEnum::all() as $item) {
         $x = User::orderBy($item, 'desc')->select('id')->limit(1000)->get();
         foreach ($x as $user) {
             $return[] = $path . $user->id;
         }
     }
     return implode("\n\r", $return);
 }
Ejemplo n.º 2
0
 public function view($playerId)
 {
     $user = User::firstOrNew(['id' => $playerId]);
     $this->_updateUser($user, true);
     // Get total users
     $cache = new UsersCountCache();
     $usersCount = $cache->retrieve();
     // Title
     $title = $user->name;
     if ($user->real_name) {
         $title .= ' (' . $user->real_name . ')';
     }
     $this->layout()->setData('title', $title);
     return new UserView($user, $usersCount);
 }
Ejemplo n.º 3
0
 protected function _updateUser(User $user, $scanFriends = false)
 {
     if ($this->_isBot()) {
         return $user;
     }
     $week = $user->updated_at < date('Y-m-d G:i:s', strtotime('-7 days'));
     $month = $user->updated_at_friends < date('Y-m-d G:i:s', strtotime('-28 days'));
     if ($week || $month) {
         // Update ranks
         foreach (SortFieldEnum::all() as $item) {
             $r = 'rank_' . $item;
             $user->{$r} = Manager::table($r)->select('id')->where('user_id', '=', $user->id)->pluck('id');
         }
         // Steam API stuff
         $playerService = new SteamPlayerService($this->_getApi());
         $userService = new SteamUser($this->_getApi());
         // User details
         $details = $userService->getPlayerSummary($user->id);
         $user->name = $details->personaname;
         $user->profile = $details->profileurl;
         $user->avatar_large = $details->avatarfull;
         $user->avatar_medium = $details->avatarmedium;
         $user->real_name = $details->realname;
         $user->time_on_steam = $details->timecreated;
         $user->country = $details->loccountrycode;
         // Games
         $games = $playerService->getOwnedGames($user->id);
         $json = [];
         foreach ($games as $game) {
             $json[$game->appId] = $game->playtimeForever;
         }
         $user->games = count($games);
         $user->games_json = json_encode($json);
         $user->time = array_sum($json);
         // level
         $level = $playerService->getSteamLevel($user->id);
         $user->level = $level->level;
         // Badges
         $badges = $playerService->getBadges($user->id);
         $user->badges = count($badges->badges);
         $user->xp = $badges->playerXp;
         $user->xp_needed = $badges->playerXpNeededToLevelUp;
         $user->xp_current = $badges->playerXpNeededCurrentLevel;
         $xp = 0;
         foreach ($badges->badges as $badge) {
             $xp += $badge->xp;
         }
         $user->xp_from_badges = $xp;
         // Friends
         try {
             $friends = $userService->getFriendList($user->id);
             $user->friends = count($friends);
             $user->friends_json = json_encode($friends);
             if ($scanFriends && $month) {
                 $this->_queueFriends($friends);
             }
         } catch (SteamException $e) {
         }
         $user->updated_at_friends = date('Y-m-d G:i:s');
         // Save
         $user->save();
     }
     return $user;
 }
Ejemplo n.º 4
0
 public function updateUser()
 {
     $user = User::firstOrNew(['id' => $this->_getRequest()->request->get('user')]);
     $this->_updateUser($user, false);
     return 'Stub updated.';
 }