Add: get_typing_exam_ranking_records
This commit is contained in:
@@ -181,8 +181,84 @@ class TypingExamCollection extends DBMethodContainer
|
||||
$historyRecord['AppName'] = "TypingExam";
|
||||
array_push($historyRecordArray, $historyRecord);
|
||||
}
|
||||
$stmt->close();
|
||||
|
||||
return $historyRecordArray;
|
||||
}
|
||||
|
||||
function getRankingRecordHour($maestroID, $writingID, $date, $time) {
|
||||
$query = "
|
||||
SELECT TER.playerID As PlayerID, U.Name AS Name, MAX(TER.Record) AS HighScore
|
||||
FROM typing_exam_record TER, player U
|
||||
WHERE TER.MaestroID = ? AND TER.playerID = U.playerID AND YEAR(TER.RecordDateTime) = YEAR(?) AND MONTH(TER.RecordDateTime) = MONTH(?) AND DAYOFMONTH(TER.RecordDateTime) = DAYOFMONTH(?) AND HOUR(TER.RecordDateTime) = HOUR(?) AND TER.WritingID = ?
|
||||
GROUP BY TER.playerID
|
||||
ORDER BY MAX(TER.Record) DESC;
|
||||
";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param('issssi', $maestroID, $date, $date, $date, $time, $writingID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $highScore);
|
||||
|
||||
$rankingRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$rankingRecord['PlayerID'] = $playerID;
|
||||
$rankingRecord['Name'] = $name;
|
||||
$rankingRecord['HighScore'] = $highScore;
|
||||
array_push($rankingRecordArray, $rankingRecord);
|
||||
}
|
||||
$stmt->close();
|
||||
|
||||
return $rankingRecordArray;
|
||||
}
|
||||
|
||||
function getRankingRecordDay($maestroID, $writingID, $date) {
|
||||
$query = "
|
||||
SELECT TER.playerID As PlayerID, U.Name AS Name, MAX(TER.Record) AS HighScore
|
||||
FROM typing_exam_record TER, player U
|
||||
WHERE TER.MaestroID = ? AND TER.playerID = U.playerID AND YEAR(TER.RecordDateTime) = YEAR(?) AND MONTH(TER.RecordDateTime) = MONTH(?) AND DAYOFMONTH(TER.RecordDateTime) = DAYOFMONTH(?) AND TER.WritingID = ?
|
||||
GROUP BY TER.playerID
|
||||
ORDER BY MAX(TER.Record) DESC;
|
||||
";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param('isssi', $maestroID, $date, $date, $date, $writingID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $highScore);
|
||||
|
||||
$rankingRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$rankingRecord['PlayerID'] = $playerID;
|
||||
$rankingRecord['Name'] = $name;
|
||||
$rankingRecord['HighScore'] = $highScore;
|
||||
array_push($rankingRecordArray, $rankingRecord);
|
||||
}
|
||||
$stmt->close();
|
||||
|
||||
return $rankingRecordArray;
|
||||
}
|
||||
|
||||
function getRankingRecordMonth($maestroID, $writingID, $date) {
|
||||
$query = "
|
||||
SELECT TER.playerID As PlayerID, U.Name AS Name, MAX(TER.Record) AS HighScore
|
||||
FROM typing_exam_record TER, player U
|
||||
WHERE TER.MaestroID = ? AND TER.playerID = U.playerID AND YEAR(TER.RecordDateTime) = YEAR(?) AND MONTH(TER.RecordDateTime) = MONTH(?) AND TER.WritingID = ?
|
||||
GROUP BY TER.playerID
|
||||
ORDER BY MAX(TER.Record) DESC;
|
||||
";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param('issi', $maestroID, $date, $date, $writingID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $highScore);
|
||||
|
||||
$rankingRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$rankingRecord['PlayerID'] = $playerID;
|
||||
$rankingRecord['Name'] = $name;
|
||||
$rankingRecord['HighScore'] = $highScore;
|
||||
array_push($rankingRecordArray, $rankingRecord);
|
||||
}
|
||||
$stmt->close();
|
||||
|
||||
return $rankingRecordArray;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestroID"];
|
||||
$playerID = $_POST["playerID"];
|
||||
$writingID = $_POST["writingID"];
|
||||
$date = $_POST["date"];
|
||||
$time = $_POST["time"];
|
||||
|
||||
include "./../lib/json_builder.php";
|
||||
include "./../lib/connect_db.php";
|
||||
|
||||
$jsonBuilder = new JsonBuilder();
|
||||
$dbConnector = new DBConnector();
|
||||
|
||||
$isConnected = $dbConnector->connectDB();
|
||||
if (!$isConnected) {
|
||||
$jsonBuilder->setErrorMessage("DB connection : failed");
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
include "./../db/db_method_container.php";
|
||||
include "./../db/typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
|
||||
$rankingRecordArray = $typingExam->getRankingRecordDay($maestroID, $writingID, $date);
|
||||
$jsonBuilder->setData("rankingDay", $rankingRecordArray);
|
||||
|
||||
if ($rankingRecordArray === null) {
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonBuilder->sendResultSuccess();
|
||||
?>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestroID"];
|
||||
$playerID = $_POST["playerID"];
|
||||
$writingID = $_POST["writingID"];
|
||||
$date = $_POST["date"];
|
||||
$time = $_POST["time"];
|
||||
|
||||
include "./../lib/json_builder.php";
|
||||
include "./../lib/connect_db.php";
|
||||
|
||||
$jsonBuilder = new JsonBuilder();
|
||||
$dbConnector = new DBConnector();
|
||||
|
||||
$isConnected = $dbConnector->connectDB();
|
||||
if (!$isConnected) {
|
||||
$jsonBuilder->setErrorMessage("DB connection : failed");
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
include "./../db/db_method_container.php";
|
||||
include "./../db/typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
|
||||
$rankingRecordArray = $typingExam->getRankingRecordHour($maestroID, $writingID, $date, $time);
|
||||
$jsonBuilder->setData("rankingHour", $rankingRecordArray);
|
||||
|
||||
if ($rankingRecordArray === null) {
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonBuilder->sendResultSuccess();
|
||||
?>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestroID"];
|
||||
$playerID = $_POST["playerID"];
|
||||
$writingID = $_POST["writingID"];
|
||||
$date = $_POST["date"];
|
||||
$time = $_POST["time"];
|
||||
|
||||
include "./../lib/json_builder.php";
|
||||
include "./../lib/connect_db.php";
|
||||
|
||||
$jsonBuilder = new JsonBuilder();
|
||||
$dbConnector = new DBConnector();
|
||||
|
||||
$isConnected = $dbConnector->connectDB();
|
||||
if (!$isConnected) {
|
||||
$jsonBuilder->setErrorMessage("DB connection : failed");
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
include "./../db/db_method_container.php";
|
||||
include "./../db/typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
|
||||
$rankingRecordArray = $typingExam->getRankingRecordMonth($maestroID, $writingID, $date);
|
||||
$jsonBuilder->setData("rankingMonth", $rankingRecordArray);
|
||||
|
||||
if ($rankingRecordArray === null) {
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonBuilder->sendResultSuccess();
|
||||
?>
|
||||
Reference in New Issue
Block a user