Lucie GOIGOUX 1 year ago
commit 975b4a80a6

@ -9,7 +9,7 @@ use gateway\VocabularyListGateway;
use model\MdlStudent;
use model\VocabularyList;
abstract class AbsController
class AbsController
{
public function showAccountInfos(): void {
@ -92,12 +92,40 @@ abstract class AbsController
throw new Exception("Erreur");
}
}
public function quiz(): void
public function quiz($match): void
{
global $twig;
$vocabId = $_GET['vocabID'];
$vocabId = Validation::filter_int($match['params']['id'] ?? null);
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId);
echo $twig->render('quizzView.html', ['translations' => $allTranslation]);
$shuffle = $allTranslation;
shuffle($shuffle);
echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations' => $shuffle]);
}
public function login(): void {
global $twig;
echo $twig->render('login.html');
}
public function confirmLogin(): void {
$model = new MdlStudent();
$login = strip_tags($_POST['logemail']);
$password = strip_tags($_POST['logpass']);
if (!$this->checkLoginExist($login)) throw new Exception(("login invalide"));
$user = $model->connection($login, $password);
if ($user == null) throw new Exception("mot de passe invalide");
$this->home();
}
public function checkLoginExist(string $login): bool {
$mdl = new MdlStudent();
return $mdl->checkLoginExist($login);
}
public function disconnect(): void {
$mdl = new MdlStudent();
$mdl->deconnection();
$this->home();
}
}

@ -19,11 +19,13 @@ class FrontController
$router = new \AltoRouter();
$router->setBasePath($altorouterPath);
$router->map('GET', '/', 'AppController');
$router->map('GET|POST', '/[a:action]?/[i:id]?', 'NULL');
$router->map('GET', '/', 'FrontController');
$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');
$router->map('GET|POST', '/abs/[a:action]?', 'Abs');
$twig->addGlobal('base', $altorouterPath);
$match = $router->match();
@ -40,25 +42,6 @@ class FrontController
$this->home();
break;
case 'memory':
AbsController::memory($match);
break;
case 'login':
$this->login();
break;
case 'confirmLogin':
$this->confirmLogin();
break;
case 'disconnect':
$this->disconnect();
break;
case 'quiz':
$this->quiz();
break;
default :
if ($id != null && !$this->checkIdExist($id)) throw new Exception("identifiant invalide");
if ($target == null) throw new Exception("pas de target");
@ -85,7 +68,7 @@ class FrontController
break;
}
else $this->login();
else (new AbsController())->login();
}
}
}
@ -96,42 +79,9 @@ class FrontController
}
}
public function home(): void {
global $twig;
echo $twig->render('home.html');
var_dump($_SESSION['roles']);
}
public function login(): void {
global $twig;
echo $twig->render('login.html');
}
public function confirmLogin(): void {
$model = new MdlStudent();
$login = strip_tags($_POST['logemail']);
$password = strip_tags($_POST['logpass']);
$user = $model->connection($login, $password);
$this->home();
}
public function checkIdExist(int $id):bool
{
$mdl = new MdlStudent();
$res = $mdl->checkIdExist($id);
return $res;
}
public function disconnect(): void {
$mdl = new MdlStudent();
$mdl->deconnection();
$this->home();
}
public function quiz(){
$ctrl = new StudentController();
$ctrl->quiz();
}
}

@ -35,23 +35,4 @@ class StudentController
$vocab = $mdl->getVocabByName($name);
echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]);
}
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) {
}
}
}*/
}

@ -125,6 +125,7 @@ class UserGateway extends AbsGateway
$args = array(':id' => array($id, PDO::PARAM_INT));
$this->con->executeQuery($query, $args);
$results = $this->con->getResults();
if (empty($results)) return null;
return new User($results[0]['id'], $results[0]['password'], $results[0]['email'], $results[0]['name'], $results[0]['surname'], $results[0]['nickname'], $results[0]['image'], $results[0]['extraTime'], $results[0]['groupID'], $this->getRoles($results[0]['id']));
}
catch(PDOException $e ){
@ -159,12 +160,13 @@ class UserGateway extends AbsGateway
}
}
public function findUserByEmail(string $email) : User{
public function findUserByEmail(string $email){
try {
$query = "SELECT * FROM User_ WHERE email=:email";
$args = array(':email' => array($email, PDO::PARAM_STR));
$this->con->executeQuery($query, $args);
$results = $this->con->getResults();
if (empty($results)) return null;
return new User($results[0]['id'], $results[0]['password'], $results[0]['email'], $results[0]['name'], $results[0]['surname'], $results[0]['nickname'], $results[0]['image'], $results[0]['extraTime'], $results[0]['groupID'], $this->getRoles($results[0]['id']));
}
catch(PDOException $e ){
@ -296,17 +298,4 @@ class UserGateway extends AbsGateway
throw new Exception($e->getMessage());
}
}
public function checkIdExist(int $id): bool {
$query = "SELECT COUNT(*) AS count FROM User_ WHERE id = :id";
$args = array(':id' => array($id, PDO::PARAM_INT));
$this->con->executeQuery($query, $args);
$results = $this->con->getResults();
if (is_array($results) && count($results) > 0) {
$count = $results[0]['count'];
return ($count > 0);
}
return false;
}
}

@ -40,5 +40,10 @@ abstract class AbsModel
$_SESSION = array();
}
public function checkLoginExist(string $login) {
$gtw = new UserGateway();
return $gtw->findUserByEmail($login) != null;
}
public abstract function is(string $login, array $roles);
}

@ -13,10 +13,6 @@ class MdlStudent extends AbsModel
{
parent::__construct("student");
}
public function checkIdExist(int $id):bool {
$gtw = new UserGateway();
return $gtw->checkIdExist($id);
}
public function getAll():array{
$gtw = new VocabularyListGateway();

@ -34,7 +34,7 @@
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#game">Game</a></li>
<li class="nav-item"><a class="nav-link" href="#download">Download</a></li>
<li class="nav-item"><a class="nav-link" href="login">My account</a></li>
<li class="nav-item"><a class="nav-link" href="{{base}}/abs/login">My account</a></li>
</ul>
</div>
</div>

@ -5,12 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unicons.iconscout.com/release/v2.1.9/css/unicons.css" rel="stylesheet"/>
<link href="css/login.css" rel="stylesheet" />
<link href="../css/login.css" rel="stylesheet" />
<title>Login</title>
</head>
<body>
<div class="section">
<a href="."><img src="assets/img/home.png"></a>
<a href="{{base}}/"><img src="../assets/img/home.png"></a>
<div class="container">
<div class="row full-height justify-content-center">
<div class="col-12 text-center align-self-center py-5">
@ -24,7 +24,7 @@
<div class="center-wrap">
<div class="section text-center">
<h4 class="mb-4 pb-3">Log In</h4>
<form action="confirmLogin" method="POST">
<form action="{{base}}/abs/confirmLogin" method="POST">
<div class="form-group">
<input type="email" name="logemail" class="form-style" placeholder="Your Email" id="logemail" autocomplete="off">
<i class="input-icon uil uil-at"></i>

@ -2,41 +2,56 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Manage groups</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Font Awesome icons (free version)-->
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
<!-- Google fonts-->
<link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet" />
<link
href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
<title>Manage groups</title><!-- Vos liens de styles et de scripts -->
</head>
<body>
<section>
<h1>Quiz</h1>
<form action="quiz" method="post">
<h2>{{frenchWord}}</h2>
{% for i in 0..3 %}
{% if translations is defined %}
{% for translation in translations %}
<h2>{{ translation.word1 }}</h2>
{% set correctAnswer = translation.word2 %}
{% if randomtranslations is defined %}
{% set otherTranslations = [correctAnswer] %}
{% for randomtranslation in randomtranslations %}
{% if randomtranslation.word2 != correctAnswer and otherTranslations|length <= 3 %}
{% set otherTranslations = otherTranslations|merge([randomtranslation.word2]) %}
{% endif %}
{% endfor %}
<input type="radio" name="answer{{i}}" value="{{valid[i]}}"> {{answers[i]}}<br>
{% endfor %}
<input type="submit" value="Soumettre">
{# Affichage des réponses sous forme de radio buttons #}
<input type="radio" name="answer" value="{{ correctAnswer }}"> {{ correctAnswer }}<br>
{% for otherTranslation in otherTranslations %}
<input type="radio" name="answer" value="{{ otherTranslation }}"> {{ otherTranslation }}<br>
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
<input type="submit" value="Submit" name="submitForm">
</form>
{% if submitted %}
{% if isCorrect %}
<p>Correct answer!</p>
{% else %}
<p>Wrong answer!</p>
{% endif %}
{% endif %}
</section>
<h1>Translator</h1>
<form action="quiz?vocabID={{row.id}}" method="POST">
<label for="wordInput">Enter a word:</label>
<input type="text" id="wordInput" name="wordInput">
<form action="quiz" method="POST">
{% if translations is defined %}
{% for translation in translations %}
<label for="wordInput{{ translation.id }}">Traduire {{ translation.word1 }}</label>
<input type="text" id="wordInput{{ translation.id }}" name="wordInput{{ translation.id }}">
<input type="hidden" name="vocabID" value="{{ translation.listVocab }}">
<button type="submit">Translate</button>
{% endfor %}
{% endif %}
</form>
</section>
</body>
</html>
Loading…
Cancel
Save