Fix: getHighestRecord -> getHighestRecordForWriting
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// get parameters from client
|
||||
$command = $_POST["command"];
|
||||
|
||||
|
||||
include "./../lib/json_builder.php";
|
||||
include "./../lib/connect_db.php";
|
||||
|
||||
$jsonBuilder = new JsonBuilder();
|
||||
$dbConnector = new DBConnector();
|
||||
|
||||
$isConnected = $dbConnector->connectDB();
|
||||
if (!$isConnected) {
|
||||
$jsonBuilder->setErrorMessage("DB connection : failed");
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
const MAESTRO_ID = 3; // 삼화초
|
||||
const PLAYER_ID = 35; // 박지상
|
||||
|
||||
const WRITING_ID = 1;
|
||||
const WRITING_RECORD = 123.456;
|
||||
|
||||
|
||||
if ($command === "addTypingExamHighestRecord") {
|
||||
include "./db_method_container.php";
|
||||
include "./typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
$typingExam->addHighestRecord(MAESTRO_ID, PLAYER_ID, WRITING_ID, WRITING_RECORD);
|
||||
// $typingExamHighestRecordData = $typingExam->getHighestRecordForWriting(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);
|
||||
// $jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData);
|
||||
$typingExam->updateHighestRecord($typingExamHighestRecordData["typingExamHighestRecordID"], WRITING_RECORD + 10);
|
||||
// $typingExamHighestRecordData = $typingExam->getHighestRecordForWriting(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);
|
||||
$jsonBuilder->setData("typingExamHighestRecordData", $typingExamHighestRecordData);
|
||||
}
|
||||
|
||||
|
||||
$jsonBuilder->sendResultSuccess();
|
||||
|
||||
?>
|
||||
@@ -80,7 +80,7 @@ class TypingExamCollection extends DBMethodContainer
|
||||
SET HighestRecord = ?, RecordDateTime = NOW()
|
||||
WHERE TypingExamHighestRecordID = ?";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("id", $typingExamHighestRecordID, $record);
|
||||
$stmt->bind_param("di", $record, $typingExamHighestRecordID);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
@@ -105,21 +105,42 @@ class TypingExamCollection extends DBMethodContainer
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getHighestRecord($maestroID, $playerID)
|
||||
public function getHighestRecordForWriting($maestroID, $playerID, $writingID)
|
||||
{
|
||||
$query = "
|
||||
SELECT WritingID, HighestRecord
|
||||
SELECT TypingExamHighestRecordID, WritingID, HighestRecord
|
||||
FROM typing_exam_highest_record
|
||||
WHERE MaestroID = ? AND PlayerID = ? AND WritingID = ?";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("iii", $maestroID, $playerID, $writingID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($typingExamHighestRecordID, $writingID, $highestRecord);
|
||||
|
||||
$stmt->fetch();
|
||||
$recordData = array();
|
||||
$recordData["typingExamHighestRecordID"] = $typingExamHighestRecordID;
|
||||
$recordData["highestRecord"] = $highestRecord;
|
||||
$stmt->close();
|
||||
|
||||
return $recordData;
|
||||
}
|
||||
|
||||
public function getHighestRecordArrayForAllWriting($maestroID, $playerID)
|
||||
{
|
||||
$query = "
|
||||
SELECT TypingExamHighestRecordID, WritingID, HighestRecord
|
||||
FROM typing_exam_highest_record
|
||||
WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->bind_param("iii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($writingID, $highestRecord);
|
||||
$stmt->bind_result($typingExamHighestRecordID, $writingID, $highestRecord);
|
||||
|
||||
$resultArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$rowArray = array();
|
||||
$rowArray["writingID"] = $writingID;
|
||||
$rowArray["typingExamHighestRecordID"] = $typingExamHighestRecordID;
|
||||
// $rowArray["writingID"] = $writingID;
|
||||
$rowArray["highestRecord"] = $highestRecord;
|
||||
array_push($resultArray, $rowArray);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestroID"];
|
||||
$playerID = $_POST["playerID"];
|
||||
$writingID = $_POST["writingID"];
|
||||
|
||||
include "./../lib/json_builder.php";
|
||||
include "./../lib/connect_db.php";
|
||||
@@ -23,10 +24,10 @@ include "./../db/typing_exam_collection.php";
|
||||
|
||||
$typingExam = new TypingExamCollection($dbConnector->getMysqli());
|
||||
|
||||
$highestRecordArray = $typingExam->getHighestRecord();
|
||||
$jsonBuilder->setData("highestRecordArray", $highestRecordArray);
|
||||
$highestRecordData = $typingExam->getHighestRecordForWriting($maestroID, $playerID, $writingID);
|
||||
$jsonBuilder->setData("highestRecordData", $highestRecordData);
|
||||
|
||||
if ($highestRecordArray === null) {
|
||||
if ($highestRecordData === null) {
|
||||
$jsonBuilder->sendResultFail();
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -45,16 +45,30 @@ if ($thisHourRecordData === null) {
|
||||
}
|
||||
}
|
||||
|
||||
$highestRecordData = $typingExam->getHighestRecord($maestroID, $playerID);
|
||||
$jsonBuilder->setData("highestRecordData", $highestRecordData);
|
||||
if (count($highestRecordData) === 0) {
|
||||
$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 {
|
||||
if ($record > $highestRecordData["record"]) {
|
||||
$typingExam->updateHighestRecord($highestRecordData["ID"], $record);
|
||||
$jsonBuilder->setData("highestRecord", "updated");
|
||||
}
|
||||
// $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();
|
||||
|
||||
Reference in New Issue
Block a user