Пример #1
0
 /**
  * Returns online Users, currently returns Eloquent User, in future should
  * return Larachat User
  * @return User[] Array with online users
  */
 public static function getOnline()
 {
     $users = array();
     if (\Cache::has('online_users')) {
         // Get active users from cache
         $online_users = \Cache::get('online_users');
         foreach ($online_users as $user) {
             // Get user object
             $temp = \User::find($user[0]);
             $now = Date::forge();
             $diff = Date::diff($now, $temp->updated_at);
             // check timestamp for 5 minutes
             if ($diff->i > 5 || $diff->y > 0 || $diff->m > 0 || $diff->d > 0 || $diff->h > 0) {
                 // If user hasn't been active for the last 5 minutes
                 // remove from cache
                 // TODO: change this to new non-static function
                 static::removeNick($temp->id);
             } else {
                 $temp->nick = $user[1];
                 $users[] = $temp;
             }
         }
     }
     return $users;
 }