From 1be8d4ee34ce0b8792dc13dc85003222755ed04b Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Wed, 23 Oct 2024 15:13:39 +0200 Subject: [PATCH] Supprimer 'gateway/questionGateway.php' --- gateway/questionGateway.php | 152 ------------------------------------ 1 file changed, 152 deletions(-) delete mode 100644 gateway/questionGateway.php diff --git a/gateway/questionGateway.php b/gateway/questionGateway.php deleted file mode 100644 index 77d964e..0000000 --- a/gateway/questionGateway.php +++ /dev/null @@ -1,152 +0,0 @@ - co = $co; - } - - /** - * Inserts a new question into the database - * - * @param QuestionEntity $q The `Question` object to insert - * @return bool True if the question was successfully inserted, false otherwise - */ - public function create(QuestionEntity $q) : bool - { - $query = " - INSERT INTO Question - VALUES(:id_q, :question, :answerA, :answerB, :answerC, :answerD, :cAnswer) - "; - $stmt = $this -> co -> prepare($query); - - return $stmt -> execute([ - ':id_q' => $q -> getIdquestion(), - ':question' => $q -> getQuestion(), - ':answerA' => $q -> getAnswerA(), - ':answerB' => $q -> getAnswerB(), - ':answerC' => $q -> getAnswerC(), - ':answerD' => $q -> getAnswerD(), - ':cAnswer' => $q -> getCAnswer() - ]); - } - - /** - * Retrieves a question from the database by its ID - * - * @param int $id The ID of the question to retrieve - * @return QuestionEntity|null The `Question` object if found, null otherwise - */ - public function findById(int $id) : ?QuestionEntity - { - $query = "SELECT * FROM Question WHERE id_question = :id_q"; - $stmt = $this -> co -> prepare($query); - $stmt -> execute([':id' => $id]); - $res = $stmt -> fetch(PDO::FETCH_ASSOC); - - if ($res) - return new QuestionEntity( - $res['id_q'], - $res['question'], - $res['answerA'], - $res['answerB'], - $res['answerC'], - $res['answerD'], - $res['cAnswer'], - ); - return null; - } - - /** - * Updates the text of and an existing question in the database - * - * @param QuestionEntity $q The `Question` object with updated information - * @return bool True if the text of the question was successfully updated, false otherwise - */ - public function updateText(QuestionEntity $q) : bool - { - $query = " - UPDATE Question - SET question = :question - WHERE id_question = :id_q - "; - $stmt = $this -> co -> prepare($query); - - return $stmt -> execute([':question' => $q -> getQuestion()]); - } - - /** - * Updates the answers of an existing question in the database - * - * @param QuestionEntity $q The `Question` object with updated information - * @return bool True if the answers of the question was successfully updated, false otherwise - */ - public function updateAnswers(QuestionEntity $q) : bool - { - $query = " - UPDATE Question - SET answerA = :answerA, answerB = :answerB, - answerC = :answerC, answerD = :answerD, cAnswer = :cAnswer - WHERE id_question = :id_q - "; - $stmt = $this -> co -> prepare($query); - - return $stmt -> execute([ - ':id_q' => $q -> getIdQuestion(), - ':answerA' => $q -> getAnswerA(), - ':answerB' => $q -> getAnswerB(), - ':answerC' => $q -> getAnswerC(), - ':answerD' => $q -> getAnswerD(), - ':cAnswer' => $q -> getCAnswer(), - ]); - } - - /** - * Deletes a question from the database by its ID - * - * @param int $id The ID of the question - * @return bool - */ - public function delete(int $id) : bool - { - $query = "DELETE FROM Question WHERE id_question = :id_q"; - $stmt = $this -> co -> prepare($query); - - return $stmt -> execute([':id_q' => $id]); - } - - /** - * Retrieves all quizzes from the database - * - * @return QuestionEntity[] An array of `Question` objects - */ - public function findAll() : array - { - $query = "SELECT * FROM Question"; - $stmt = $this -> co -> prepare($query); - $stmt->execute(); - $res = $stmt -> fetchAll(PDO::FETCH_ASSOC); - - $questions = []; - - foreach ($res as $q) - $questions[] = new QuestionEntity( - $q['id_question'], - $q['question'], - $q['answerA'], - $q['answerB'], - $q['answerC'], - $q['answerD'], - $q['cAnswer'] - ); - - return $questions; - } - -} \ No newline at end of file