diff --git a/src/web/php/db/tdd_setup.php b/src/web/php/db/tdd_setup.php index 9d54931..a1302ea 100644 --- a/src/web/php/db/tdd_setup.php +++ b/src/web/php/db/tdd_setup.php @@ -29,21 +29,21 @@ if ($command === "deleteWritingRecordAll") { $typingExam = new TypingExamCollection($dbConnector->getMysqli()); $typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID); $typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID); - $jsonBuilder->setData("deleteWritingRecordAll", "succeeded"); + // $jsonBuilder->setData("deleteWritingRecordAll", "succeeded"); } elseif ($command === "deleteTypingExamRecordAll") { include "./db_method_container.php"; include "./typing_exam_collection.php"; $typingExam = new TypingExamCollection($dbConnector->getMysqli()); $typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID); - $jsonBuilder->setData("deleteTypingExamRecordAll", "succeeded"); + // $jsonBuilder->setData("deleteTypingExamRecordAll", "succeeded"); } elseif ($command === "deleteTypingExamHighestRecordAll") { include "./db_method_container.php"; include "./typing_exam_collection.php"; $typingExam = new TypingExamCollection($dbConnector->getMysqli()); $typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID); - $jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded"); + // $jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded"); } diff --git a/src/web/php/db/typing_exam_collection.php b/src/web/php/db/typing_exam_collection.php index cb66ff2..f19e61a 100644 --- a/src/web/php/db/typing_exam_collection.php +++ b/src/web/php/db/typing_exam_collection.php @@ -49,6 +49,18 @@ class TypingExamCollection extends DBMethodContainer $stmt->close(); } + public function updateRecord($typingExamRecordID, $record) + { + $query = " + UPDATE typing_exam_record + SET Record = ?, RecordDateTime = NOW() + WHERE TypingExamRecordID = ?"; + $stmt = $this->mysqli->prepare($query); + $stmt->bind_param("di", $record, $typingExamRecordID); + $stmt->execute(); + $stmt->close(); + } + public function deleteRecord($typingExamRecordID) { $query = " @@ -73,18 +85,6 @@ class TypingExamCollection extends DBMethodContainer $stmt->close(); } - public function updateHighestRecord($typingExamHighestRecordID, $record) - { - $query = " - UPDATE typing_exam_highest_record - SET HighestRecord = ?, RecordDateTime = NOW() - WHERE TypingExamHighestRecordID = ?"; - $stmt = $this->mysqli->prepare($query); - $stmt->bind_param("di", $record, $typingExamHighestRecordID); - $stmt->execute(); - $stmt->close(); - } - public function getThisHourRecord($maestroID, $playerID) { $query = " @@ -149,6 +149,18 @@ class TypingExamCollection extends DBMethodContainer return $resultArray; } + public function updateHighestRecord($typingExamHighestRecordID, $record) + { + $query = " + UPDATE typing_exam_highest_record + SET HighestRecord = ?, RecordDateTime = NOW() + WHERE TypingExamHighestRecordID = ?"; + $stmt = $this->mysqli->prepare($query); + $stmt->bind_param("di", $record, $typingExamHighestRecordID); + $stmt->execute(); + $stmt->close(); + } + } ?> \ No newline at end of file diff --git a/src/web/php/writing/update_result_record.php b/src/web/php/writing/update_result_record.php index 24ded11..bed4c70 100644 --- a/src/web/php/writing/update_result_record.php +++ b/src/web/php/writing/update_result_record.php @@ -27,50 +27,60 @@ include "./../db/typing_exam_collection.php"; $typingExam = new TypingExamCollection($dbConnector->getMysqli()); if (isset($isPrevHourFlag)) { - $typingExam->addPrevHourRecord($maestroID, $playerID, $writingID, $record); - $jsonBuilder->setData("prevHourRecord", "added"); + addPrevHourRecord($maestroID, $playerID, $writingID, $record); + updateHighestRecord($maestroID, $playerID, $writingID, $record); $jsonBuilder->sendResultSuccess(); exit; } -$thisHourRecordData = $typingExam->getThisHourRecord($maestroID, $playerID); -if ($thisHourRecordData === null) { - $typingExam->addRecord($maestroID, $playerID, $writingID, $record); - $jsonBuilder->setData("record", "added"); -} else { - if ($record > $thisHourRecordData["record"]) { - $typingExam->deleteRecord($thisHourRecordData["ID"]); - $typingExam->addRecord($maestroID, $playerID, $writingID, $record); - $jsonBuilder->setData("record", "updated"); - } -} - -$highestRecordArray = $typingExam->getHighestRecordForWriting($maestroID, $playerID, $writingID); -$jsonBuilder->setData("highestRecordArray", $highestRecordArray); -if (count($highestRecordArray) === 0) { - $typingExam->addHighestRecord($maestroID, $playerID, $writingID, $record); - $jsonBuilder->setData("highestRecord", "added"); -} else { - // $highestRecord = null; - // $count = count($highestRecordArray); - // for ($i = 0; $i < $count; $i++) { - // $data = $highestRecordArray[$i]; - // if ($data["writingID"] === $writingID) { - // $highestRecordData = $data; - // break; - // } - // } - // if ($highestRecord === null) { - // $typingExam->addHighestRecord($maestroID, $playerID, $writingID, $record); - // $jsonBuilder->setData("highestRecord", "added"); - // } else { - if ($record > $highestRecordArray["highestRecord"]) { - $typingExam->updateHighestRecord($highestRecordArray["typingExamHighestRecordID"], $record); - $jsonBuilder->setData("highestRecord", "updated"); - } - // } -} +addHighestRecord($maestroID, $playerID, $writingID, $record); +updateHighestRecord($maestroID, $playerID, $writingID, $record); $jsonBuilder->sendResultSuccess(); + + + +function addPrevHourRecord($maestroID, $playerID, $writingID, $record) +{ + global $typingExam, $jsonBuilder; + + $typingExam->addPrevHourRecord($maestroID, $playerID, $writingID, $record); + // $jsonBuilder->setData("prevHourRecord", "added"); +} + +function addHighestRecord($maestroID, $playerID, $writingID, $record) +{ + global $typingExam, $jsonBuilder; + + $thisHourRecordData = $typingExam->getThisHourRecord($maestroID, $playerID); + // $jsonBuilder->setData("thisHourRecordData", $thisHourRecordData); + if ($thisHourRecordData["record"] === null) { + $typingExam->addRecord($maestroID, $playerID, $writingID, $record); + // $jsonBuilder->setData("record", "added : ".$record); + } else { + if ($record > $thisHourRecordData["record"]) { + $typingExam->updateRecord($thisHourRecordData["typingExamRecordID"], $record); + // $jsonBuilder->setData("record", "updated : ".$record); + } + } +} + +function updateHighestRecord($maestroID, $playerID, $writingID, $record) +{ + global $typingExam, $jsonBuilder; + + $highestRecordData = $typingExam->getHighestRecordForWriting($maestroID, $playerID, $writingID); + // $jsonBuilder->setData("highestRecordData", $highestRecordData); + if ($highestRecordData["highestRecord"] === null) { + $typingExam->addHighestRecord($maestroID, $playerID, $writingID, $record); + // $jsonBuilder->setData("highestRecord", "added : ".$record); + } else { + if ($record > $highestRecordData["highestRecord"]) { + $typingExam->updateHighestRecord($highestRecordData["typingExamHighestRecordID"], $record); + // $jsonBuilder->setData("highestRecord", "updated : ".$record); + } + } +} + ?> \ No newline at end of file diff --git a/test/tdd.js b/test/tdd.js index 5cd1269..f898bec 100644 --- a/test/tdd.js +++ b/test/tdd.js @@ -4,14 +4,13 @@ QUnit.test( "TypingExamHighestRecord", function( assert ) { var MAESTRO_ID = 3; // 삼화초 var PLAYER_ID = 35; // 박지상 + var WRITING_ID = 1; + var RECORD = 123.456; var dbService = new DBService(); dbService.setMaestroID(MAESTRO_ID); dbService.setPlayerID(PLAYER_ID); - var WRITING_ID = 1; - var RECORD = 123.456; - dbService.tddSetup( "deleteTypingExamHighestRecordAll", (function(jsonData) { // onSucceeded @@ -80,77 +79,121 @@ QUnit.test( "TypingExamHighestRecord", function( assert ) { ////////////////////////////////////////////////// // typing exam DB -QUnit.test( "TypingExam", function( assert ) { - var dbService = new DBService(); - dbService.setMaestroID(3); // 삼화초 - dbService.setPlayerID(35); // 박지상 +QUnit.test( "TypingExamDB", function( assert ) { + var MAESTRO_ID = 3; // 삼화초 + var PLAYER_ID = 35; // 박지상 + var WRITING_ID = 1; + var RECORD = 117.89; - var writingIDForTest = 1; - var recordForTest = 117.89; + var dbService = new DBService(); + dbService.setMaestroID(MAESTRO_ID); + dbService.setPlayerID(PLAYER_ID); dbService.tddSetup( - "deleteTypingExamRecordAll", + "deleteWritingRecordAll", (function(jsonData) { // onSucceeded // console.log(jsonData); + addPrevHourTypingExamRecord(); }).bind(this), (function(jsonData) { // onFailed // console.log(jsonData); }).bind(this) ); - // dbService.tddSetup( - // "deleteTypingExamHighestRecordAll", - // (function(jsonData) { // onSucceeded - // // console.log(jsonData); - // }).bind(this), - // (function(jsonData) { // onFailed - // // console.log(jsonData); - // }).bind(this) - // ); + function addPrevHourTypingExamRecord() + { + dbService.addPrevHourTypingExamRecord( + WRITING_ID, //writingRecord + RECORD + 10, // record + (function(jsonData) { // onSucceeded + // console.log(jsonData); + updateTypingExamRecord(); + }).bind(this), + (function(jsonData) { // onFailed + // console.log(jsonData); + }).bind(this) + ); + } - dbService.addPrevHourTypingExamRecord( - writingIDForTest, //writingRecord - recordForTest + 10, // record - (function(jsonData) { // onSucceeded - // console.log(jsonData); - }).bind(this), - (function(jsonData) { // onFailed - // console.log(jsonData); - }).bind(this) - ); + // add this hour record - 10 + function updateTypingExamRecord() + { + dbService.updateTypingExamRecord( + WRITING_ID, //writingRecord + RECORD - 10, // record + (function(jsonData) { // onSucceeded + console.log(jsonData); + updateTypingExamRecord2(); + }).bind(this), + (function(jsonData) { // onFailed + // console.log(jsonData); + }).bind(this) + ); + } - dbService.updateTypingExamRecord( - writingIDForTest, //writingRecord - recordForTest - 10, // record - (function(jsonData) { // onSucceeded - // console.log(jsonData); - }).bind(this), - (function(jsonData) { // onFailed - // console.log(jsonData); - }).bind(this) - ); - - dbService.updateTypingExamRecord( - writingIDForTest, //writingRecord - recordForTest, // record - (function(jsonData) { // onSucceeded - console.log(jsonData); - }).bind(this), - (function(jsonData) { // onFailed - console.log(jsonData); - }).bind(this) - ); + // update this hour record + function updateTypingExamRecord2() + { + dbService.updateTypingExamRecord( + WRITING_ID, //writingRecord + RECORD, // record + (function(jsonData) { // onSucceeded + console.log(jsonData); + getTypingExamHighestRecord(); + }).bind(this), + (function(jsonData) { // onFailed + console.log(jsonData); + }).bind(this) + ); + } var done = assert.async(); - setTimeout(function() { + function getTypingExamHighestRecord() + { + setTimeout(function() { + dbService.getTypingExamHighestRecord( + WRITING_ID, + (function(jsonData) { // onSucceeded + console.log(jsonData); + + var highestRecord = jsonData["highestRecordData"]; + assert.equal(highestRecord["highestRecord"], RECORD + 10, "highest record"); + updateTypingExamRecord3(); + }).bind(this), + (function(jsonData) { // onFailed + // console.log(jsonData); + done(); + }).bind(this) + ); + }); + } + + // update this hour record + function updateTypingExamRecord3() + { + dbService.updateTypingExamRecord( + WRITING_ID, //writingRecord + RECORD + 20, // record + (function(jsonData) { // onSucceeded + console.log(jsonData); + getTypingExamHighestRecord2(); + }).bind(this), + (function(jsonData) { // onFailed + console.log(jsonData); + done(); + }).bind(this) + ); + } + + function getTypingExamHighestRecord2() + { dbService.getTypingExamHighestRecord( - writingIDForTest, + WRITING_ID, (function(jsonData) { // onSucceeded console.log(jsonData); var highestRecord = jsonData["highestRecordData"]; - assert.equal(highestRecord["writingID"], writingIDForTest, "highest record"); - assert.equal(highestRecord["highestRecord"], recordForTest, "highest record"); + assert.equal(highestRecord["highestRecord"], RECORD + 20, "highest record"); done(); }).bind(this), (function(jsonData) { // onFailed @@ -158,7 +201,8 @@ QUnit.test( "TypingExam", function( assert ) { done(); }).bind(this) ); - }); + } + });