From 2755c58b719754944fe8e836da39e0b8eba3642d Mon Sep 17 00:00:00 2001 From: tomivt Date: Tue, 15 Oct 2024 12:14:58 +0200 Subject: [PATCH] Add questionModel.php --- src/questionModel.php | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/questionModel.php diff --git a/src/questionModel.php b/src/questionModel.php new file mode 100644 index 0000000..d0dc225 --- /dev/null +++ b/src/questionModel.php @@ -0,0 +1,65 @@ + gateway = $gateway; + } + + public function createQuestion(int $id_question, string $question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer) : bool + { + $q = new QuestionEntity($id_question, $question, $answerA, $answerB, $answerC, $answerD, $cAnswer); + return $this -> gateway -> create($q); + } + + public function getQuestion(int $id_question) : ?QuestionEntity + { + return $this -> gateway -> findById($id_question); + } + + public function updateTextQuestion(int $id_question, string $question) : bool + { + $q = $this -> gateway -> findById($id_question); + + if ($q) + { + $q -> setQuestion($question); + return $this -> gateway -> updateText($q); + } + + return false; + } + + public function updateAnswersQuestion(int $id_question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer) : bool + { + $q = $this -> gateway -> findById($id_question); + + if ($q) + { + $q -> setAnswerA($answerA); + $q -> setAnswerB($answerB); + $q -> setAnswerC($answerC); + $q -> setAnswerD($answerD); + $q -> setAnswerC($cAnswer); + return $this -> gateway -> updateAnswers($q); + } + + return false; + } + + public function deleteQuestion(int $id_question) : bool + { + return $this -> gateway -> delete($id_question); + } + + public function getAllQuestions() : array + { + return $this -> gateway -> findAll(); + } +} \ No newline at end of file