Merge pull request 'Création du Quiz random' (#30) from ajoutQuiz into master

Reviewed-on: #30
master
Kentin BRONGNIART 3 months ago
commit 3403a5592c

@ -14,7 +14,7 @@ $mdp = '';
//$racine='/~kemondejar/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website
$racine='/WF-Website';
$racine='/~kekentin/WF/WF-Website';
//$repImg='/home/UCA/kemondejar/public_html/WF-Website/public/images/';
$repImg='/';
@ -35,6 +35,8 @@ $vues['endQuiz'] = 'vue/endQuiz.php';
$vues['submitQuote'] = 'vue/submitQuote.php';
$vues['recap'] = 'vue/recap.php';
$vues['accueilQuiz'] = 'vue/accueilQuiz.php';
$vues['quizRandom'] = 'vue/quizRandom.php';
$vues['endQuizRandom'] = 'vue/endQuizRandom.php';

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

@ -16,7 +16,7 @@ Class FrontControler{
global $twig,$racine;
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'),
'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add', 'accueilQuiz', 'deleteAccount'),
'user' => array('quiz','randomQuiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add', 'accueilQuiz', 'deleteAccount'),
'admin' => array('null')];
$dVueEreur = [];
@ -56,6 +56,7 @@ Class FrontControler{
$router->map('GET|POST', '/add', 'UserControler', 'add');
$router->map('GET|POST', '/accueilQuiz', 'UserControler', 'accueilQuiz');
$router->map('GET|POST', '/error', 'VisitorControler','error');
$router->map('GET|POST', '/randomQuiz', 'UserControler','randomQuiz');
$router->map('GET|POST', '/deleteAccount', 'UserControler', 'deleteAccount');

@ -53,6 +53,90 @@ class UserControler {
$quizs = $this->quizModel->listQuiz();
require_once $vues['accueilQuiz'];
}
public function randomQuiz() {
global $vues;
$canswer = Verification::verifChar($_POST['canswer'] ?? null);
/*---------------------------------------------*/
if(!isset($_SESSION["no_question"])){
$no_question = 0;
}
else{
$no_question = Verification::verifChar($_SESSION["no_question"]);
if($canswer!=null){
$no_question=$no_question+1;
}
if($no_question < 1 ){
$no_question = 0;
}
}
$_SESSION["no_question"]=$no_question;
/*---------------------------------------------*/
if(!isset($_SESSION["nbVie"])){
$vie = 3;
}
else{
$vie = Verification::verifChar($_SESSION["nbVie"]) ;
if($vie > 3 ){
$vie = 3;
}
elseif($vie < 1){
$vie = 0;
}
}
/*---------------------------------------------*/
$answera = Verification::verifChar($_POST['answera'] ?? null);
$answerb = Verification::verifChar($_POST['answerb'] ?? null);
$answerc = Verification::verifChar($_POST['answerc'] ?? null);
$answerd = Verification::verifChar($_POST['answerd'] ?? null);
$answer = null;
if ($answera) {
$answer = $answera;
} elseif ($answerb) {
$answer = $answerb;
} elseif ($answerc) {
$answer = $answerc;
} elseif ($answerd) {
$answer = $answerd;
}
if($answer != $canswer){
$vie=$vie-1;
}
/*---------------------------------------------*/
$_SESSION["nbVie"]=$vie;
if($vie<=0){
$score=($no_question - 3);
$next=false;
$nbQuestion=$no_question;
unset($_SESSION["no_question"]);
unset($_SESSION["nbVie"]);
require_once $vues['endQuizRandom'];
}
else{
/*---------------------------------------------*/
$question = $this->questMod->QuestionForQuoteToCarac('fr');
require_once $vues['quizRandom'];
}
}
public function profil() {
@ -531,25 +615,6 @@ class UserControler {
}
}
// Quiz aléatoire
// argument = Langue / type question / type reponse
public function quizAleatoire(){
global $vues;
if(!isset($_POST["nbVie"])){
$vie = 3;
}
$question = $questMod->getRandomQuestion([$_POST["questionType"],$_POST["awnserType"]],$_POST["langue"]);
addTab($question);
if($question == null){
$erreur = [501,"Erreur serveur lors de l'obtention de la question"];
$require_once($vues["erreur"]);
}
else{
$require_once($vues['quiz']);
}
}
public function questionSuivantAleatoire(){
}

@ -102,4 +102,71 @@ class QuestionGateway extends Gateway
}
/*--------------------------------------- Quiz Aléatoire ---------------------------------------*/
/*----------------------- Question + Reponce Corecte -----------------------*/
public function QuestionToReponceForQuoteToCarac(string $lang) : array
{
$query = "Select q.content as Question ,c.caracter as Reponce
from Quote Q
join Caracter c on c.id_caracter=q.id_caracter
where q.langue=:lang and q.isValide = 'true'
ORDER BY RANDOM()
LIMIT 1;";
$this -> co -> executeQuery($query, [':lang' => array($lang, PDO::PARAM_STR)]);
return $this -> co -> getResults();
}
public function QuestionToReponceForQuoteToTitle(string $lang) : array
{
$query = "Select q.content as Question ,s.title as Reponce
from Quote Q
join Source s on s.id_source=q.id_source
where q.langue=:lang and q.isValide = 'true'
ORDER BY RANDOM()
LIMIT 1;";
$this -> co -> executeQuery($query, [':lang' => array($lang, PDO::PARAM_STR)]);
return $this -> co -> getResults();
}
/*----------------------- Reponce Fausse -----------------------*/
public function FakeReponceForQuoteToCarac(string $lang,string $corecteReponce) : array
{
$query = "Select c.caracter as Reponce
from Quote Q
join Caracter c on c.id_caracter=q.id_caracter
where q.langue = :lang And c.caracter != :corecteReponce and q.isValide = 'true'
ORDER BY RANDOM()
LIMIT 3;";
$this -> co -> executeQuery($query, [
':lang' => array($lang, PDO::PARAM_STR),
':corecteReponce' => array($lang, PDO::PARAM_STR)
]);
return $this -> co -> getResults();
}
public function FakeReponceForQuoteToTitle(string $lang,string $corecteReponce) : array
{
$query = "Select s.title as Reponce
from Quote Q
join Source s on s.id_source=q.id_source
where q.langue = :lang And s.title != :corecteReponce and q.isValide = 'true'
ORDER BY RANDOM()
LIMIT 3;";
$this -> co -> executeQuery($query, [
':lang' => array($lang, PDO::PARAM_STR),
':corecteReponce' => array($lang, PDO::PARAM_STR)
]);
return $this -> co -> getResults();
}
}

@ -114,4 +114,47 @@ class QuestionModel extends Model
return null;
}
}
/*--------------------------------------- Quiz Aléatoire ---------------------------------------*/
/*----------------------- Question compléte -----------------------*/
public function QuestionForQuoteToCarac(string $lang) : QuestionEntity
{
$questRep = $this->gateway->QuestionToReponceForQuoteToCarac($lang);
$quest = $questRep[0]['question'];
$cAnswer = $questRep[0]['reponce'];
$fake = $this->gateway->FakeReponceForQuoteToCarac($lang,$cAnswer);
$fakeRep = [$cAnswer];
foreach ($fake as $rep){
$fakeRep[]=$rep['reponce'];
}
shuffle($fakeRep);
return new QuestionEntity(-1,$quest,$fakeRep[0],$fakeRep[1],$fakeRep[2],$fakeRep[3],$cAnswer);
}
public function QuestionForQuoteToTitle(string $lang) : QuestionEntity
{
$questRep = $this->gateway->QuestionToReponceForQuoteToTitle($lang);
$quest = $questRep['question'];
$cAnswer = $questRep['reponce'];
$fake = $this->gateway->FakeReponceForQuoteToTitle($lang,$cAnswer);
$fakeRep = [$cAnswer];
foreach ($fake as $rep){
$fakeRep[]=$rep['reponce'];
}
$fakeRep=array_rand($fakeRep);
return new QuestionEntity(-1,$quest,$fakeRep[0],$fakeRep[1],$fakeRep[2],$fakeRep[3],$cAnswer);
}
}

@ -2,7 +2,7 @@
namespace Model;
use Entity\quizEntity;
use Entity\QuizEntity;
use Gateway\QuizGateway;
use Gateway\Gateway;
@ -13,11 +13,11 @@ class QuizModel extends Model{
return $this -> gateway -> create($id_quiz, $nb_questions, $id_img, $title);
}
public function getQuiz(int $id_quiz): ?quizEntity
public function getQuiz(int $id_quiz): ?QuizEntity
{
$q = $this -> gateway -> findQuizById($id_quiz);
if ($q) {
return new quizEntity(
return new QuizEntity(
$q[0]['id_quiz'],
$q[0]['nb_quest'],
$q[0]['imgpath'],
@ -40,7 +40,7 @@ class QuizModel extends Model{
foreach ($res as $quiz)
{
$quizs[] = new quizEntity(
$quizs[] = new QuizEntity(
$quiz['id_quiz'],
$quiz['nb_quest'],
$quiz['imgpath'],

@ -8,14 +8,12 @@ echo $twig->render('head.html.twig', [
'scripts' => array("../public/script/theme-toggle-double-param.js")
]);
// Rendu du bandeau
echo $twig->render('bandeau.html.twig');
echo $twig->render('endQuiz.html.twig',
['score' => $score,
'isNextQuiz' => $next,
'nextquiz' => $id_quiz + 1,
'nb' => $nbQuestion]);
?>

@ -0,0 +1,17 @@
<?php
global $twig;
echo $twig->render('head.html.twig', [
'title' => "Quiz",
'style' => "public/styles/styleEndQuiz.css",
'scripts' => array("public/script/theme-toggle.js")
]);
// Rendu du bandeau
echo $twig->render('bandeau.html.twig');
echo $twig->render('endQuizRandom.html.twig',
['score' => $score
]);
?>

@ -10,5 +10,9 @@ echo $twig->render('head.html.twig', [
// Rendu du bandeau
echo $twig->render('bandeau.html.twig');
echo $twig->render('quiz.html.twig', ['idQuiz'=>$id , 'question' => $question,'id'=>$idquestion]);
?>
echo $twig->render('quiz.html.twig', [
'question' => $question,
'id'=>$idquestion,
'nb' => $num + 1,
'nbFinal' => $nbQuestion
]);

@ -0,0 +1,20 @@
<?php
global $twig;
echo $twig->render('head.html.twig', [
'title' => "Random Quiz",
'style' => "public/styles/styleQuiz.css",
'scripts' => array("public/script/theme-toggle.js")
]);
// Rendu du bandeau
echo $twig->render('bandeau.html.twig');
echo $twig->render('quizRandom.html.twig', [
'vie' => $vie,
'question' => $question,
'nb' => $no_question + 1
]);

@ -1,5 +1,13 @@
<h2>Liste des Quiz</h2>
<div class="quiz-container">
<div class="quizCard">
<a href="{{ racine }}/randomQuiz" class="linkQuiz">
<img src="{{ racine }}/images/quizz.svg" alt="Image du quiz random">
<h3>Quiz random </h3>
</a>
</div>
{% for quiz in quizs %}
<div class="quizCard">
<a href="{{ racine }}/quiz/{{ quiz.id_quiz }}" class="linkQuiz">
@ -10,6 +18,9 @@
{% else %}
<h3>Aucun quiz disponible pour le moment.</h3>
{% endfor %}
</div>
</body>
</html>

@ -3,11 +3,11 @@
<p> nombre de réponse juste : {{ score }}</p>
<p> nombre de réponse fausse : {{ nb - score }}</p>
<p> pourcentage de réusite : {{ (100 * score) / nb }}%<p>
{% if nextquiz %}
<a class="suiv" href="{{racine}}/quiz/{{ nextquiz }}" alt="quiz suivant">
<img src="../images/suivant.png" />
</a>
{% endif %}
<a class="suiv" href="{{racine}}/accueilQuiz" alt="Retour selection quiz">
<img src="../images/suivant.png" />
</a>
</div>
</body>
</html>

@ -0,0 +1,12 @@
<h1>Résultat</h1>
<div class="resultat">
<p> nombre de réponse juste : {{ score }}</p>
<a class="suiv" href="{{racine}}/accueilQuiz" alt="Retour selection quiz">
<img src="images/suivant.png" />
</a>
</div>
</body>
</html>

@ -4,16 +4,16 @@
<form id="quizForm" method="POST" >
<div class="answers">
<button class="answer" name="answera" value="A-{{ id }}">
<button class="answer" name="answera" value="{{ question.answera }}-{{ id }}">
{{ question.answera }}
</button>
<button class="answer" name="answerb" value="B-{{ id }}">
<button class="answer" name="answerb" value="{{ question.answerb }}-{{ id }}">
{{ question.answerb }}
</button>
<button class="answer" name="answerc" value="C-{{ id }}">
<button class="answer" name="answerc" value="{{ question.answerc }}-{{ id }}">
{{ question.answerc }}
</button>
<button class="answer" name="answerd" value="D-{{ id }}">
<button class="answer" name="answerd" value="{{ question.answerd }}-{{ id }}">
{{ question.answerd }}
</button>
</div>

@ -0,0 +1,27 @@
<h1>Quiz Random</h1>
<div class="quiz">
<h2> {{ question.question }} </h2>
<h3>Vie restante : {{ vie }}</h3>
<form id="quizForm" method="POST" >
<div class="answers">
<button class="answer" name="answera" value="{{ question.answera }}">
{{ question.answera }}
</button>
<button class="answer" name="answerb" value="{{ question.answerb }}">
{{ question.answerb }}
</button>
<button class="answer" name="answerc" value="{{ question.answerc }}">
{{ question.answerc }}
</button>
<button class="answer" name="answerd" value="{{ question.answerd }}">
{{ question.answerd }}
</button>
</div>
<input type="hidden" name="canswer" value="{{ question.canswer }}">
</form>
<a id="timer">{{ nb }}/∞</a>
</div>
</body>
</html>
Loading…
Cancel
Save