fix AccueilQuiz

pull/30/head
Maxime ROCHER 5 months ago
parent 342a9f1de8
commit 37f0c11f4c

@ -15,8 +15,8 @@ if(!isset($_SESSION['theme'])){
require_once __DIR__ . '/config/config.php';
require __DIR__ . '/vendor/autoload.php';
//$co = new \Gateway\Connection('pgsql:host=localhost;dbname=wikifantasy3;', 'postgres', 'sucepute');
$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd');
$co = new \Gateway\Connection('pgsql:host=localhost;dbname=wikifantasy3;', 'postgres', 'sucepute');
//$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd');
//twig
$loader = new \Twig\Loader\FilesystemLoader('vue/templates');

@ -62,7 +62,7 @@ Class FrontControler{
$action = NULL;
if(!$match){
$dVueEreur = [404,"Page inconue"];
$dVueEreur = [404,"Page non troue"];
$this->vueErreur($dVueEreur);
}
else{
@ -72,7 +72,7 @@ Class FrontControler{
//Si existe, on lappelle
if(!$this->ifExisteAction($action)){
$dVueEreur = [404,"Action inconue"];
$dVueEreur = [404,"Action non troue"];
$this->vueErreur($dVueEreur);
}

@ -4,18 +4,26 @@ namespace Entity;
class QuizEntity
{
private int $id_quiz;
public int $id_quiz;
private int $nb_questions;
public int $nb_quest;
public string $imgPath;
public string $title;
/**
* @param int $id_quiz
* @param int $nb_questions
* @param int $nb_quest
* @param string $imgPath
* @param string $title
*/
public function __construct(int $id_quiz, int $nb_questions)
public function __construct(int $id_quiz, int $nb_quest, string $imgPath, string $title)
{
$this->id_quiz = $id_quiz;
$this->nb_questions = $nb_questions;
$this->nb_quest = $nb_quest;
$this->imgPath = $imgPath;
$this->title = $title;
}
/**
@ -39,14 +47,46 @@ class QuizEntity
*/
public function getNbQuestions(): int
{
return $this->nb_questions;
return $this->nb_quest;
}
/**
* @param int $nb_quest
*/
public function setNbQuestions(int $nb_quest): void
{
$this->nb_quest = $nb_quest;
}
/**
* @return string
*/
public function getIdImg(): string
{
return $this->imgPath;
}
/**
* @param string $imgPath
*/
public function setIdImg(string $imgPath): void
{
$this->imgPath = $imgPath;
}
/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* @param int $nb_questions
* @param string $title
*/
public function setNbQuestions(int $nb_questions): void
public function setTitle(string $title): void
{
$this->nb_questions = $nb_questions;
$this->title = $title;
}
}

@ -8,16 +8,18 @@ use PDO;
class QuizGateway extends Gateway
{
public function create(int $id_quiz, int $nb_questions) : bool
public function create(int $id_quiz, int $nb_questions, string $id_img, string $title) : bool
{
$query = "
INSERT INTO Quiz
VALUES (:id_q, :nb_q)
VALUES (:id_q, :nb_q, :id_img, :title)
";
return $this -> co -> executeQuery($query, [
':id_q' => array($id_quiz, PDO::PARAM_INT),
':nb_q' => array($nb_questions, PDO::PARAM_INT)
':nb_q' => array($nb_questions, PDO::PARAM_INT),
':id_img' => array($id_img, PDO::PARAM_STR),
':title' => array($title, PDO::PARAM_STR)
]);
}
@ -36,7 +38,7 @@ class QuizGateway extends Gateway
public function findAll() : array
{
$query = "SELECT id_quiz, title, imgPath FROM Quiz q JOIN Image i on q.img = i.id_img";
$query = "SELECT id_quiz, title, imgPath, nb_quest FROM Quiz q JOIN Image i on q.img = i.id_img";
$this -> co -> executeQuery($query);
return $this -> co -> getResults();
}

@ -8,9 +8,9 @@ use Gateway\Gateway;
class QuizModel extends Model{
public function createQuiz(int $id_quiz, int $nb_questions) : bool
public function createQuiz(int $id_quiz, int $nb_questions, String $id_img, string $title) : bool
{
return $this -> gateway -> create($id_quiz, $nb_questions);
return $this -> gateway -> create($id_quiz, $nb_questions, $id_img, $title);
}
public function getQuiz(int $id_quiz): ?quizEntity
@ -19,7 +19,9 @@ class QuizModel extends Model{
if ($q) {
return new quizEntity(
$q[0]['id_quiz'],
$q[0]['nb_quest']
$q[0]['nb_quest'],
$q[0]['id_img'],
$q[0]['title']
);
}
return null;
@ -32,6 +34,20 @@ class QuizModel extends Model{
public function listQuiz() : array
{
$res = $this -> gateway -> findAll();
$quizs = [];
foreach ($res as $quiz)
{
$quizs[] = new quizEntity(
$quiz['id_quiz'],
$quiz['nb_quest'],
$quiz['imgpath'],
$quiz['title']
);
}
return $quizs;
}
}

@ -10,7 +10,7 @@ echo $twig->render('head.html.twig', [
echo $twig->render('bandeau.html.twig');
echo $twig->render('quiz.html.twig', [
'quizList' => $quizIds
echo $twig->render('accueilQuiz.html.twig', [
'quizs' => $quizs
]);
?>

@ -1,11 +1,11 @@
<h2>Liste des Quiz</h2>
<ul>
{% for quiz in quizList %}
{% for quiz in quizs %}
<li>
<div class="quizCard">
<a href="{{ racine }}/quote/{{ quizIds.id_quiz }}">
<img src="{{ quizIds.image }}" alt="Image du quiz {{ quiz.title }}">
<h3>{{ quizIds.title }}</h3>
<a href="{{ racine }}/quiz/{{ quiz.id_quiz }}" class="linkQuiz">
<img src="{{ quiz.imgPath }}" alt="Image du quiz {{ quiz.title }}">
<h3>{{ quiz.title }} ({{ quiz.nb_quest }} questions)</h3>
</a>
</div>
</li>
@ -14,4 +14,4 @@
{% endfor %}
</ul>
</body>
</html>
</html>

Loading…
Cancel
Save