Add: ranking for app
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "./../lib/send_reply_json.php";
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$maestroID = $_POST["MaestroID"];
|
||||
$appID = $_POST["AppID"];
|
||||
|
||||
|
||||
$rankingHour = get_ranking_hour($maestroID, $appID);
|
||||
$rankingDay = get_ranking_day($maestroID, $appID);
|
||||
$rankingMonth = get_ranking_month($maestroID, $appID);
|
||||
|
||||
set_data("rankingHour", $rankingHour);
|
||||
set_data("rankingDay", $rankingDay);
|
||||
set_data("rankingMonth", $rankingMonth);
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
|
||||
function get_ranking_hour($maestroID, $appID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT BR.PlayerID As PlayerID, P.Name AS Name, MAX(BR.BestRecord) AS BestRecord
|
||||
FROM best_record BR, player P
|
||||
WHERE BR.PlayerID = P.PlayerID AND DATE(BR.RecordDateTime) = DATE(NOW()) AND HOUR(BR.RecordDateTime) = HOUR(NOW()) AND BR.MaestroID = ? AND BR.AppID = ?
|
||||
GROUP BY BR.PlayerID
|
||||
ORDER BY max(BR.BestRecord) DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $appID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $bestRecord);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['PlayerID'] = $playerID;
|
||||
$best_record['Name'] = $name;
|
||||
$best_record['BestRecord'] = $bestRecord;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
}
|
||||
return $bestRecordArray;
|
||||
}
|
||||
|
||||
function get_ranking_day($maestroID, $appID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT BR.PlayerID As PlayerID, P.Name AS Name, MAX(BR.BestRecord) AS BestRecord
|
||||
FROM best_record BR, player P
|
||||
WHERE BR.PlayerID = P.PlayerID AND DATE(BR.RecordDateTime) = DATE(NOW()) AND BR.MaestroID = ? AND BR.AppID = ?
|
||||
GROUP BY BR.PlayerID
|
||||
ORDER BY max(BR.BestRecord) DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $appID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $bestRecord);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['PlayerID'] = $playerID;
|
||||
$best_record['Name'] = $name;
|
||||
$best_record['BestRecord'] = $bestRecord;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
}
|
||||
return $bestRecordArray;
|
||||
}
|
||||
|
||||
function get_ranking_month($maestroID, $appID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT BR.PlayerID As PlayerID, P.Name AS Name, MAX(BR.BestRecord) AS BestRecord
|
||||
FROM best_record BR, player P
|
||||
WHERE BR.PlayerID = P.PlayerID AND MONTH(BR.RecordDateTime) = MONTH(NOW()) AND BR.MaestroID = ? AND BR.AppID = ?
|
||||
GROUP BY BR.PlayerID
|
||||
ORDER BY max(BR.BestRecord) DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $appID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $bestRecord);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['PlayerID'] = $playerID;
|
||||
$best_record['Name'] = $name;
|
||||
$best_record['BestRecord'] = $bestRecord;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
}
|
||||
return $bestRecordArray;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user