Add: writing exam - save and update record (incompleted)
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
class TypingExamCollection extends DBMethodContainer
|
||||
{
|
||||
// begin - for TDD
|
||||
public function deleteTypingExamRecordAll($maestroID, $playerID) {
|
||||
$query = "
|
||||
DELETE
|
||||
FROM typing_exam_record
|
||||
WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
public function deleteTypingExamHighestRecordAll($maestroID, $playerID) {
|
||||
$query = "
|
||||
DELETE
|
||||
FROM typing_exam_highest_record
|
||||
WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
public function addPrevHourRecord($maestroID, $playerID, $writingID, $record)
|
||||
{
|
||||
$query = "
|
||||
INSERT INTO typing_exam_record (MaestroID, PlayerID, WritingID, Record, RecordDateTime)
|
||||
VALUES (?, ?, ?, ?, DATE_SUB(NOW(), INTERVAL 1 HOUR))";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("iiid", $maestroID, $playerID, $writingID, $record);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
// end - for TDD
|
||||
|
||||
public function addRecord($maestroID, $playerID, $writingID, $record)
|
||||
{
|
||||
$query = "
|
||||
INSERT INTO typing_exam_record (MaestroID, PlayerID, WritingID, Record, RecordDateTime)
|
||||
VALUES (?, ?, ?, ?, NOW())";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("iiid", $maestroID, $playerID, $writingID, $record);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
public function deleteRecord($typingExamRecordID)
|
||||
{
|
||||
$query = "
|
||||
DELETE
|
||||
FROM typing_exam_record
|
||||
WHERE TypingExamRecordID = ?
|
||||
";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param('i', $typingExamRecordID);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
public function addHighestRecord($maestroID, $playerID, $writingID, $record)
|
||||
{
|
||||
$query = "
|
||||
INSERT INTO typing_exam_highest_record (MaestroID, PlayerID, WritingID, HighestRecord, RecordDateTime)
|
||||
VALUES (?, ?, ?, ?, NOW())";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("iiid", $maestroID, $playerID, $writingID, $record);
|
||||
$stmt->execute();
|
||||
$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("id", $typingExamHighestRecordID, $record);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
public function getThisHourRecord($maestroID, $playerID)
|
||||
{
|
||||
$query = "
|
||||
SELECT TypingExamRecordID, Record
|
||||
FROM typing_exam_record
|
||||
WHERE MaestroID = ? AND PlayerID = ? AND DATE(RecordDateTime) = DATE(NOW()) AND HOUR(RecordDateTime) = HOUR(NOW())";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($typingExamRecordID, $record);
|
||||
|
||||
$stmt->fetch();
|
||||
$result = array();
|
||||
$result["typingExamRecordID"] = $typingExamRecordID;
|
||||
$result["record"] = $record;
|
||||
$stmt->close();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getHighestRecord($maestroID, $playerID)
|
||||
{
|
||||
$query = "
|
||||
SELECT WritingID, HighestRecord
|
||||
FROM typing_exam_highest_record
|
||||
WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$stmt = $this->mysqli->prepare($query);
|
||||
$stmt->bind_param("ii", $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($writingID, $highestRecord);
|
||||
|
||||
$resultArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$rowArray = array();
|
||||
$rowArray["writingID"] = $writingID;
|
||||
$rowArray["highestRecord"] = $highestRecord;
|
||||
array_push($resultArray, $rowArray);
|
||||
}
|
||||
$stmt->close();
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user