From e324e9c41a5f022cbac5f1fd12d1462e6ee12c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 18 Jul 2019 09:39:31 +0900 Subject: [PATCH] Fix: get_typing_exam_history_record --- src/game/lib/db_service.js | 44 +++++++++---------- src/game/result/result.js | 4 +- src/web/php/db/db_method_container.php | 1 - src/web/php/db/tdd_run.php | 2 - src/web/php/db/tdd_setup.php | 2 - src/web/php/db/typing_exam_collection.php | 24 +++++++++- src/web/php/db/writing_collection.php | 1 - src/web/php/lib/connect_db.php | 1 - src/web/php/lib/json_builder.php | 1 - ...php => get_typing_exam_highest_record.php} | 1 - .../record/get_typing_exam_history_record.php | 37 ++++++++++++++++ ...cord.php => update_typing_exam_record.php} | 1 - src/web/php/writing/player_list.php | 1 - src/web/php/writing/writing_info.php | 1 - .../{php => server}/record/history_record.php | 0 15 files changed, 83 insertions(+), 38 deletions(-) rename src/web/php/record/{get_writing_highest_record.php => get_typing_exam_highest_record.php} (99%) create mode 100644 src/web/php/record/get_typing_exam_history_record.php rename src/web/php/record/{update_writing_record.php => update_typing_exam_record.php} (99%) rename src/web/{php => server}/record/history_record.php (100%) diff --git a/src/game/lib/db_service.js b/src/game/lib/db_service.js index bdccbcc..0dbf481 100644 --- a/src/game/lib/db_service.js +++ b/src/game/lib/db_service.js @@ -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 historyRecordManager = new HistoryRecordManager(); + 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)); diff --git a/src/game/result/result.js b/src/game/result/result.js index dbd91a6..d3c2227 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -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'; diff --git a/src/web/php/db/db_method_container.php b/src/web/php/db/db_method_container.php index 0d6ff9f..0156b8e 100644 --- a/src/web/php/db/db_method_container.php +++ b/src/web/php/db/db_method_container.php @@ -12,5 +12,4 @@ class DBMethodContainer { } } - ?> \ No newline at end of file diff --git a/src/web/php/db/tdd_run.php b/src/web/php/db/tdd_run.php index 579774f..d8b7a3e 100644 --- a/src/web/php/db/tdd_run.php +++ b/src/web/php/db/tdd_run.php @@ -53,7 +53,5 @@ if ($command === "addTypingExamHighestRecord") { $jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData); } - $jsonBuilder->sendResultSuccess(); - ?> \ No newline at end of file diff --git a/src/web/php/db/tdd_setup.php b/src/web/php/db/tdd_setup.php index a1302ea..0d3f61e 100644 --- a/src/web/php/db/tdd_setup.php +++ b/src/web/php/db/tdd_setup.php @@ -46,7 +46,5 @@ if ($command === "deleteWritingRecordAll") { // $jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded"); } - $jsonBuilder->sendResultSuccess(); - ?> \ No newline at end of file diff --git a/src/web/php/db/typing_exam_collection.php b/src/web/php/db/typing_exam_collection.php index 2fad7d9..4472218 100644 --- a/src/web/php/db/typing_exam_collection.php +++ b/src/web/php/db/typing_exam_collection.php @@ -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; + } +} ?> \ No newline at end of file diff --git a/src/web/php/db/writing_collection.php b/src/web/php/db/writing_collection.php index 175a8de..38f36d3 100644 --- a/src/web/php/db/writing_collection.php +++ b/src/web/php/db/writing_collection.php @@ -54,5 +54,4 @@ class WritingCollection extends DBMethodContainer } } - ?> \ No newline at end of file diff --git a/src/web/php/lib/connect_db.php b/src/web/php/lib/connect_db.php index ea49af0..4cf2848 100644 --- a/src/web/php/lib/connect_db.php +++ b/src/web/php/lib/connect_db.php @@ -80,5 +80,4 @@ class DBConnector return $this->mysqli; } } - ?> \ No newline at end of file diff --git a/src/web/php/lib/json_builder.php b/src/web/php/lib/json_builder.php index d6d62d3..a33442d 100644 --- a/src/web/php/lib/json_builder.php +++ b/src/web/php/lib/json_builder.php @@ -47,5 +47,4 @@ class JsonBuilder } } - ?> \ No newline at end of file diff --git a/src/web/php/record/get_writing_highest_record.php b/src/web/php/record/get_typing_exam_highest_record.php similarity index 99% rename from src/web/php/record/get_writing_highest_record.php rename to src/web/php/record/get_typing_exam_highest_record.php index 25984d5..b8a6e6b 100644 --- a/src/web/php/record/get_writing_highest_record.php +++ b/src/web/php/record/get_typing_exam_highest_record.php @@ -33,5 +33,4 @@ if ($highestRecordData === null) { } $jsonBuilder->sendResultSuccess(); - ?> \ No newline at end of file diff --git a/src/web/php/record/get_typing_exam_history_record.php b/src/web/php/record/get_typing_exam_history_record.php new file mode 100644 index 0000000..f6111fa --- /dev/null +++ b/src/web/php/record/get_typing_exam_history_record.php @@ -0,0 +1,37 @@ +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(); +?> \ No newline at end of file diff --git a/src/web/php/record/update_writing_record.php b/src/web/php/record/update_typing_exam_record.php similarity index 99% rename from src/web/php/record/update_writing_record.php rename to src/web/php/record/update_typing_exam_record.php index f90b46d..4ae2d09 100644 --- a/src/web/php/record/update_writing_record.php +++ b/src/web/php/record/update_typing_exam_record.php @@ -82,5 +82,4 @@ function updateHighestRecord($maestroID, $playerID, $writingID, $record) } } } - ?> \ No newline at end of file diff --git a/src/web/php/writing/player_list.php b/src/web/php/writing/player_list.php index d157e69..9353612 100644 --- a/src/web/php/writing/player_list.php +++ b/src/web/php/writing/player_list.php @@ -28,5 +28,4 @@ $systemWritingArray = $writingCollection->getSystemWritingList(); $jsonBuilder->setData("writingArray", $systemWritingArray); $jsonBuilder->sendResultSuccess(); - ?> \ No newline at end of file diff --git a/src/web/php/writing/writing_info.php b/src/web/php/writing/writing_info.php index 74dc767..6d3fd35 100644 --- a/src/web/php/writing/writing_info.php +++ b/src/web/php/writing/writing_info.php @@ -31,5 +31,4 @@ $writingInfo = $writingCollection->getWritingInfo($writingID); // $jsonBuilder->setData("writerID", $writingInfo["writerID"]); $jsonBuilder->setData("writingInfo", $writingInfo); $jsonBuilder->sendResultSuccess(); - ?> \ No newline at end of file diff --git a/src/web/php/record/history_record.php b/src/web/server/record/history_record.php similarity index 100% rename from src/web/php/record/history_record.php rename to src/web/server/record/history_record.php