Add: ranking for app

This commit is contained in:
2018-09-05 09:21:48 +09:00
parent 3a1be0744c
commit 3d4852c42c
7 changed files with 529 additions and 19 deletions
+97
View File
@@ -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;
}
?>