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.
55 lines
1.1 KiB
55 lines
1.1 KiB
<?php
|
|
|
|
namespace Model;
|
|
|
|
use Entity\quizEntity;
|
|
use Gateway\QuizGateway;
|
|
|
|
class QuizModel {
|
|
|
|
private QuizGateway $gateway;
|
|
|
|
public function __construct(QuizGateway $gw)
|
|
{
|
|
$this -> gateway = $gw;
|
|
}
|
|
|
|
public function createQuiz(int $id_quiz, int $nb_questions) : bool
|
|
{
|
|
return $this -> gateway -> create($id_quiz, $nb_questions);
|
|
}
|
|
|
|
public function getQuiz(int $id_quiz): ?quizEntity
|
|
{
|
|
$q = $this -> gateway -> findQuizById($id_quiz);
|
|
if ($q) {
|
|
return new quizEntity(
|
|
$q[0]['id_quiz'],
|
|
$q[0]['nb_quest']
|
|
);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function deleteQuiz(int $id_quiz) : bool
|
|
{
|
|
return $this -> gateway -> delete($id_quiz);
|
|
}
|
|
|
|
public function getAllQuiz() : array
|
|
{
|
|
$q = $this -> gateway -> findAll();
|
|
|
|
$quizzes = [];
|
|
|
|
foreach ($q as $quiz) {
|
|
$quizzes[] = new quizEntity(
|
|
$quiz['id_quiz'],
|
|
$quiz['nb_questions']
|
|
);
|
|
}
|
|
return $quizzes;
|
|
|
|
}
|
|
|
|
} |