You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
<?php
|
|
|
|
namespace Model;
|
|
use Gateway\QuestionGateway;
|
|
use Entity\QuestionEntity;
|
|
|
|
class QuestionModel
|
|
{
|
|
private QuestionGateway $gateway;
|
|
|
|
public function __construct(QuestionGateway $gw)
|
|
{
|
|
$this -> gateway = $gw;
|
|
}
|
|
|
|
public function createQuestion(int $id_question, string $question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer): bool
|
|
{
|
|
return $this -> gateway -> create($id_question, $question, $answerA, $answerB, $answerC, $answerD, $cAnswer);
|
|
|
|
}
|
|
|
|
public function getQuestion(int $id_question) : ?QuestionEntity
|
|
{
|
|
$q = $this -> gateway -> findById($id_question);
|
|
if ($q)
|
|
return new QuestionEntity(
|
|
$q['id_question'],
|
|
$q['question'],
|
|
$q['answerA'],
|
|
$q['answerB'],
|
|
$q['answerC'],
|
|
$q['answerD'],
|
|
$q['cAnswer']
|
|
);
|
|
return null;
|
|
}
|
|
|
|
public function updateTextQuestion(int $id_question, string $question) : bool
|
|
{
|
|
return $this -> gateway -> updateText($id_question, $question);
|
|
}
|
|
|
|
public function updateAnswersQuestion(int $id_question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer): bool
|
|
{
|
|
return $this -> gateway -> updateAnswers($id_question, $answerA, $answerB, $answerC, $answerD, $cAnswer);
|
|
}
|
|
|
|
public function deleteQuestion(int $id_question) : bool
|
|
{
|
|
return $this -> gateway -> delete($id_question);
|
|
}
|
|
|
|
public function getAllQuestions() : array
|
|
{
|
|
$q = $this -> gateway -> findAll();
|
|
|
|
$questions = [];
|
|
|
|
foreach ($q as $question) {
|
|
$questions[] = new QuestionEntity(
|
|
$question['id_question'],
|
|
$question['question'],
|
|
$question['answerA'],
|
|
$question['answerB'],
|
|
$question['answerC'],
|
|
$question['answerD'],
|
|
$question['cAnswer']
|
|
);
|
|
}
|
|
return $questions;
|
|
}
|
|
|
|
public function getRdmQuestion() : ?QuestionEntity
|
|
{
|
|
$q = $this -> gateway -> findRdmQuestion();
|
|
if ($q)
|
|
return new QuestionEntity(
|
|
$q['id_question'],
|
|
$q['question'],
|
|
$q['answerA'],
|
|
$q['answerB'],
|
|
$q['answerC'],
|
|
$q['answerD'],
|
|
$q['cAnswer']
|
|
);
|
|
return null;
|
|
}
|
|
} |