public static function getUserFacebookFriends(GameUsers $user)
 {
     if (!empty($user)) {
         $userId = $user->getUserId();
         $fbId = $user->getFacebookId();
         $oauthTOken = $user->getOauthToken();
         if (!empty($userId) && !empty($fbId) && !empty($oauthTOken)) {
             $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true));
             $facebook->setAccessToken($oauthTOken);
             try {
                 $fbFriends = array();
                 $apiUrl = "/me/friends";
                 while (!empty($apiUrl)) {
                     $result = $facebook->api($apiUrl);
                     $apiUrl = null;
                     if (!empty($result)) {
                         $data = null;
                         if (isset($result["data"])) {
                             $data = $result["data"];
                         }
                         if (!empty($data) && sizeof($data)) {
                             foreach ($data as $fbFriend) {
                                 if (!empty($fbFriend)) {
                                     array_push($fbFriends, $fbFriend);
                                 }
                             }
                         }
                         unset($data);
                         if (isset($result["paging"])) {
                             $paging = $result["paging"];
                             if (!empty($paging) && isset($paging["next"]) && !empty($paging["next"])) {
                                 $next = $paging["next"];
                                 if (strpos($next, "/friends")) {
                                     $apiUrl = "/me" . substr($next, strpos($next, "/friends"));
                                 }
                                 unset($next);
                             }
                             unset($paging);
                         }
                     }
                     unset($result);
                     unset($apiUrl);
                 }
                 return $fbFriends;
             } catch (Exception $exc) {
                 error_log("FriendUtils>getUserFacebookFriends> Error : " . $exc->getMessage() . " Trace : " . $exc->getTraceAsString());
             }
         }
     }
     return null;
 }
 public static function updateXP(GameUsers $user, GameUsers $opponent, $roomGroupId, $action, $gameId = null, $double = 0, $normal = true, $type = null, $time = null)
 {
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($user) && !empty($action)) {
         $gain = 0;
         $xp = $user->getUserXP();
         if ($action == GameUtils::$GAME_RESULT_ACTION_WIN) {
             $gain = (int) GameConstantUtil::getConstant(GameUtils::$CONSTANT_WIN_XP_GAIN);
             if (!$normal) {
                 $gain = $gain * 2;
             }
         } else {
             if ($action == GameUtils::$GAME_RESULT_ACTION_LOST) {
                 if ($type == GameUtils::$GAME_RESULT_ACTION_TYPE_QUIT) {
                     $gain = (int) GameConstantUtil::getConstant(GameUtils::$CONSTANT_QUIT_XP_GAIN);
                 } else {
                     if ($type == GameUtils::$GAME_RESULT_ACTION_TYPE_LEFT || $type == GameUtils::$GAME_RESULT_ACTION_TYPE_TIMESUP) {
                         $gain = (int) GameConstantUtil::getConstant(GameUtils::$CONSTANT_CONN_LOST_XP_GAIN);
                     } else {
                         $gain = (int) GameConstantUtil::getConstant(GameUtils::$CONSTANT_LOSE_XP_GAIN);
                     }
                 }
             } else {
                 $xp = -1;
             }
         }
         if ($xp >= 0) {
             $gameResult = $action . "_" . $normal . "_" . $double . "_" . $type;
             $oppId = null;
             if (!empty($opponent)) {
                 $oppId = $opponent->getUserId();
             }
             if (empty($time)) {
                 $time = time();
             }
             Queue::addUserXPLog($user->userId, $gain, $time, GameUserXpLog::$CONSTANT_LOG_TYPE_GAME, $gameId, $gameResult, $oppId);
             $xp = $xp + $gain;
             $user->setUserXP($xp);
             $userLevel = GameUserLevel::getUserLevel($xp);
             $user->userLevel = $userLevel;
             if (!empty($userLevel) && !empty($userLevel->levelNumber)) {
                 $user->setUserLevelNumber($userLevel->levelNumber);
             }
             $result->success = true;
         } else {
             $result->success = false;
             $result->result = "Action unknown";
         }
     }
     return $result;
 }