debut de travail sur le jeu quiz

php
Patrick BRUGIERE 2 years ago
commit 6e5fd079fb

@ -34,9 +34,6 @@ INSERT INTO Be VALUES (3, 3);
INSERT INTO Be VALUES (6, 3);
INSERT INTO Be VALUES (10, 3);
INSERT INTO Be VALUES (4, 1);
INSERT INTO Be VALUES (4, 2);
INSERT INTO Be VALUES (20, 2);
INSERT INTO Be VALUES (5, 2);
@ -45,7 +42,7 @@ INSERT INTO Be VALUES (30, 1);
-- Vocabulary list
INSERT INTO VocabularyList VALUES (1, "Animaux", "", 5);
INSERT INTO VocabularyList VALUES (2, "Informatique", "", 5);
INSERT INTO VocabularyList VALUES (3, "Moyens de transport", "", 4);
INSERT INTO VocabularyList VALUES (3, "Moyens de transport", "", 20);
-- Vocabulary creation : FR
INSERT INTO Vocabulary VALUES ("Chat");

@ -0,0 +1,78 @@
<?php
namespace controller;
use config\Validation;
use Exception;
use gateway\TranslationGateway;
use gateway\VocabularyListGateway;
use model\MdlStudent;
use model\VocabularyList;
abstract class AbsController
{
public function showAccountInfos(): void {
try {
global $twig;
$userID = Validation::filter_int($_GET['user'] ?? null);
$mdl = new MdlStudent();
$user = $mdl->getUser($userID);
echo $twig->render('myAccountView.html', ['user' => $user]);
}
catch (Exception $e){
throw new Exception("invalid user ID");
}
}
public function modifyPassword(): void {
try {
$userID = $_GET['user'];
$currentPassword = Validation::val_password($_GET['currentPassword'] ?? null);
$newPassword = Validation::val_password($_GET['newPassword'] ?? null);
$confirmNewPassword = Validation::val_password($_GET['confirmNewPassword'] ?? null);
$mdl = new MdlStudent();
$user = $mdl->getUser($userID);
if ($user->getPassword() != $currentPassword || $newPassword != $confirmNewPassword)
throw new Exception("");
$mdl->ModifyPassword($userID, $newPassword);
$_GET['user'] = $userID;
$this->showAccountInfos();
}
catch (Exception $e){
throw new Exception("invalid entries");
}
}
public function modifyNickname(): void {
try {
$userID = Validation::filter_int($_GET['user'] ?? null);
$newNickname = Validation::filter_str_nospecialchar($_GET['newNickname'] ?? null);
$mdl = new MdlStudent();
$mdl->modifyNickname($userID, $newNickname);
$_GET['user'] = $userID;
$this->showAccountInfos();
}
catch (Exception $e){
throw new Exception("invalid entries");
}
}
public function memory(): void{
global $twig;
try{
$idVoc = Validation::filter_int($_GET['id'] ?? null);
$wordList = (new \gateway\TranslationGateway)->findByIdVoc($idVoc);
}
catch (Exception $e){
throw new Exception("Erreur");
}
echo $twig->render('memory.html');
}
}

@ -6,7 +6,7 @@ use config\Validation;
use model\MdlAdmin;
use Exception;
class AdminController
class AdminController extends AbsController
{
public function showAllUsers(): void {
global $twig;

@ -15,15 +15,12 @@ class FrontController
session_start();
var_dump($_SESSION['login']);
var_dump($_SESSION['roles']);
try {
$router = new \AltoRouter();
$router->setBasePath($altorouterPath);
$router->map('GET', '/', 'AppController');
$router->map('GET|POST', '/[a:action]?', 'NULL');
$router->map('GET|POST', '/[a:action]?/[i:id]?', 'NULL');
$router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'Admin');
$router->map('GET|POST', '/teacher/[i:id]/[a:action]?', 'Teacher');
$router->map('GET|POST', '/student/[i:id]/[a:action]?', 'Student');

@ -2,11 +2,8 @@
namespace controller;
use config\Validation;
use gateway\TranslationGateway;
use gateway\VocabularyListGateway;
use model\MdlStudent;
use Exception;
use model\Translation;
class StudentController
{
@ -37,69 +34,4 @@ class StudentController
$vocab = $mdl->getVocabByName($name);
echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]);
}
public function showAccountInfos(): void {
try {
global $twig;
$userID = Validation::filter_int($_GET['user'] ?? null);
$mdl = new MdlStudent();
$user = $mdl->getUser($userID);
echo $twig->render('myAccountView.html', ['user' => $user]);
}
catch (Exception $e){
throw new Exception("invalid user ID".$e->getFile().$e->getLine());
}
}
public function modifyNickname(): void {
try {
$userID = Validation::filter_int($_GET['user'] ?? null);
$newNickname = Validation::filter_str_nospecialchar($_GET['newNickname'] ?? null);
$mdl = new MdlStudent();
$mdl->modifyNickname($userID, $newNickname);
$_GET['user'] = $userID;
$this->showAccountInfos();
}
catch (Exception $e){
throw new Exception("invalid entries");
}
}
public function modifyPassword(): void {
try {
$userID = $_GET['user'];
$currentPassword = Validation::val_password($_GET['currentPassword'] ?? null);
$newPassword = Validation::val_password($_GET['newPassword'] ?? null);
$confirmNewPassword = Validation::val_password($_GET['confirmNewPassword'] ?? null);
$mdl = new MdlStudent();
$user = $mdl->getUser($userID);
if ($user->getPassword() != $currentPassword || $newPassword != $confirmNewPassword)
throw new Exception("");
$mdl->ModifyPassword($userID, $newPassword);
$_GET['user'] = $userID;
$this->showAccountInfos();
}
catch (Exception $e){
throw new Exception("invalid entries");
}
}
public function quiz(): void {
global $twig;
$vocabId = $_GET['vocabID'];
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId);
echo $twig->render('quizzView.html', ['translations' => $allTranslation ]);
}
/*
public function flashcard(VocabularyList $v) {
$idVoc = $v->getId();
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($idVoc);
while(1) {
}
}
*/
}

@ -6,7 +6,7 @@ use model\MdlTeacher;
use gateway\VocabularyListGateway;
use Exception;
class TeacherController
class TeacherController extends AbsController
{
public function affAllStudent(): void
{

Loading…
Cancel
Save