Ejemplo n.º 1
0
 public static function getUserFriends($userId)
 {
     if (!empty($userId)) {
         $SQL = "SELECT level.levelName as level_levelname,users.coins as leaderboard_coins,users.* FROM " . TBL_GAME_USERS . " users," . TBL_GAME_USER_LEVEL . " as level," . TBL_GAME_USER_FRIENDS . " as friend WHERE friend.userId=" . DBUtils::mysql_escape($userId, 1) . " AND friend.friendId=users.userId AND users.userLevelNumber=level.levelNumber ORDER BY users.coins DESC";
         $query = mysql_query($SQL, DBUtils::getManualConnection());
         if (!empty($query)) {
             $friends = array();
             $user = LeaderBoardUtils::getUserAllBoard($userId);
             $userAdded = false;
             while ($db_field = mysql_fetch_assoc($query)) {
                 $friend = GameUsers::createFromSQLWithLeaderboard($db_field);
                 if (!empty($friend)) {
                     $friendId = $friend->getUserId();
                     if (!empty($friendId)) {
                         if (!empty($user) && !$userAdded) {
                             $userId = $user->getUserId();
                             if (!empty($userId)) {
                                 if ($user->getCoins() > $friend->getCoins()) {
                                     $userAdded = true;
                                     array_push($friends, $user);
                                 }
                             }
                         }
                         array_push($friends, $friend);
                     }
                 }
             }
             if (!empty($friends) && sizeof($friends) > 0) {
                 return $friends;
             }
         }
     }
     return null;
 }
Ejemplo n.º 2
0
$userId = null;
if (isset($_POST['userId'])) {
    $userId = $_POST['userId'];
} else {
    if (isset($_GET['userId'])) {
        $userId = $_GET['userId'];
    }
}
$page = null;
if (isset($_GET['page'])) {
    $page = $_GET['page'];
} else {
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
}
$pageCount = null;
if (isset($_GET['pageCount'])) {
    $pageCount = $_GET['pageCount'];
} else {
    if (isset($_POST['pageCount'])) {
        $pageCount = $_POST['pageCount'];
    }
}
if (!empty($action)) {
    $result = LeaderBoardUtils::getLeaderBoard($userId, $action, $page, $pageCount);
} else {
    $result->result = "Acion is unknown";
}
echo json_encode($result);
exit(1);
 public static function getAllLeaderBoard($userId = null, $action = null, $page = 0, $pageCount = 10)
 {
     $result = new FunctionResult();
     $result->success = false;
     if ($action == LeaderBoardUtils::$LEADERBOARD_ACTION_ALL) {
         $SQL = "SELECT users.coins as leaderboard_coins,users.lastLoginDate as leaderboard_lastplayed,level.levelName as level_levelname,level.levelNumber as level_levelnumber,level.maxXP as level_maxXP,level.minXP as level_minXP,users.* FROM " . TBL_GAME_USERS . " users," . TBL_GAME_USER_LEVEL . " as level WHERE users.userLevelNumber=level.levelNumber ORDER BY users.coins DESC LIMIT " . DBUtils::mysql_escape($page) . "," . DBUtils::mysql_escape($pageCount);
         $query = mysql_query($SQL, DBUtils::getManualConnection());
         if (empty($query)) {
             $result->success = true;
             $result->result = new stdClass();
             $result->result->list = array();
             $result->result->page = $page;
             $result->result->pageCount = $pageCount;
         } else {
             $list = array();
             $userAdded = false;
             while ($db_field = mysql_fetch_assoc($query)) {
                 $user = GameUsers::createFromSQLWithLeaderboard($db_field);
                 if (!empty($user)) {
                     $userId_ = $user->getUserId();
                     if (!empty($userId_)) {
                         array_push($list, $user);
                     }
                     if ($userId_ == $userId) {
                         $userAdded = true;
                     }
                 }
             }
             if (!$userAdded) {
                 $user = LeaderBoardUtils::getUserAllBoard($userId);
                 if (!empty($user)) {
                     array_push($list, $user);
                 }
             }
             $result->success = true;
             $result->result = new stdClass();
             $result->result->list = $list;
             $result->result->page = $page;
             $result->result->pageCount = $pageCount;
         }
     } else {
         $result->result = "Action is unknown";
     }
     return $result;
 }