Fix: add and update TypingExamRecord, TypingExamHighestRecord
This commit is contained in:
@@ -29,21 +29,21 @@ if ($command === "deleteWritingRecordAll") {
|
|||||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||||
$typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID);
|
$typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID);
|
||||||
$typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID);
|
$typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID);
|
||||||
$jsonBuilder->setData("deleteWritingRecordAll", "succeeded");
|
// $jsonBuilder->setData("deleteWritingRecordAll", "succeeded");
|
||||||
} elseif ($command === "deleteTypingExamRecordAll") {
|
} elseif ($command === "deleteTypingExamRecordAll") {
|
||||||
include "./db_method_container.php";
|
include "./db_method_container.php";
|
||||||
include "./typing_exam_collection.php";
|
include "./typing_exam_collection.php";
|
||||||
|
|
||||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||||
$typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID);
|
$typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID);
|
||||||
$jsonBuilder->setData("deleteTypingExamRecordAll", "succeeded");
|
// $jsonBuilder->setData("deleteTypingExamRecordAll", "succeeded");
|
||||||
} elseif ($command === "deleteTypingExamHighestRecordAll") {
|
} elseif ($command === "deleteTypingExamHighestRecordAll") {
|
||||||
include "./db_method_container.php";
|
include "./db_method_container.php";
|
||||||
include "./typing_exam_collection.php";
|
include "./typing_exam_collection.php";
|
||||||
|
|
||||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||||
$typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID);
|
$typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID);
|
||||||
$jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded");
|
// $jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,18 @@ class TypingExamCollection extends DBMethodContainer
|
|||||||
$stmt->close();
|
$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)
|
public function deleteRecord($typingExamRecordID)
|
||||||
{
|
{
|
||||||
$query = "
|
$query = "
|
||||||
@@ -73,18 +85,6 @@ class TypingExamCollection extends DBMethodContainer
|
|||||||
$stmt->close();
|
$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)
|
public function getThisHourRecord($maestroID, $playerID)
|
||||||
{
|
{
|
||||||
$query = "
|
$query = "
|
||||||
@@ -149,6 +149,18 @@ class TypingExamCollection extends DBMethodContainer
|
|||||||
return $resultArray;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -27,50 +27,60 @@ include "./../db/typing_exam_collection.php";
|
|||||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||||
|
|
||||||
if (isset($isPrevHourFlag)) {
|
if (isset($isPrevHourFlag)) {
|
||||||
$typingExam->addPrevHourRecord($maestroID, $playerID, $writingID, $record);
|
addPrevHourRecord($maestroID, $playerID, $writingID, $record);
|
||||||
$jsonBuilder->setData("prevHourRecord", "added");
|
updateHighestRecord($maestroID, $playerID, $writingID, $record);
|
||||||
$jsonBuilder->sendResultSuccess();
|
$jsonBuilder->sendResultSuccess();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$thisHourRecordData = $typingExam->getThisHourRecord($maestroID, $playerID);
|
addHighestRecord($maestroID, $playerID, $writingID, $record);
|
||||||
if ($thisHourRecordData === null) {
|
updateHighestRecord($maestroID, $playerID, $writingID, $record);
|
||||||
$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");
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
$jsonBuilder->sendResultSuccess();
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
+99
-55
@@ -4,14 +4,13 @@
|
|||||||
QUnit.test( "TypingExamHighestRecord", function( assert ) {
|
QUnit.test( "TypingExamHighestRecord", function( assert ) {
|
||||||
var MAESTRO_ID = 3; // 삼화초
|
var MAESTRO_ID = 3; // 삼화초
|
||||||
var PLAYER_ID = 35; // 박지상
|
var PLAYER_ID = 35; // 박지상
|
||||||
|
var WRITING_ID = 1;
|
||||||
|
var RECORD = 123.456;
|
||||||
|
|
||||||
var dbService = new DBService();
|
var dbService = new DBService();
|
||||||
dbService.setMaestroID(MAESTRO_ID);
|
dbService.setMaestroID(MAESTRO_ID);
|
||||||
dbService.setPlayerID(PLAYER_ID);
|
dbService.setPlayerID(PLAYER_ID);
|
||||||
|
|
||||||
var WRITING_ID = 1;
|
|
||||||
var RECORD = 123.456;
|
|
||||||
|
|
||||||
dbService.tddSetup(
|
dbService.tddSetup(
|
||||||
"deleteTypingExamHighestRecordAll",
|
"deleteTypingExamHighestRecordAll",
|
||||||
(function(jsonData) { // onSucceeded
|
(function(jsonData) { // onSucceeded
|
||||||
@@ -80,77 +79,121 @@ QUnit.test( "TypingExamHighestRecord", function( assert ) {
|
|||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
// typing exam DB
|
// typing exam DB
|
||||||
|
|
||||||
QUnit.test( "TypingExam", function( assert ) {
|
QUnit.test( "TypingExamDB", function( assert ) {
|
||||||
var dbService = new DBService();
|
var MAESTRO_ID = 3; // 삼화초
|
||||||
dbService.setMaestroID(3); // 삼화초
|
var PLAYER_ID = 35; // 박지상
|
||||||
dbService.setPlayerID(35); // 박지상
|
var WRITING_ID = 1;
|
||||||
|
var RECORD = 117.89;
|
||||||
|
|
||||||
var writingIDForTest = 1;
|
var dbService = new DBService();
|
||||||
var recordForTest = 117.89;
|
dbService.setMaestroID(MAESTRO_ID);
|
||||||
|
dbService.setPlayerID(PLAYER_ID);
|
||||||
|
|
||||||
dbService.tddSetup(
|
dbService.tddSetup(
|
||||||
"deleteTypingExamRecordAll",
|
"deleteWritingRecordAll",
|
||||||
(function(jsonData) { // onSucceeded
|
(function(jsonData) { // onSucceeded
|
||||||
// console.log(jsonData);
|
// console.log(jsonData);
|
||||||
|
addPrevHourTypingExamRecord();
|
||||||
}).bind(this),
|
}).bind(this),
|
||||||
(function(jsonData) { // onFailed
|
(function(jsonData) { // onFailed
|
||||||
// console.log(jsonData);
|
// console.log(jsonData);
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
// dbService.tddSetup(
|
function addPrevHourTypingExamRecord()
|
||||||
// "deleteTypingExamHighestRecordAll",
|
{
|
||||||
// (function(jsonData) { // onSucceeded
|
dbService.addPrevHourTypingExamRecord(
|
||||||
// // console.log(jsonData);
|
WRITING_ID, //writingRecord
|
||||||
// }).bind(this),
|
RECORD + 10, // record
|
||||||
// (function(jsonData) { // onFailed
|
(function(jsonData) { // onSucceeded
|
||||||
// // console.log(jsonData);
|
// console.log(jsonData);
|
||||||
// }).bind(this)
|
updateTypingExamRecord();
|
||||||
// );
|
}).bind(this),
|
||||||
|
(function(jsonData) { // onFailed
|
||||||
|
// console.log(jsonData);
|
||||||
|
}).bind(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
dbService.addPrevHourTypingExamRecord(
|
// add this hour record - 10
|
||||||
writingIDForTest, //writingRecord
|
function updateTypingExamRecord()
|
||||||
recordForTest + 10, // record
|
{
|
||||||
(function(jsonData) { // onSucceeded
|
dbService.updateTypingExamRecord(
|
||||||
// console.log(jsonData);
|
WRITING_ID, //writingRecord
|
||||||
}).bind(this),
|
RECORD - 10, // record
|
||||||
(function(jsonData) { // onFailed
|
(function(jsonData) { // onSucceeded
|
||||||
// console.log(jsonData);
|
console.log(jsonData);
|
||||||
}).bind(this)
|
updateTypingExamRecord2();
|
||||||
);
|
}).bind(this),
|
||||||
|
(function(jsonData) { // onFailed
|
||||||
|
// console.log(jsonData);
|
||||||
|
}).bind(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
dbService.updateTypingExamRecord(
|
// update this hour record
|
||||||
writingIDForTest, //writingRecord
|
function updateTypingExamRecord2()
|
||||||
recordForTest - 10, // record
|
{
|
||||||
(function(jsonData) { // onSucceeded
|
dbService.updateTypingExamRecord(
|
||||||
// console.log(jsonData);
|
WRITING_ID, //writingRecord
|
||||||
}).bind(this),
|
RECORD, // record
|
||||||
(function(jsonData) { // onFailed
|
(function(jsonData) { // onSucceeded
|
||||||
// console.log(jsonData);
|
console.log(jsonData);
|
||||||
}).bind(this)
|
getTypingExamHighestRecord();
|
||||||
);
|
}).bind(this),
|
||||||
|
(function(jsonData) { // onFailed
|
||||||
dbService.updateTypingExamRecord(
|
console.log(jsonData);
|
||||||
writingIDForTest, //writingRecord
|
}).bind(this)
|
||||||
recordForTest, // record
|
);
|
||||||
(function(jsonData) { // onSucceeded
|
}
|
||||||
console.log(jsonData);
|
|
||||||
}).bind(this),
|
|
||||||
(function(jsonData) { // onFailed
|
|
||||||
console.log(jsonData);
|
|
||||||
}).bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
var done = assert.async();
|
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(
|
dbService.getTypingExamHighestRecord(
|
||||||
writingIDForTest,
|
WRITING_ID,
|
||||||
(function(jsonData) { // onSucceeded
|
(function(jsonData) { // onSucceeded
|
||||||
console.log(jsonData);
|
console.log(jsonData);
|
||||||
|
|
||||||
var highestRecord = jsonData["highestRecordData"];
|
var highestRecord = jsonData["highestRecordData"];
|
||||||
assert.equal(highestRecord["writingID"], writingIDForTest, "highest record");
|
assert.equal(highestRecord["highestRecord"], RECORD + 20, "highest record");
|
||||||
assert.equal(highestRecord["highestRecord"], recordForTest, "highest record");
|
|
||||||
done();
|
done();
|
||||||
}).bind(this),
|
}).bind(this),
|
||||||
(function(jsonData) { // onFailed
|
(function(jsonData) { // onFailed
|
||||||
@@ -158,7 +201,8 @@ QUnit.test( "TypingExam", function( assert ) {
|
|||||||
done();
|
done();
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user