diff --git a/webapp/controller/RankingController.class.php b/webapp/controller/RankingController.class.php index 1a1fcd6d..7338f88b 100644 --- a/webapp/controller/RankingController.class.php +++ b/webapp/controller/RankingController.class.php @@ -51,18 +51,25 @@ class RankingController extends BaseAuthedController { { $userInfo = $this->_getOrmUserInfo(); $type = getReqVal('type', 0); + + if (! RankBattle::inspectType($type)){ + $this->_rspErr(1, 'type param error'); + return; + } $list = RankBattle::getTopLimit($type,100); $rankingList = array(); $ranked = 1; - foreach ($list as $row) { - $user = User::find($row['account_id']); - array_push($rankingList, array( - 'ranked' => $ranked++, - 'user' => $this->_extractUserInfo($user), - 'value' => $row['value'], - 'modifytime' => $row['modifytime'], - )); + if (count($list) > 0){ + foreach ($list as $row) { + $user = User::find($row['account_id']); + array_push($rankingList, array( + 'ranked' => $ranked++, + 'user' => $this->_extractUserInfo($user), + 'value' => $row['value'], + 'modifytime' => $row['modifytime'], + )); + } } $myRanked = array( @@ -78,9 +85,11 @@ class RankingController extends BaseAuthedController { } $lists = RankBattle::getTopLimit($type,10000,array('account_id')); - foreach ($lists as $k=>$row){ - if ($userInfo['account_id'] == $row['account_id']){ - $myRanked['ranked'] = $k+1; + if (count($lists) > 0){ + foreach ($lists as $k=>$row){ + if ($userInfo['account_id'] == $row['account_id']){ + $myRanked['ranked'] = $k+1; + } } } diff --git a/webapp/models/RankBattle.php b/webapp/models/RankBattle.php index 4f4ccb05..82333057 100644 --- a/webapp/models/RankBattle.php +++ b/webapp/models/RankBattle.php @@ -14,7 +14,7 @@ class RankBattle extends BaseModel const TOP_THREE_TIMES = 4; const KILL_TIMES = 5; - private static function inspectType($type){ + public static function inspectType($type){ if (!in_array($type,array( self::GAME_TIMES, self::WIN_TIMES,