Fix: add and update TypingExamRecord, TypingExamHighestRecord

This commit is contained in:
2019-07-16 09:03:43 +09:00
parent 3cb72799d4
commit 90f4219298
4 changed files with 175 additions and 109 deletions
+3 -3
View File
@@ -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");
}
+24 -12
View File
@@ -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();
}
}
?>
+49 -39
View File
@@ -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);
}
}
}
?>