Fix: get_typing_exam_history_record

This commit is contained in:
2019-07-18 09:39:31 +09:00
parent 031be3ad1b
commit e324e9c41a
15 changed files with 83 additions and 38 deletions
-1
View File
@@ -12,5 +12,4 @@ class DBMethodContainer
{
}
}
?>
-2
View File
@@ -53,7 +53,5 @@ if ($command === "addTypingExamHighestRecord") {
$jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData);
}
$jsonBuilder->sendResultSuccess();
?>
-2
View File
@@ -46,7 +46,5 @@ if ($command === "deleteWritingRecordAll") {
// $jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded");
}
$jsonBuilder->sendResultSuccess();
?>
+23 -1
View File
@@ -161,6 +161,28 @@ class TypingExamCollection extends DBMethodContainer
$stmt->close();
}
}
function getHistoryRecord($maestroID, $playerID, $writingID, $date) {
$query = "
SELECT DATE(RecordDateTime), MAX(Record)
FROM typing_exam_record
WHERE MaestroID = ? AND PlayerID = ? AND DATE(RecordDateTime) <= ? AND WritingID = ?
GROUP BY DATE(RecordDateTime)
ORDER BY RecordDateTime DESC
LIMIT 7";
$stmt = $this->mysqli->prepare($query);
$stmt->bind_param('iisi', $maestroID, $playerID, $date, $writingID);
$stmt->execute();
$stmt->bind_result($date, $highestRecord);
$historyRecordArray = array();
while($stmt->fetch()) {
$historyRecord['Date'] = $date;
$historyRecord['HighScore'] = $highestRecord;
$historyRecord['AppName'] = "TypingExam";
array_push($historyRecordArray, $historyRecord);
}
return $historyRecordArray;
}
}
?>
-1
View File
@@ -54,5 +54,4 @@ class WritingCollection extends DBMethodContainer
}
}
?>
-1
View File
@@ -80,5 +80,4 @@ class DBConnector
return $this->mysqli;
}
}
?>
-1
View File
@@ -47,5 +47,4 @@ class JsonBuilder
}
}
?>
@@ -33,5 +33,4 @@ if ($highestRecordData === null) {
}
$jsonBuilder->sendResultSuccess();
?>
@@ -0,0 +1,37 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestroID"];
$playerID = $_POST["playerID"];
$writingID = $_POST["writingID"];
$date = $_POST["date"];
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());
$historyRecordArray = $typingExam->getHistoryRecord($maestroID, $playerID, $writingID, $date);
$jsonBuilder->setData("history", $historyRecordArray);
if ($historyRecordArray === null) {
$jsonBuilder->sendResultFail();
exit;
}
$jsonBuilder->sendResultSuccess();
?>
-59
View File
@@ -1,59 +0,0 @@
<?php
header('Content-Type: application/json');
$maestro_id = $_POST["MaestroID"];
$app_id = $_POST["AppID"];
$player_id = $_POST["PlayerID"];
$date = $_POST["Date"];
include "./../setup/connect_db.php";
include "./../lib/util_app.php";
$replyJSON = get_history_record($maestro_id, $app_id, $player_id, $date);
if($replyJSON.length === 0) {
send_error_message($replyJSON, "히스토리 기록 없음");
$db_conn->close();
exit;
}
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
function get_history_record($maestro_id, $app_id, $player_id, $date) {
global $db_conn;
$query = "
FROM best_record BR
INNER JOIN app AS AA
ON BR.MaestroID = ? AND BR.PlayerID = ? AND DATE(BR.RecordDateTime) <= ? AND BR.AppID = ? AND BR.AppID = AA.AppID
GROUP BY DATE(BR.RecordDateTime)
ORDER BY BR.RecordDateTime DESC
LIMIT 7
";
if(is_highest_record_prefer_app($app_id)) {
$query = "SELECT DATE(BR.RecordDateTime) AS Date, MAX(BR.BestRecord) AS HighScore, AA.AppName AS AppName".$query;
}
else {
$query = "SELECT DATE(BR.RecordDateTime) AS Date, MIN(BR.BestRecord) AS HighScore, AA.AppName AS AppName".$query;
}
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iisi', $maestro_id, $player_id, $date, $app_id);
$stmt->execute();
$stmt->bind_result($date, $score, $app_name);
$history_record_array = array();
while($stmt->fetch()) {
$history_record['Date'] = $date;
$history_record['HighScore'] = $score;
$history_record['AppName'] = $app_name;
array_push($history_record_array, $history_record);
array_push($return_array, $history_record);
}
$return_array['history'] = $history_record_array;
return $return_array;
}
?>
@@ -82,5 +82,4 @@ function updateHighestRecord($maestroID, $playerID, $writingID, $record)
}
}
}
?>
-1
View File
@@ -28,5 +28,4 @@ $systemWritingArray = $writingCollection->getSystemWritingList();
$jsonBuilder->setData("writingArray", $systemWritingArray);
$jsonBuilder->sendResultSuccess();
?>
-1
View File
@@ -31,5 +31,4 @@ $writingInfo = $writingCollection->getWritingInfo($writingID);
// $jsonBuilder->setData("writerID", $writingInfo["writerID"]);
$jsonBuilder->setData("writingInfo", $writingInfo);
$jsonBuilder->sendResultSuccess();
?>