Add QuizQuestion Gateway & Model

pull/17/head
tomivt 6 months ago
parent df1de5ff32
commit c9f496e2ed

@ -2,7 +2,7 @@
namespace Entity;
class Quiz_questionEntity
class QuizQuestionEntity
{
private int $id_question;
private int $id_quiz;

@ -1,8 +1,6 @@
<?php
namespace Gateway;
use Entity\FavoriteEntity;
use Gateway\Connection;
use PDO;
class FavoriteGateway

@ -1,7 +1,6 @@
<?php
namespace Gateway;
use Gateway\Connection;
use PDO;
class ImageGateway
@ -22,8 +21,8 @@ class ImageGateway
return $this -> 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),
]);
}

@ -0,0 +1,73 @@
<?php
namespace Gateway;
use PDO;
class QuizQuestionGateway
{
private Connection $co;
public function __construct(Connection $co)
{
$this -> 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
}

@ -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);
}
}

@ -0,0 +1,56 @@
<?php
namespace Model;
use Entity\QuizQuestionEntity;
use Gateway\QuizQuestionGateway;
class QuizQuestionModel
{
private QuizQuestionGateway $gw;
public function __construct(QuizQuestionGateway $gw)
{
$this -> 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);
}
}
Loading…
Cancel
Save