From ba8eb05b5d61a60f0170124b32bf16592d9827eb Mon Sep 17 00:00:00 2001 From: brongniart Date: Wed, 20 Nov 2024 16:50:19 +0100 Subject: [PATCH] dernier finition --- config/config.php | 4 +- src/Controleur/FrontControler.php | 3 +- src/Controleur/QuizControler.php | 92 +----------- src/Controleur/UserControler.php | 159 +++++++++++++++++++-- src/Controleur/VisitorControler.php | 8 +- src/Entity/UserEntity.php | 156 ++++++++++++++++++++ src/Entity/questionEntity.php | 148 ------------------- src/Gateway/AccueilGateway.php | 34 ----- src/Gateway/QuizQuestionGateway.php | 14 +- src/Gateway/QuoteGateway.php | 78 +++++++--- src/Gateway/UserGateway.php | 2 +- src/Gateway/favoritsGateway.php | 15 -- src/Model/QuestionModel.php | 2 +- src/Model/QuoteModel.php | 28 ++++ src/Model/SearchModel.php | 1 - src/Model/UserModel.php | 2 +- vue/accueil.php | 14 +- vue/endQuiz.php | 18 +++ vue/favorits.php | 2 +- vue/profil.php | 9 +- vue/quiz.html | 61 -------- vue/quiz.php | 17 +++ vue/quizz.html | 211 ---------------------------- vue/search.php | 16 +-- vue/templates/bandeau.html.twig | 2 +- vue/templates/endQuiz.html.twig | 13 -- vue/templates/profil.html.twig | 10 +- vue/templates/quiz.html.twig | 32 +---- vue/templates/quoteLittle.html.twig | 10 +- 29 files changed, 474 insertions(+), 687 deletions(-) create mode 100644 src/Entity/UserEntity.php delete mode 100644 src/Entity/questionEntity.php delete mode 100644 src/Gateway/favoritsGateway.php create mode 100644 vue/endQuiz.php delete mode 100644 vue/quiz.html create mode 100644 vue/quiz.php delete mode 100644 vue/quizz.html diff --git a/config/config.php b/config/config.php index 65bc07d..87e7c39 100644 --- a/config/config.php +++ b/config/config.php @@ -19,10 +19,12 @@ $vues['quote'] = 'vue/quote.php'; $vues['profil'] = 'vue/profil.php'; $vues['login'] = 'vue/login.php'; $vues['signin'] = 'vue/signin.php'; -$vues['quiz'] = 'vue/quiz.html'; $vues['search'] = 'vue/search.php'; $vues['favorite'] = 'vue/favorits.php'; +$vues['quiz'] = 'vue/quiz.php'; +$vues['endQuiz'] = 'vue/endQuiz.php'; + //Style css $style['accueil'] = 'public/styles/styleAccueil.css'; diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index 34cc64b..bb7f233 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -35,11 +35,12 @@ Class FrontControler{ $router->map('GET|POST', '/quote/[i:idQuote]', 'VisitorControler','quote'); $router->map('GET|POST', '/addComment', 'UserControler','addComment'); - $router->map('GET|POST', '/quiz/[i:id]?', 'QuizControler','quiz'); + $router->map('GET|POST', '/quiz/[i:id]', 'UserControler','quiz'); $router->map('GET|POST', '/favorite', 'UserControler','favorite'); $router->map('GET|POST', '/search', 'VisitorControler','search'); $router->map('GET|POST', '/profil', 'UserControler','profil'); $router->map('GET|POST', '/login', 'VisitorControler','login'); + $router->map('GET|POST', '/unlog', 'UserControler','unlog'); $router->map('GET|POST', '/signin', 'VisitorControler','signin'); $router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin'); $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); diff --git a/src/Controleur/QuizControler.php b/src/Controleur/QuizControler.php index 28ec2c7..318a7f2 100644 --- a/src/Controleur/QuizControler.php +++ b/src/Controleur/QuizControler.php @@ -41,6 +41,7 @@ class QuizControler $action = $_REQUEST['action'] ?? null; $id = (int) explode('/', $_SERVER['REQUEST_URI'])[2] ?? null; + echo $id; $nb_questions = $this->getNumberOfQuestion($id); switch ($action) { @@ -64,95 +65,6 @@ class QuizControler } - /** - * @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 - { - $answera = $_POST['answera'] ?? null; - $answerb = $_POST['answerb'] ?? null; - $answerc = $_POST['answerc'] ?? null; - $answerd = $_POST['answerd'] ?? null; - - $id= null; - $answer = null; - - if ($answera) { - $answer = explode('-', $answera)[0]; - $id = (int) explode('-', $answera)[1]; - } elseif ($answerb) { - $answer = explode('-', $answerb)[0]; - $id = (int) explode('-', $answerb)[1]; - } elseif ($answerc) { - $answer = explode('-', $answerc)[0]; - $id = (int) explode('-', $answerc)[1]; - } elseif ($answerd) { - $answer = explode('-', $answerd)[0]; - $id = (int) explode('-', $answerd)[1]; - } - - $res = $this->mdl->getQuestion($id); - return $answer == $res->getCanswer(); - } - - public function GetQuestion(int $id): array - { - $gw = new QuizQuestionGateway($this->co); - $mdl = new QuizQuestionModel($gw); - return $mdl->getAllQuestionByQuiz($id, $this->co); - } - - /** - * @throws RuntimeError - * @throws SyntaxError - * @throws LoaderError - */ - public function showQuestion(int $id, int $num) : void - { - global $twig; - $q = $this->GetQuestion($id); - $question = $q[$num] ?? $q[0]; - $idquestion = $question->getIdQuestion(); - echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); - } - - - public function getNumberOfQuestion(int $id) : int - { - $gw = new QuizGateway($this->co); - $mdl = new QuizModel($gw); - return $mdl->getQuiz($id)->getNbQuestions(); - } + } \ No newline at end of file diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 3ab20f3..58cd581 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -4,34 +4,46 @@ use Model\CommentaryModel; use Gateway\CommentaryGateway; use Model\UserModel; use Gateway\UserGateway; - - +use Model\QuoteModel; use Gateway\QuoteGateway; +use Entity\QuestionEntity; +use Gateway\Connection; +use Gateway\QuestionGateway; +use Gateway\QuizGateway; +use Gateway\QuizQuestionGateway; +use Model\QuestionModel; +use Model\QuizModel; +use Model\QuizQuestionModel; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\Error\SyntaxError; +use Twig\Loader\FilesystemLoader; + class UserControler { - private QuoteGateway $quoteGateway; private CommentaryModel $cMod; private UserModel $uMod; + private QuoteModel $qMod; + private QuestionModel $mdl; public function __construct() { global $co; - $this->quoteGateway = new QuoteGateway($co); $this->cMod = new CommentaryModel(new CommentaryGateway($co)); $this->uMod = new UserModel(new UserGateway($co)); + $this->qMod = new QuoteModel(new QuoteGateway($co)); + $this -> mdl = new QuestionModel(new QuestionGateway($co)); } public function profil() { global $vues; + $p = $this->uMod->getUsername($_SESSION["user"]); require_once $vues['profil']; } - public function quiz() { - global $vues; - require_once $vues['quiz']; - } public function addComment(){ @@ -46,8 +58,137 @@ class UserControler { $userId = $this->uMod->getIdByUsername($_SESSION["user"]); - $favorites = $this->quoteGateway->getFavorites($userId); + $favorites = $this->qMod->getFavorites($userId); require_once $vues['favorite']; } + + public function unlog(){ + session_unset(); + session_destroy(); + $_SESSION = array(); + header("Location: /~kekentin/WF/WF-Website/"); + } + + public function quiz(array $args){ + global $vues; + $id=$args['id']; + $nb_questions = $this->getNumberOfQuestion($id); + + $action = $_REQUEST['action'] ?? null; + switch ($action) { + case 'canswer': + if ($this->CorrectAnswer()) + $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1; + $this->continueQuiz($id, $nb_questions); + break; + default: + switch($id) + { + case null: + // page erreur + break; + default: + $_SESSION['score'] = $_SESSION['score'] ?? 0; + $this->showQuestion($id, $_SESSION['no_question'] ?? 0); + break; + } + } + } + + /** + * @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: /~kekentin/WF/WF-Website/quiz/$id_quiz"); + + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function endQuiz(int $id_quiz, int $score) : void + { + global $vues,$co; + + $gw = new QuizGateway($co); + $mdl = new QuizModel($gw); + + if ($mdl->getQuiz($id_quiz + 1)){ + require_once $vues['endQuiz']; + } + require_once $vues['endQuiz']; + } + + public function CorrectAnswer() : bool + { + $answera = $_POST['answera'] ?? null; + $answerb = $_POST['answerb'] ?? null; + $answerc = $_POST['answerc'] ?? null; + $answerd = $_POST['answerd'] ?? null; + + $id= null; + $answer = null; + + if ($answera) { + $answer = explode('-', $answera)[0]; + $id = (int) explode('-', $answera)[1]; + } elseif ($answerb) { + $answer = explode('-', $answerb)[0]; + $id = (int) explode('-', $answerb)[1]; + } elseif ($answerc) { + $answer = explode('-', $answerc)[0]; + $id = (int) explode('-', $answerc)[1]; + } elseif ($answerd) { + $answer = explode('-', $answerd)[0]; + $id = (int) explode('-', $answerd)[1]; + } + + $res = $this->mdl->getQuestion($id); + return $answer == $res->getCanswer(); + } + + public function GetQuestion(int $id): array + { + global $co; + $gw = new QuizQuestionGateway($co); + $mdl = new QuizQuestionModel($gw); + return $mdl->getAllQuestionByQuiz($id, $co); + } + + /** + * @throws RuntimeError + * @throws SyntaxError + * @throws LoaderError + */ + public function showQuestion(int $id, int $num) : void + { + global $vues; + $q = $this->GetQuestion($id); + $question = $q[$num] ?? $q[0]; + $idquestion = $question->getIdQuestion(); + require_once $vues['quiz']; + + //echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); + } + + + public function getNumberOfQuestion(int $id) : int + { + global $co; + $gw = new QuizGateway($co); + $mdl = new QuizModel($gw); + return $mdl->getQuiz($id)->getNbQuestions(); + } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 3cc128b..22a8191 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -12,13 +12,11 @@ use Model\UserModel; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; -use Gateway\AccueilGateway; Class VisitorControler { private QuoteModel $qMod; private CommentaryModel $cMod; - private AccueilGateway $accueilGateway; private SearchModel $sMod; @@ -38,8 +36,6 @@ Class VisitorControler { $this->qMod = new QuoteModel(new QuoteGateway($co)); $this->cMod = new CommentaryModel(new CommentaryGateway($co)); $this->sMod = new SearchModel(new QuoteGateway($co)); - - $this->accueilGateway = new AccueilGateway($co); $this->gw = new UserGateway($co); $this->mdl = new UserModel($this->gw); } @@ -48,8 +44,8 @@ Class VisitorControler { global $vues; // Récupérer la citation du jour via AccueilGateway - $citationDuJour = $this->accueilGateway->getQuoteOfTheDay('fr'); - $suggestions = $this->accueilGateway->getSuggestions(0, 'fr'); + $citationDuJour = $this->qMod->getQuoteOfTheDay('fr'); + $suggestions = $this->qMod->getSuggest(0, 'fr'); // Passer les données à la vue require_once $vues['accueil']; diff --git a/src/Entity/UserEntity.php b/src/Entity/UserEntity.php new file mode 100644 index 0000000..5530463 --- /dev/null +++ b/src/Entity/UserEntity.php @@ -0,0 +1,156 @@ +id; + } + + public function setId(int $id): void + { + $this->id = $id; + } + + public function getPseudo(): string + { + return $this->pseudo; + } + + public function setPseudo(string $pseudo): void + { + $this->pseudo = $pseudo; + } + + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): void + { + $this->password = $password; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setEmail(string $email): void + { + $this->email = $email; + } + + public function getDate(): string + { + return $this->date; + } + + public function setDate(string $date): void + { + $this->date = $date; + } + + public function isAdmin(): bool + { + return $this->isAdmin; + } + + public function setIsAdmin(bool $isAdmin): void + { + $this->isAdmin = $isAdmin; + } + + public function getImgPrfl(): string + { + return $this->imgPrfl; + } + + public function setImgPrfl(string $imgPrfl): void + { + $this->imgPrfl = $imgPrfl; + } + + /** + * @param int $id + * @param string $pseudo + * @param string $password + * @param string $email + * @param int $imgPrfl + * @param bool $isAdmin + * @param string $date + */ + public function __construct(int $id, string $pseudo, string $password, string $email, string $imgPrfl, string $date) + { + $this->id = $id; + $this->pseudo = $pseudo; + $this->password = $password; + $this->email = $email; + $this->imgPrfl = $imgPrfl; + $this->date = $date; + } + + + } + // ============================================ En attente du Model ============================================ + /*$dsn = "pgsql:host=londres;dbname=dblebeaulato"; + $username = "lebeaulato"; + $password = ""; + + $con = new Connection($dsn,$username,$password); + + $query = 'SELECT * FROM Users WHERE id_user=:idUser'; + $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR))); + $result = $con->getResults(); + + $u = new User($result[0]['id_user'],$result[0]['username'], $result[0]['pssword'], '../images/imageProfil.png', $result[0]['email']); + + + + + //UPDATE username User + $query = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser'; + $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newUsername'=> array('Hello', PDO::PARAM_STR))); + $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser'; + + $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR))); + $result = $con->getResults(); + $u->setUsername($result[0]['username']); + + + //UPDATE email User + $query = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser'; + $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newEmail'=> array('hello@gmail.com', PDO::PARAM_STR))); + $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser'; + + $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR))); + $result = $con->getResults(); + $u->setEmail($result[0]['email']); + + //UPDATE passwd User + $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser'; + $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newPassWd'=> array('TestMotDePasssse', PDO::PARAM_STR))); + + $queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser'; + $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR))); + $result = $con->getResults(); + $u->setPasswd($result[0]['pssword']); /*Test*/ + +// ================================================================================================================ + + + + function hidenPassWd(string $passwd){ + if(strlen($passwd) >= 16) return str_repeat('*', 16); + return str_repeat('*', strlen($passwd)); + } +?> diff --git a/src/Entity/questionEntity.php b/src/Entity/questionEntity.php deleted file mode 100644 index c3cb082..0000000 --- a/src/Entity/questionEntity.php +++ /dev/null @@ -1,148 +0,0 @@ -id_question = $id_question; - $this->question = $question; - $this->answerA = $answerA; - $this->answerB = $answerB; - $this->answerC = $answerC; - $this->answerD = $answerD; - $this->cAnswer = $cAnswer; - } - - /** - * @return int - */ - public function getIdQuestion(): int - { - return $this->id_question; - } - - /** - * @param int $id_question - */ - public function setIdQuestion(int $id_question): void - { - $this->id_question = $id_question; - } - - /** - * @return string - */ - public function getQuestion(): string - { - return $this->question; - } - - /** - * @param string $question - */ - public function setQuestion(string $question): void - { - $this->question = $question; - } - - /** - * @return string - */ - public function getAnswerA(): string - { - return $this->answerA; - } - - /** - * @param string $answerA - */ - public function setAnswerA(string $answerA): void - { - $this->answerA = $answerA; - } - - /** - * @return string - */ - public function getAnswerB(): string - { - return $this->answerB; - } - - /** - * @param string $answerB - */ - public function setAnswerB(string $answerB): void - { - $this->answerB = $answerB; - } - - /** - * @return string - */ - public function getAnswerC(): string - { - return $this->answerC; - } - - /** - * @param string $answerC - */ - public function setAnswerC(string $answerC): void - { - $this->answerC = $answerC; - } - - /** - * @return string - */ - public function getAnswerD(): string - { - return $this->answerD; - } - - /** - * @param string $answerD - */ - public function setAnswerD(string $answerD): void - { - $this->answerD = $answerD; - } - - /** - * @return string - */ - public function getCAnswer(): string - { - return $this->cAnswer; - } - - /** - * @param string $cAnswer - */ - public function setCAnswer(string $cAnswer): void - { - $this->cAnswer = $cAnswer; - } - - - - } diff --git a/src/Gateway/AccueilGateway.php b/src/Gateway/AccueilGateway.php index e9699f4..03e684c 100644 --- a/src/Gateway/AccueilGateway.php +++ b/src/Gateway/AccueilGateway.php @@ -11,39 +11,5 @@ class AccueilGateway { $this->con = $con; } - public function getQuoteOfTheDay(string $language): array { - $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue - FROM Quote q - JOIN Caracter c ON c.id_caracter = q.id_caracter - JOIN Source s ON s.id_source = q.id_source - JOIN Image i ON c.id_img = i.id_img - WHERE q.isValide = true AND q.isCitationDuJour = true AND q.langue = :language - ORDER BY id_quote DESC LIMIT 1;"; - try { - $this->con->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]); - $result = $this->con->getResults(); - return $result[0] ?? []; - } catch (PDOException $e) { - echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage(); - return []; - } - } - - public function getSuggestions(int $numpage, string $language): array { - $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue - FROM Quote q - JOIN Caracter c ON c.id_caracter = q.id_caracter - JOIN Source s ON s.id_source = q.id_source - JOIN Image i ON c.id_img = i.id_img - WHERE q.isValide = true AND q.langue = :language - ORDER BY RANDOM() - LIMIT 20 OFFSET :offset;"; - - $this->con->executeQuery($query, [ - ':language' => [$language, PDO::PARAM_STR], - ':offset' => [$numpage * 20, PDO::PARAM_INT] - ]); - return $this->con->getResults(); - } } diff --git a/src/Gateway/QuizQuestionGateway.php b/src/Gateway/QuizQuestionGateway.php index 35a521f..ebed811 100644 --- a/src/Gateway/QuizQuestionGateway.php +++ b/src/Gateway/QuizQuestionGateway.php @@ -15,7 +15,7 @@ class QuizQuestionGateway public function createQuizQuestionGateway(int $idQuiz, int $idQuestion): bool { $query = " - INSERT INTO QuizQuestions + INSERT INTO Quiz_Question VALUES (:id_quiz, :id_question) "; @@ -28,8 +28,8 @@ class QuizQuestionGateway public function findQuizQuestionById(int $idQuiz, int $idQuestion) : array { $query = " - SELECT * FROM QuizQuestions - WHERE quiz_qq = :id_quiz AND question_qq = :id_question + SELECT * FROM Quiz_Question + WHERE quiz = :id_quiz AND question_qq = :id_question "; $this -> co -> executeQuery($query, [ @@ -43,8 +43,8 @@ class QuizQuestionGateway public function findQuestionsFromQuiz(int $idQuiz) : array { $query = " - SELECT * FROM QuizQuestions - WHERE quiz_qq = :id_quiz + SELECT * FROM Quiz_Question + WHERE quiz = :id_quiz "; $this -> co -> executeQuery($query, ['id_quiz' => array($idQuiz, PDO::PARAM_INT)]); @@ -55,8 +55,8 @@ class QuizQuestionGateway public function deleteQuizQuestionGateway(int $idQuiz, int $idQuestion) : bool { $query = " - DELETE FROM QuizQuestions - WHERE quiz_qq = :id_quiz AND question_qq = :id_question + DELETE FROM Quiz_Question + WHERE quiz = :id_quiz AND question_qq = :id_question "; return $this -> co -> executeQuery($query, [ diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php index b5b4c97..f04318a 100644 --- a/src/Gateway/QuoteGateway.php +++ b/src/Gateway/QuoteGateway.php @@ -72,6 +72,62 @@ Class QuoteGateway{ return $result; } + public function getQuoteOfTheDay(string $language): array { + $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue + FROM Quote q + JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Source s ON s.id_source = q.id_source + JOIN Image i ON c.id_img = i.id_img + WHERE q.isValide = true AND q.isCitationDuJour = true AND q.langue = :language + ORDER BY id_quote DESC LIMIT 1;"; + try { + $this->con->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]); + $result = $this->con->getResults(); + return $result[0] ?? []; + } catch (PDOException $e) { + echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage(); + return []; + } + } + + + public function getSuggestions(int $numpage, string $language): array { + $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue + FROM Quote q + JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Source s ON s.id_source = q.id_source + JOIN Image i ON c.id_img = i.id_img + WHERE q.isValide = true AND q.langue = :language + ORDER BY RANDOM() + LIMIT 20 OFFSET :offset;"; + + $this->con->executeQuery($query, [ + ':language' => [$language, PDO::PARAM_STR], + ':offset' => [$numpage * 20, PDO::PARAM_INT] + ]); + return $this->con->getResults(); + } + + public function getFavorites(string $userId): array { + $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue + FROM Favorite f + JOIN Quote q ON f.quote = q.id_quote + JOIN Caracter c ON c.id_caracter = q.id_caracter + JOIN Source s ON s.id_source = q.id_source + JOIN Image i ON c.id_img = i.id_img + WHERE f.users = :userId"; + + try { + $this->con->executeQuery($query, [ + ':userId' => [$userId, PDO::PARAM_STR] + ]); + return $this->con->getResults(); + } catch (PDOException $e) { + echo "Erreur dans getFavorites: " . $e->getMessage(); + return []; + } + } + //======================== PARTI ADMIN ======================== //Probablement à déplacer dans un autre fichier @@ -154,28 +210,6 @@ Class QuoteGateway{ $result = $con->getResults(); return $result; } - - public function getFavorites(string $userId): array { - $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue - FROM Favorite f - JOIN Quote q ON f.quote = q.id_quote - JOIN Caracter c ON c.id_caracter = q.id_caracter - JOIN Source s ON s.id_source = q.id_source - JOIN Image i ON c.id_img = i.id_img - WHERE f.users = :userId"; - - try { - $this->con->executeQuery($query, [ - ':userId' => [$userId, PDO::PARAM_STR] - ]); - return $this->con->getResults(); - } catch (PDOException $e) { - echo "Erreur dans getFavorites: " . $e->getMessage(); - return []; - } - } - - } ?> \ No newline at end of file diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index c7a2c8f..9074f22 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -74,7 +74,7 @@ Class UserGateway{ // obtenir les informations d'un user selon son pseudo public function findUsername(string $username):array{ - $query = 'SELECT * FROM Users WHERE username= :username'; + $query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users u Join Image i on i.id_img=u.img WHERE username= :username'; $this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); return $this->con->getResults(); } diff --git a/src/Gateway/favoritsGateway.php b/src/Gateway/favoritsGateway.php deleted file mode 100644 index 4c8fa99..0000000 --- a/src/Gateway/favoritsGateway.php +++ /dev/null @@ -1,15 +0,0 @@ -con = $con; - } - - -} diff --git a/src/Model/QuestionModel.php b/src/Model/QuestionModel.php index 4aa134c..c58a186 100644 --- a/src/Model/QuestionModel.php +++ b/src/Model/QuestionModel.php @@ -25,7 +25,7 @@ class QuestionModel if ($q) return new QuestionEntity( $q[0]['id_question'], - $q[0]['question'], + $q[0]['texte'], $q[0]['answera'], $q[0]['answerb'], $q[0]['answerc'], diff --git a/src/Model/QuoteModel.php b/src/Model/QuoteModel.php index 2bcaea4..b924b6f 100644 --- a/src/Model/QuoteModel.php +++ b/src/Model/QuoteModel.php @@ -18,6 +18,34 @@ else return new Quote($res[0]["id_quote"],$res[0]["content"],$res[0]["caracter"],$res[0]["imgpath"],$res[0]["title"],$res[0]["dates"],$res[0]["likes"],$res[0]["langue"]); } + + public function getSuggest(int $numpage, string $language):array{ + $res = $this->gateway->getSuggestions($numpage,$language); + $tabQ=[]; + + foreach($res as $q ){ + $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"]) ; + } + return $tabQ; + } + + public function getQuoteOfTheDay(string $language):Quote{ + $res = $this->gateway->getQuoteOfTheDay($language); + if( count($res) == 0) + return new Quote(-1,"NULL","NULL","NULL","NULL","NULL",0,"Default"); + else + return new Quote($res["id_quote"],$res["content"],$res["caracter"],$res["imgpath"],$res["title"],$res["dates"],$res["likes"],$res["langue"]) ; + } + + public function getFavorites(string $userId): array { + $res = $this->gateway->getFavorites($userId); + $tabQ=[]; + + foreach($res as $q ){ + $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"]) ; + } + return $tabQ; + } } ?> diff --git a/src/Model/SearchModel.php b/src/Model/SearchModel.php index 40f3578..4a81b17 100644 --- a/src/Model/SearchModel.php +++ b/src/Model/SearchModel.php @@ -22,5 +22,4 @@ return $tabQ; } } - ?> diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index f82fc7f..c7f2040 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -59,7 +59,7 @@ $res[0]['username'], $res[0]['password'], $res[0]['email'], - $res[0]['img'], + $res[0]['imgpath'], $res[0]['creation'] ); return null; diff --git a/vue/accueil.php b/vue/accueil.php index f76183f..469c395 100644 --- a/vue/accueil.php +++ b/vue/accueil.php @@ -15,12 +15,12 @@ echo $twig->render('bandeau.html.twig'); // Vérification de la présence de la "Citation du jour" if (!empty($citationDuJour)) { echo $twig->render('citation_du_jour.html.twig', [ - 'quote' => $citationDuJour['content'], - 'movie' => $citationDuJour['title'], - 'character' => $citationDuJour['caracter'], - 'year' => $citationDuJour['dates'], - 'imagePath' => $citationDuJour['imgpath'], - 'id' => $citationDuJour['id_quote'], + 'quote' => $citationDuJour->getContent(), + 'movie' => $citationDuJour->getTitleSrc(), + 'character' => $citationDuJour->getCarac(), + 'year' => $citationDuJour->getDateSrc(), + 'imagePath' => $citationDuJour->getImgPath(), + 'id' => $citationDuJour->getId(), ]); } else { echo "

Aucune citation du jour n'a été trouvée.

"; @@ -28,7 +28,7 @@ if (!empty($citationDuJour)) { // Affichage des suggestions de citations -echo $twig->render('quote.html.twig', [ +echo $twig->render('quoteLittle.html.twig', [ 'quotes' => $suggestions, 'titre' => "Suggestions" ]); diff --git a/vue/endQuiz.php b/vue/endQuiz.php new file mode 100644 index 0000000..7a70e27 --- /dev/null +++ b/vue/endQuiz.php @@ -0,0 +1,18 @@ +render('head.html.twig', [ + 'title' => "Quiz", + 'style' => "public/styles/styleQuiz.css", + 'scripts' => array("public/script/theme-toggle.js") +]); + + +// Rendu du bandeau +echo $twig->render('bandeau.html.twig'); + +echo $twig->render('endQuiz.html.twig', ['score' => $score, 'nextquiz' => $id_quiz + 1]) +?> + + diff --git a/vue/favorits.php b/vue/favorits.php index 777f424..61ad807 100644 --- a/vue/favorits.php +++ b/vue/favorits.php @@ -9,7 +9,7 @@ echo $twig->render('head.html.twig', [ echo $twig->render('bandeau.html.twig'); -echo $twig->render('quote.html.twig', [ +echo $twig->render('quoteLittle.html.twig', [ 'quotes' => $favorites, 'titre' => "Favoris" ]); diff --git a/vue/profil.php b/vue/profil.php index 78e24f8..5dffffb 100644 --- a/vue/profil.php +++ b/vue/profil.php @@ -3,7 +3,7 @@ echo $twig->render('head.html.twig', [ - 'title' => "Accueil", + 'title' => "Profil", 'style' => "public/styles/styleProfil.css", 'scripts' => array("public/script/theme-toggle.js") ]); @@ -13,9 +13,8 @@ echo $twig->render('bandeau.html.twig'); echo $twig->render('profil.html.twig', array( - 'srcUsername' => "Test User", - 'srcEmail' => "test@gmail.com", - 'srcPasswd' => "*****", - 'srcImg' => "images/imageProfil.png", + 'srcUsername' => $p->getPseudo(), + 'srcEmail' => $p->getEmail(), + 'srcImg' => $p->getImgPrfl(), )); ?> \ No newline at end of file diff --git a/vue/quiz.html b/vue/quiz.html deleted file mode 100644 index 0274419..0000000 --- a/vue/quiz.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - Wiki Fantasy : Quiz - - - - - - -
- - -
- user -
-
- -

▶ Quiz ◀

- -
-

Question 1

-

“Tu es un sorcier Harry”

- - -
- - - - -
- -
- -
-
- - diff --git a/vue/quiz.php b/vue/quiz.php new file mode 100644 index 0000000..cb0514c --- /dev/null +++ b/vue/quiz.php @@ -0,0 +1,17 @@ +render('head.html.twig', [ + 'title' => "Quiz", + 'style' => "../public/styles/styleQuiz.css", + 'scripts' => array("../public/script/theme-toggle-double-param.js") +]); + + +// Rendu du bandeau +echo $twig->render('bandeau.html.twig'); + +echo $twig->render('quiz.html.twig', ['idQuiz'=>$id , 'question' => $question,'id'=>$idquestion]); +?> + diff --git a/vue/quizz.html b/vue/quizz.html deleted file mode 100644 index ae2f1d3..0000000 --- a/vue/quizz.html +++ /dev/null @@ -1,211 +0,0 @@ - - - - - - - - Wiki Fantasy : Quizz - - - - - - - -
-
- - -
- user -
-
-
- - -

▶ Quizz ◀

- -
-

Question 1

-

“Tu es un sorcier Harry”

- - -
- - - - -
- -
- -
-
- - - - - diff --git a/vue/search.php b/vue/search.php index 22732e9..8d73c70 100644 --- a/vue/search.php +++ b/vue/search.php @@ -15,18 +15,10 @@ )); - echo "

Résultats

"; - echo "
"; - foreach($tq as $q){ - - echo $twig->render('quoteLittle.html.twig', array( - 'srcImg' => $q->getImgPath(), - 'quoteContent' => $q->getContent(), - 'sourceName' => $q->getTitleSrc(), - 'nameCarac' => $q->getCarac(), - 'dateSortie' => $q->getDateSrc(), - )); - } + echo $twig->render('quoteLittle.html.twig', [ + 'quotes' => $tq, + 'titre' => "Résultats" + ]); echo "
"; //echo $twig->render('resultat.html.twig'); diff --git a/vue/templates/bandeau.html.twig b/vue/templates/bandeau.html.twig index 4bb49d8..9849c2f 100644 --- a/vue/templates/bandeau.html.twig +++ b/vue/templates/bandeau.html.twig @@ -2,7 +2,7 @@