Fix: update result record to DB
This commit is contained in:
@@ -32,24 +32,24 @@ if ($command === "addTypingExamHighestRecord") {
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
$typingExam->addHighestRecord(MAESTRO_ID, PLAYER_ID, WRITING_ID, WRITING_RECORD);
|
||||
// $typingExamHighestRecordData = $typingExam->getHighestRecordForWriting(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
// $typingExamHighestRecordData = $typingExam->getHighestRecord(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
// $jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData);
|
||||
} elseif ($command === "updateTypingExamHighestRecord") {
|
||||
include "./db_method_container.php";
|
||||
include "./typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
$typingExamHighestRecordData = $typingExam->getHighestRecordForWriting(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
$typingExamHighestRecordData = $typingExam->getHighestRecord(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
// $jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData);
|
||||
$typingExam->updateHighestRecord($typingExamHighestRecordData["typingExamHighestRecordID"], WRITING_RECORD + 10);
|
||||
// $typingExamHighestRecordData = $typingExam->getHighestRecordForWriting(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
// $typingExamHighestRecordData = $typingExam->getHighestRecord(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
// $jsonBuilder->setData("updateTypingExamHighestRecord", $typingExamHighestRecordData);
|
||||
} elseif ($command === "getTypingExamHigestRecord") {
|
||||
include "./db_method_container.php";
|
||||
include "./typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
$typingExamHighestRecordData = $typingExam->getHighestRecordForWriting(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
$typingExamHighestRecordData = $typingExam->getHighestRecord(MAESTRO_ID, PLAYER_ID, WRITING_ID);
|
||||
$jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,14 +85,14 @@ class TypingExamCollection extends DBMethodContainer
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
public function getThisHourRecord($maestroID, $playerID)
|
||||
public function getThisHourRecord($maestroID, $playerID, $writingID)
|
||||
{
|
||||
$query = "
|
||||
SELECT TypingExamRecordID, Record
|
||||
FROM typing_exam_record
|
||||
WHERE MaestroID = ? AND PlayerID = ? AND DATE(RecordDateTime) = DATE(NOW()) AND HOUR(RecordDateTime) = HOUR(NOW())";
|
||||
WHERE MaestroID = ? AND PlayerID = ? AND WritingID = ? AND DATE(RecordDateTime) = DATE(NOW()) AND HOUR(RecordDateTime) = HOUR(NOW())";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->bind_param("iii", $maestroID, $playerID, $writingID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($typingExamRecordID, $record);
|
||||
|
||||
@@ -105,7 +105,7 @@ class TypingExamCollection extends DBMethodContainer
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getHighestRecordForWriting($maestroID, $playerID, $writingID)
|
||||
public function getHighestRecord($maestroID, $playerID, $writingID)
|
||||
{
|
||||
$query = "
|
||||
SELECT TypingExamHighestRecordID, WritingID, HighestRecord
|
||||
|
||||
@@ -24,7 +24,7 @@ include "./../db/typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
|
||||
$highestRecordData = $typingExam->getHighestRecordForWriting($maestroID, $playerID, $writingID);
|
||||
$highestRecordData = $typingExam->getHighestRecord($maestroID, $playerID, $writingID);
|
||||
$jsonBuilder->setData("highestRecordData", $highestRecordData);
|
||||
|
||||
if ($highestRecordData === null) {
|
||||
|
||||
@@ -33,7 +33,7 @@ if (isset($isPrevHourFlag)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
addHighestRecord($maestroID, $playerID, $writingID, $record);
|
||||
updateRecord($maestroID, $playerID, $writingID, $record);
|
||||
updateHighestRecord($maestroID, $playerID, $writingID, $record);
|
||||
|
||||
$jsonBuilder->sendResultSuccess();
|
||||
@@ -49,19 +49,19 @@ function addPrevHourRecord($maestroID, $playerID, $writingID, $record)
|
||||
// $jsonBuilder->setData("prevHourRecord", "added");
|
||||
}
|
||||
|
||||
function addHighestRecord($maestroID, $playerID, $writingID, $record)
|
||||
function updateRecord($maestroID, $playerID, $writingID, $record)
|
||||
{
|
||||
global $typingExam, $jsonBuilder;
|
||||
|
||||
$thisHourRecordData = $typingExam->getThisHourRecord($maestroID, $playerID);
|
||||
$thisHourRecordData = $typingExam->getThisHourRecord($maestroID, $playerID, $writingID);
|
||||
// $jsonBuilder->setData("thisHourRecordData", $thisHourRecordData);
|
||||
if ($thisHourRecordData["record"] === null) {
|
||||
$typingExam->addRecord($maestroID, $playerID, $writingID, $record);
|
||||
// $jsonBuilder->setData("record", "added : ".$record);
|
||||
$jsonBuilder->setData("record", "added : ".$record);
|
||||
} else {
|
||||
if ($record > $thisHourRecordData["record"]) {
|
||||
$typingExam->updateRecord($thisHourRecordData["typingExamRecordID"], $record);
|
||||
// $jsonBuilder->setData("record", "updated : ".$record);
|
||||
$jsonBuilder->setData("record", "updated : ".$record);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ function updateHighestRecord($maestroID, $playerID, $writingID, $record)
|
||||
{
|
||||
global $typingExam, $jsonBuilder;
|
||||
|
||||
$highestRecordData = $typingExam->getHighestRecordForWriting($maestroID, $playerID, $writingID);
|
||||
$highestRecordData = $typingExam->getHighestRecord($maestroID, $playerID, $writingID);
|
||||
// $jsonBuilder->setData("highestRecordData", $highestRecordData);
|
||||
if ($highestRecordData["highestRecord"] === null) {
|
||||
$typingExam->addHighestRecord($maestroID, $playerID, $writingID, $record);
|
||||
|
||||
Reference in New Issue
Block a user