Add Score + Start endQuiz View

pull/19/head
tomivt 5 months ago
parent 51d2ee5728
commit 10ac911cc7

@ -5,12 +5,8 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="afa12d51-331f-4dbc-a297-7289ad4e396d" name="Changes" comment=""> <list default="true" id="afa12d51-331f-4dbc-a297-7289ad4e396d" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/index.php" beforeDir="false" afterPath="$PROJECT_DIR$/index.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Controleur/QuizController.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/QuizController.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Controleur/QuizController.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/QuizController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Model/QuizModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/QuizModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/templates/quiz.html.twig" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/quiz.html.twig" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -71,27 +67,30 @@
&quot;associatedIndex&quot;: 4 &quot;associatedIndex&quot;: 4
}</component> }</component>
<component name="ProjectId" id="2oQGGlghI0ydDNgxjOeok3kwC7m" /> <component name="ProjectId" id="2oQGGlghI0ydDNgxjOeok3kwC7m" />
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="1" id="Add" />
</component>
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;master&quot;, "git-widget-placeholder": "quizPart",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
}, },
&quot;keyToStringList&quot;: { "keyToStringList": {
&quot;DatabaseDriversLRU&quot;: [ "DatabaseDriversLRU": [
&quot;postgresql&quot; "postgresql"
] ]
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/vue/templates" /> <recent name="$PROJECT_DIR$/vue/templates" />

@ -0,0 +1,95 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\CoreExtension;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
use Twig\TemplateWrapper;
/* endQuiz.html.twig */
class __TwigTemplate_c06a302c21f2b7c0cffcc93742935dad extends Template
{
private Source $source;
/**
* @var array<string, Template>
*/
private array $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->parent = false;
$this->blocks = [
];
}
protected function doDisplay(array $context, array $blocks = []): iterable
{
$macros = $this->macros;
// line 1
yield "<!DOCTYPE html>
<html lang=\"fr\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>Wiki Fantasy : Quiz</title>
<link id=\"favicon\" rel=\"icon\" href=\"../../images/iconeSombre.ico\"> <!-- Par défaut sombre -->
<link rel=\"stylesheet\" href=\"../../public/styles/styleQuiz.css\">
<script defer src=\"../../public/script/theme-toggle.js\"></script>
</head>
<body>
<h2> ";
// line 14
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["score"] ?? null), "html", null, true);
yield " </h2>
</body>
</html>
";
yield from [];
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName(): string
{
return "endQuiz.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function isTraitable(): bool
{
return false;
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo(): array
{
return array ( 57 => 14, 42 => 1,);
}
public function getSourceContext(): Source
{
return new Source("", "endQuiz.html.twig", "/Users/kiem/Documents/WikiFantasy/WF-Website/vue/templates/endQuiz.html.twig");
}
}

@ -1,6 +1,4 @@
<?php <?php
namespace Controleur; namespace Controleur;
use Entity\QuestionEntity; use Entity\QuestionEntity;
@ -17,8 +15,6 @@ use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError; use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader; use Twig\Loader\FilesystemLoader;
class QuizController class QuizController
{ {
@ -45,15 +41,13 @@ class QuizController
$action = $_REQUEST['action'] ?? null; $action = $_REQUEST['action'] ?? null;
$id = (int) explode('/', $_SERVER['REQUEST_URI'])[2] ?? null; $id = (int) explode('/', $_SERVER['REQUEST_URI'])[2] ?? null;
$nb_questions = $this->getNumberOfQuestion($id);
switch ($action) { switch ($action) {
case 'canswer': case 'canswer':
if ($this->CorrectAnswer()) if ($this->CorrectAnswer())
echo "Bonne réponse"; $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1;
else echo "Mauvaise réponse"; $this->continueQuiz($id, $nb_questions);
$_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
header("Location: http://localhost:8000/quiz/$id");
break; break;
default: default:
switch($id) switch($id)
@ -62,6 +56,7 @@ class QuizController
// page erreur // page erreur
break; break;
default: default:
$_SESSION['score'] = $_SESSION['score'] ?? 0;
$this->showQuestion($id, $_SESSION['no_question'] ?? 0); $this->showQuestion($id, $_SESSION['no_question'] ?? 0);
break; break;
} }
@ -69,6 +64,40 @@ class QuizController
} }
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function continueQuiz(int $id_quiz, int $total_questions) : void
{
$score = $_SESSION['score'];
$_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
if ($_SESSION['no_question'] >= $total_questions) {
session_destroy();
$this->endQuiz($id_quiz, $score);
}
else header("Location: http://localhost:8000/quiz/$id_quiz");
}
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function endQuiz(int $id_quiz, int $score) : void
{
global $twig;
$gw = new QuizGateway($this->co);
$mdl = new QuizModel($gw);
if ($mdl->getQuiz($id_quiz + 1))
echo $twig->render('endQuiz.html.twig', ['score' => $score, 'nextquiz' => $id_quiz + 1]);
echo $twig->render('endQuiz.html.twig', ['score' => $score]);
}
public function CorrectAnswer() : bool public function CorrectAnswer() : bool
{ {
$answera = $_POST['answera'] ?? null; $answera = $_POST['answera'] ?? null;
@ -104,11 +133,6 @@ class QuizController
return $mdl->getAllQuestionByQuiz($id, $this->co); return $mdl->getAllQuestionByQuiz($id, $this->co);
} }
public function RunQuiz(int $idQuiz)
{
}
/** /**
* @throws RuntimeError * @throws RuntimeError
* @throws SyntaxError * @throws SyntaxError
@ -118,14 +142,11 @@ class QuizController
{ {
global $twig; global $twig;
echo $num; echo $num;
echo " : ", $_SESSION['score'];
$q = $this->GetQuestion($id); $q = $this->GetQuestion($id);
$question = $q[$num]; $question = $q[$num] ?? $q[0];
$idquestion = $question->getIdQuestion(); $idquestion = $question->getIdQuestion();
echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]);
//else
//page resultat
} }

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wiki Fantasy : Quiz</title>
<link id="favicon" rel="icon" href="../../images/iconeSombre.ico"> <!-- Par défaut sombre -->
<link rel="stylesheet" href="../../public/styles/styleQuiz.css">
<script defer src="../../public/script/theme-toggle.js"></script>
</head>
<body>
<h1 style="color: #b7c8ff"> {{ score }} </h1>
<h1> {{ nextquiz }} </h1>
zeze
</body>
</html>
Loading…
Cancel
Save