parent
df1de5ff32
commit
c9f496e2ed
@ -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
|
||||
|
||||
|
||||
|
||||
}
|
@ -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…
Reference in new issue