From c9f496e2ed1a6b01450119ac48693f096c7f822f Mon Sep 17 00:00:00 2001 From: tomivt Date: Wed, 30 Oct 2024 23:43:16 +0100 Subject: [PATCH] Add QuizQuestion Gateway & Model --- ...stionEntity.php => QuizQuestionEntity.php} | 2 +- src/Gateway/FavoriteGateway.php | 2 - src/Gateway/ImageGateway.php | 5 +- src/Gateway/QuizQuestionGateway.php | 73 +++++++++++++++++++ src/Model/ImageModel.php | 4 +- src/Model/QuizQuestionModel.php | 56 ++++++++++++++ 6 files changed, 134 insertions(+), 8 deletions(-) rename src/Entity/{quiz_questionEntity.php => QuizQuestionEntity.php} (97%) create mode 100644 src/Gateway/QuizQuestionGateway.php create mode 100644 src/Model/QuizQuestionModel.php diff --git a/src/Entity/quiz_questionEntity.php b/src/Entity/QuizQuestionEntity.php similarity index 97% rename from src/Entity/quiz_questionEntity.php rename to src/Entity/QuizQuestionEntity.php index fc1634c..96dcf56 100644 --- a/src/Entity/quiz_questionEntity.php +++ b/src/Entity/QuizQuestionEntity.php @@ -2,7 +2,7 @@ namespace Entity; -class Quiz_questionEntity +class QuizQuestionEntity { private int $id_question; private int $id_quiz; diff --git a/src/Gateway/FavoriteGateway.php b/src/Gateway/FavoriteGateway.php index 53f394e..90f3eb1 100644 --- a/src/Gateway/FavoriteGateway.php +++ b/src/Gateway/FavoriteGateway.php @@ -1,8 +1,6 @@ co -> executeQuery($query, [ 'id_img' => array($idImg, PDO::PARAM_INT), - 'img_path' => array($idImg, PDO::PARAM_STR), - 'is_img_profile' => array($idImg, PDO::PARAM_BOOL), + 'img_path' => array($imgPath, PDO::PARAM_STR), + 'is_img_profile' => array($isImgProfile, PDO::PARAM_BOOL), ]); } diff --git a/src/Gateway/QuizQuestionGateway.php b/src/Gateway/QuizQuestionGateway.php new file mode 100644 index 0000000..2c71b86 --- /dev/null +++ b/src/Gateway/QuizQuestionGateway.php @@ -0,0 +1,73 @@ + co = $co; + } + + public function createQuizQuestionGateway(int $idQuiz, int $idQuestion): bool + { + $query = " + INSERT INTO QuizQuestions + VALUES (:id_quiz, :id_question) + "; + + return $this -> co -> executeQuery($query, [ + 'id_quiz' => array($idQuiz, PDO::PARAM_INT), + 'id_question' => array($idQuestion, PDO::PARAM_INT) + ]); + } + + public function findQuizQuestionById(int $idQuiz, int $idQuestion) : array + { + $query = " + SELECT * FROM QuizQuestions + WHERE quiz_qq = :id_quiz AND question_qq = :id_question + "; + + $this -> co -> executeQuery($query, [ + 'id_quiz' => array($idQuiz, PDO::PARAM_INT), + 'id_question' => array($idQuestion, PDO::PARAM_INT) + ]); + + return $this -> co -> getResults(); + } + + public function findQuestionsFromQuiz(int $idQuiz) : array + { + $query = " + SELECT * FROM QuizQuestions + WHERE quiz_qq = :id_quiz + "; + + $this -> co -> executeQuery($query, ['id_quiz' => array($idQuiz, PDO::PARAM_INT)]); + + return $this -> co -> getResults(); + } + + public function deleteQuizQuestionGateway(int $idQuiz, int $idQuestion) : bool + { + $query = " + DELETE FROM QuizQuestions + WHERE quiz_qq = :id_quiz AND question_qq = :id_question + "; + + return $this -> co -> executeQuery($query, [ + 'id_quiz' => array($idQuiz, PDO::PARAM_INT), + 'id_question' => array($idQuestion, PDO::PARAM_INT) + ]); + } + + # To do : + # Method that deletes all questions related to a quiz + + + +} \ No newline at end of file diff --git a/src/Model/ImageModel.php b/src/Model/ImageModel.php index 5a3dafa..8290b4f 100644 --- a/src/Model/ImageModel.php +++ b/src/Model/ImageModel.php @@ -73,8 +73,8 @@ class ImageModel return $this -> gw -> deleteImgGateway($idImg); } - public function updateImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool + public function updateImgModel(int $idImg, string $imgPath) : bool { - return $this -> gw -> updateImgGateway($idImg, $imgPath, $isImgProfile); + return $this -> gw -> updateImgGateway($idImg, $imgPath); } } \ No newline at end of file diff --git a/src/Model/QuizQuestionModel.php b/src/Model/QuizQuestionModel.php new file mode 100644 index 0000000..e4ff7cf --- /dev/null +++ b/src/Model/QuizQuestionModel.php @@ -0,0 +1,56 @@ + gw = $gw; + } + + public function createQuizQuestionModel(int $idQuiz, int $idQuestion) : bool + { + return $this -> gw -> createQuizQuestionGateway($idQuiz, $idQuestion); + } + + public function getQuizQuestionById(int $idQuiz, int $idQuestion) : ?QuizQuestionEntity + { + $res = $this -> gw -> findQuizQuestionById($idQuiz, $idQuestion); + + if ($res) + { + return new QuizQuestionEntity ( + $res[0]['quiz_qq'], + $res[0]['question_qq'] + ); + } + return null; + } + + public function getQuestionsFromQuiz(int $idQuiz) : array + { + $res = $this -> gw -> findQuestionsFromQuiz($idQuiz); + + $questions = []; + + foreach ($res as $question) + { + $questions[] = new QuizQuestionEntity ( + $question['quiz_qq'], + $question['question_qq'] + ); + } + return $questions; + } + + public function deleteQuizQuestionModel(int $idQuiz, int $idQuestion) : bool + { + return $this -> gw -> deleteQuizQuestionGateway($idQuiz, $idQuestion); + } +} \ No newline at end of file