Fix et ajout navBar sur le quiz

php
Lucie GOIGOUX 1 year ago
parent 79f10db489
commit ffefe0d0b9

@ -12,6 +12,7 @@ class VisitorController
{
public function memory($match): void{
global $twig;
global $user;
try{
$idVoc = Validation::filter_int($_POST['idVoc'] ?? 4);
@ -19,6 +20,7 @@ class VisitorController
$name = ((new \gateway\VocabularyListGateway())->findById($idVoc))->getName();
$wordShuffle = array();
shuffle($wordList);
$pairs = [];
$maxWords = 28;
@ -33,11 +35,22 @@ class VisitorController
shuffle($wordShuffle);
echo $twig->render('memory.html', [
'wordShuffle' => $wordShuffle,
'pairs' => json_encode($pairs),
'name' => $name
]);
if(isset($user)) {
echo $twig->render('memory.html', [
'wordShuffle' => $wordShuffle,
'pairs' => json_encode($pairs),
'name' => $name,
'userID' => $user->getID(),
'userRole' => $user->getRoles()
]);
}
else{
echo $twig->render('memory.html', [
'wordShuffle' => $wordShuffle,
'pairs' => json_encode($pairs),
'name' => $name
]);
}
}
catch (Exception $e){
@ -47,40 +60,60 @@ class VisitorController
public function quiz($match): void
{
global $twig;
$vocabId = Validation::filter_int($_POST['idVoc'] ?? 4);
$vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null;
if ($vocabList == null) throw new Exception("liste inconnue");
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId);
$shuffle = $allTranslation;
shuffle($shuffle);
$questions = array();
$goodAnswers = array();
$allEnglishWords = array();
foreach ($allTranslation as $translation) {
$questions[] = $translation->getWord1();
$allEnglishWords[] = $translation->getWord2();
$goodAnswers[] = $translation->getWord2();
}
global $user;
try {
$vocabId = Validation::filter_int($_POST['idVoc'] ?? 4);
$vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null;
if ($vocabList == null) throw new Exception("liste inconnue");
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId);
$shuffle = $allTranslation;
shuffle($shuffle);
$questions = array();
$goodAnswers = array();
$allEnglishWords = array();
foreach ($allTranslation as $translation) {
$questions[] = $translation->getWord1();
$allEnglishWords[] = $translation->getWord2();
$goodAnswers[] = $translation->getWord2();
}
$answers = array();
$answers = array();
for($i=0 ; $i< count($questions) ; $i++) {
$correctAnswer = $allTranslation[$i]->getWord2();
array_splice($allEnglishWords, array_search($correctAnswer, $allEnglishWords), 1);
for ($i = 0; $i < count($questions); $i++) {
$correctAnswer = $allTranslation[$i]->getWord2();
array_splice($allEnglishWords, array_search($correctAnswer, $allEnglishWords), 1);
$tab = array_rand(array_flip($allEnglishWords), 3);
$tab = array_rand(array_flip($allEnglishWords), 3);
array_push($allEnglishWords, $correctAnswer);
array_push($allEnglishWords, $correctAnswer);
$tab[] = $correctAnswer;
shuffle($tab);
$answers[] = $tab;
}
$tab[] = $correctAnswer;
shuffle($tab);
$answers[] = $tab;
}
echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers, 'listName' => $vocabList->getName()]);
if (isset($user)) {
echo $twig->render('quizView.html', [
'questions' => $questions,
'answers' => $answers,
'goodAnswers' => $goodAnswers,
'listName' => $vocabList->getName(),
'userID' => $user->getID(),
'userRole' => $user->getRoles()]);
} else {
echo $twig->render('quizView.html', [
'questions' => $questions,
'answers' => $answers,
'goodAnswers' => $goodAnswers,
'listName' => $vocabList->getName()]);
}
}
catch (Exception $e){
throw new Exception("Erreur");
}
}
public function login(): void {

@ -21,6 +21,8 @@ h1{
gap: 10px;
margin: auto;
perspective: 1000px;
min-width: 70vw;
max-height: 70vh;
}
.card {

@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function () {
var word1;
var word2;
var clickEnabled = true;
var score = 25;
var score = 500;
cards.forEach(function (card) {
card.addEventListener('click', function () {
@ -12,7 +12,6 @@ document.addEventListener('DOMContentLoaded', function () {
return;
}
card.classList.toggle('flipped');
nbCard += 1;
if (nbCard === 1) {
word1 = card.dataset.word;
@ -67,12 +66,11 @@ document.addEventListener('DOMContentLoaded', function () {
(pair[0] === word1 && pair[1] === word2) ||
(pair[0] === word2 && pair[1] === word1)
) {
score+=10;
return true;
}
}
if(score !== 0){
score-=1;
score-=5;
}
return false;
}

@ -4,11 +4,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Game</title>
<link href="{{base}}/css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="{{base}}/css/memory.css">
<link rel="icon" type="image/x-icon" href="{{base}}/assets/favicon.ico"/>
</head>
<body>
<div>
{% include 'navBar.twig' %}
<div class="content">
<h1><u>Memory Game:</u> <i>{{ name }}</i></h1>
<div id="memory-game">
{% for word in wordShuffle %}

@ -19,7 +19,7 @@
</head>
<body>
{% include 'navBar.twig' %}
<section id="quiz">
<h1>{{listName}}</h1>
<div id="questionContainer">

@ -12,7 +12,7 @@
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
height: auto;
}
.content {

Loading…
Cancel
Save