|
|
|
@ -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 {
|
|
|
|
|