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
+14 -18
View File
@@ -129,7 +129,7 @@ DBService.prototype.requestWritingInfo = function(writingID, onSucceededListener
// typing exam
DBService.prototype.addPrevHourTypingExamRecord = function(writingID, record, onSucceededListener, onFailedListener) {
var xhr = this.makeXhr(
"php/record/update_writing_record.php",
"php/record/update_typing_exam_record.php",
(function() { // onreadystatechange
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
@@ -152,7 +152,7 @@ DBService.prototype.addPrevHourTypingExamRecord = function(writingID, record, on
DBService.prototype.updateTypingExamRecord = function(writingID, record, onSucceededListener, onFailedListener) {
var xhr = this.makeXhr(
"php/record/update_writing_record.php",
"php/record/update_typing_exam_record.php",
(function() { // onreadystatechange
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
@@ -174,7 +174,7 @@ DBService.prototype.updateTypingExamRecord = function(writingID, record, onSucce
DBService.prototype.getTypingExamHighestRecord = function(writingID, onSucceededListener, onFailedListener) {
var xhr = this.makeXhr(
"php/record/get_writing_highest_record.php",
"php/record/get_typing_exam_highest_record.php",
(function() { // onreadystatechange
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
@@ -194,20 +194,17 @@ DBService.prototype.getTypingExamHighestRecord = function(writingID, onSucceeded
}
DBService.prototype.requestWritingPlayerHistory = function(writingID, date, onSucceededListener, onFailedListener) {
/*
var historyRecordManager = new HistoryRecordManager();
if(isDebugMode()) {
this.loadTempPlayerHistory(historyRecordManager);
if(onSucceededListener !== null)
onSucceededListener(historyRecordManager);
return;
}
*/
/*
var xhr = this.makeXhr(
"php/record/history_record.php",
"php/record/get_typing_exam_history_record.php",
(function() { // onreadystatechange
if(xhr.readyState == 4 && xhr.status == 200) {
var replyJSON = JSON.parse(xhr.responseText);
@@ -225,24 +222,24 @@ DBService.prototype.requestWritingPlayerHistory = function(writingID, date, onSu
+ "&writingID=" + writingID
+ "&date=" + date
);
*/
}
DBService.prototype.parseJSONtoHistoryRecord = function(json) {
DBService.prototype.parseJSONtoHistoryRecord = function(jsonData) {
var historyRecordManager = new HistoryRecordManager();
if(typeof json === "undefined")
if(typeof jsonData === "undefined")
return historyRecordManager;
if(typeof json.history === "undefined")
if(typeof jsonData.history === "undefined")
return historyRecordManager;
var count = json.history.length;
var count = jsonData.history.length;
for(var i = 0; i < count; i++) {
var record = new HistoryRecord(
json.history[i]["Date"],
json.history[i]["AppName"],
json.history[i]["HighScore"]
jsonData.history[i]["Date"],
jsonData.history[i]["AppName"],
jsonData.history[i]["HighScore"]
);
historyRecordManager.push(record);
}
@@ -250,7 +247,6 @@ DBService.prototype.parseJSONtoHistoryRecord = function(json) {
return historyRecordManager;
}
DBService.prototype.loadTempPlayerHistory = function(historyRecordManager) {
// historyRecordManager.push(new HistoryRecord("05/14", "space_invaders", 14460));
historyRecordManager.push(new HistoryRecord("2019-05-13 00:00:00", "space_invaders", 14460));
+3 -1
View File
@@ -62,7 +62,9 @@ var Result = {
back: function() {
if(isTypingPracticeApp())
if(isTypingExamApp())
location.href = '../../web/client/menu_typing_exam.html';
else if(isTypingPracticeApp())
location.href = '../../web/client/menu_typing_practice.html';
else if(isTypingTestApp())
location.href = '../../web/client/menu_typing_test.html';
-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();
?>
+22
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();
?>
@@ -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();
?>