diff --git a/config/config.php b/config/config.php index 18ac15c..d25d503 100644 --- a/config/config.php +++ b/config/config.php @@ -13,10 +13,11 @@ $login = ''; $mdp = ''; +//$racine='/~kemondejar/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website +$racine='/~kekentin/WF/WF-Website'; -$racine='/~kekentin/WF/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website -//$racine='/WF-Website'; - +//$repImg='/home/UCA/kemondejar/public_html/WF-Website/public/images/'; +$repImg='/'; @@ -33,6 +34,11 @@ $vues['create'] = 'vue/create.php'; $vues['quiz'] = 'vue/quiz.php'; $vues['endQuiz'] = 'vue/endQuiz.php'; $vues['submitQuote'] = 'vue/submitQuote.php'; +$vues['recap'] = 'vue/recap.php'; +$vues['accueilQuiz'] = 'vue/accueilQuiz.php'; +$vues['quizRandom'] = 'vue/quizRandom.php'; +$vues['endQuizRandom'] = 'vue/endQuizRandom.php'; + //Style css diff --git a/images/WIKIFANTASY.png b/images/WIKIFANTASY.png index 2dffdee..719e2e8 100644 Binary files a/images/WIKIFANTASY.png and b/images/WIKIFANTASY.png differ diff --git a/images/chaos.png b/images/chaos.png new file mode 100644 index 0000000..d54d38f Binary files /dev/null and b/images/chaos.png differ diff --git a/images/cool-background.png b/images/cool-background.png new file mode 100644 index 0000000..889e97b Binary files /dev/null and b/images/cool-background.png differ diff --git a/images/iconeClaire copy.ico b/images/iconeClaire copy.ico new file mode 100644 index 0000000..4248279 Binary files /dev/null and b/images/iconeClaire copy.ico differ diff --git a/images/iconeClaire.ico b/images/iconeClaire.ico deleted file mode 100644 index 87a6e54..0000000 Binary files a/images/iconeClaire.ico and /dev/null differ diff --git a/index.php b/index.php index 3bc9649..a4837a8 100644 --- a/index.php +++ b/index.php @@ -15,7 +15,7 @@ if(!isset($_SESSION['theme'])){ require_once __DIR__ . '/config/config.php'; require __DIR__ . '/vendor/autoload.php'; -//$co = new \Gateway\Connection('pgsql:host=localhost;dbname=wikifantasy3;', 'postgres', 'postgres'); +//$co = new \Gateway\Connection('pgsql:host=localhost;dbname=wikifantasy3;', 'postgres', 'sucepute'); $co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd'); //twig diff --git a/public/images/iconeClaire.ico b/public/images/iconeClaire.ico index 87a6e54..4248279 100644 Binary files a/public/images/iconeClaire.ico and b/public/images/iconeClaire.ico differ diff --git a/public/styles/style.css b/public/styles/style.css index 76d9ab8..63472e3 100644 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -1,25 +1,31 @@ /* @import url('https://fonts.googleapis.com/css2?family=Lemon&display=swap'); */ @import url(./styleScroll.css); +@import url('https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Roboto+Condensed:ital,wght@0,100..900;1,100..900&family=Roboto:ital,wght@0,100..900;1,100..900&display=swap'); :root { --main-dark-background-color: #120B1D; --main-dark-text-color : #ffffff; --main-dark-gradient : linear-gradient(45deg, #4a148c, #7b1fa2); --main-dark-other-color : #000000; - --main-light-background-color: #cccccc; - /*--main-light-background-color: #ffffff;*/ - --main-light-text-color : #000; - --main-light-gradient : linear-gradient(90deg, #46BE73, #BAEBF6); - /*--main-light-gradient : linear-gradient(-90deg, #f3e0f7, #dd9aff);*/ - /*--main-light-gradient : linear-gradient(45deg, #73CFF6, #DE95CA);*/ + --main-light-background-color: #ffffff; + --main-light-text-color : #000000; + /*--main-light-gradient : linear-gradient(90deg, #46BE73, #BAEBF6);*/ + /*--main-light-gradient : linear-gradient(90deg, #AAB9CF, #BDD4E7);*/ + --main-light-gradient : #84e4a9; --main-light-other-color : #46BE73; - /*--main-light-other-color : #f8eaff;*/ - /*--main-light-other-color : #d2d2d8;*/ + /* --main-light-gradient : #94d3ac; + --main-light-other-color : #75b48d; */ } + +*{ + font-family: "roboto condensed", sans-serif; + font-weight: 600; +} + /* Général */ body{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; margin : 0%; } @@ -62,7 +68,7 @@ body.dark-mode .header{ /* Light mode */ body.light-mode{ - background-color: var(--main-light-background-color); + background-image: url("../../images/chaos.png"); color: var(--main-light-text-color); } @@ -96,7 +102,7 @@ body.light-mode .header img{ } .light-mode .theme-icon:hover, .light-mode .nav a:hover { - filter: brightness(0) saturate(100%) invert(84%) sepia(88%) saturate(6613%) hue-rotate(276deg) brightness(89%) contrast(95%); + filter: brightness(0) saturate(100%) invert(100%) sepia(0%) saturate(0%) hue-rotate(271deg) brightness(103%) contrast(101%); } /* écran par défaut */ @@ -171,6 +177,18 @@ body{ height : 7vh; } +.error{ + display:block; + margin-top: 30vh; + text-align: center; + font-size: 5em; +} + +.explanation{ + text-align: center; + font-size: 3em; +} + /* écran tablette*/ @media (max-width: 834px) or (max-aspect-ratio : 1/1){ diff --git a/public/styles/styleAccueilQuiz.css b/public/styles/styleAccueilQuiz.css new file mode 100644 index 0000000..e1fdb96 --- /dev/null +++ b/public/styles/styleAccueilQuiz.css @@ -0,0 +1,76 @@ +@import url(./style.css); /* Import de style.css */ + +h2{ + text-align: center; + font-size: 2em; + padding-top: 15px; + font-weight: bolder; +} + +h3{ + text-align: center; + margin-left: 15px; + margin-right: 15px; + margin-top: -5px; + text-decoration: none; +} + +a{ + text-decoration: none; +} + +.linkQuiz img{ + width: 14vw; + height: 22vh; + object-fit: cover; + border-radius: 10px 10px 0px 0px; + margin : 10px; +} + +.quizCard{ + text-align: center; + border-radius: 15px; + box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2); +} + +.quiz-container{ + margin-left: auto; + margin-right: auto; + display: flex; + justify-content: start; + align-items: self-start; + gap: 2vw; + margin-top: 2em; + min-height: 68vh; + width: 95vw; + padding: 15px; + border-radius: 15px; +} + +/* Dark mode */ + +.dark-mode h3 { + color: white; +} + +.dark-mode .quizCard { + background: var(--main-dark-gradient); +} + +.dark-mode .quiz-container { + background: black; +} + +/* Light mode */ + +.light-mode h3 { + color: black; +} + +.light-mode .quizCard { + background: var(--main-light-gradient); +} + +.light-mode .quiz-container { + background: #46BE73; +} \ No newline at end of file diff --git a/public/styles/styleEndQuiz.css b/public/styles/styleEndQuiz.css index b1de2e1..c504692 100644 --- a/public/styles/styleEndQuiz.css +++ b/public/styles/styleEndQuiz.css @@ -27,7 +27,7 @@ body.light-mode .resultat { /* ====== ECRAN DEFAUT ====== */ h1 { - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; text-align: center; } diff --git a/public/styles/styleLogin.css b/public/styles/styleLogin.css index b950a71..cb91fd4 100644 --- a/public/styles/styleLogin.css +++ b/public/styles/styleLogin.css @@ -61,7 +61,7 @@ body.light-mode a{ } h1{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; text-align: center; font-size: 32px; margin-top: 10%; @@ -71,7 +71,7 @@ p{ margin-top: 6%; margin-bottom: 2%; font-size: 20px; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } .login{ @@ -88,11 +88,11 @@ p{ font-size: 1em; text-align: center; padding-top: 1%; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } .buttonSudmite{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; border: none; padding: 2%; border-radius: 25px; diff --git a/public/styles/styleProfil.css b/public/styles/styleProfil.css index 7fb4e17..2862661 100644 --- a/public/styles/styleProfil.css +++ b/public/styles/styleProfil.css @@ -34,7 +34,7 @@ body.dark-mode .imgModify{ body.light-mode .inputPasswd{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; margin-top: 2%; color: black; } @@ -77,7 +77,7 @@ body.light-mode .login{ body.light-mode .inputPasswd{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; margin-top: 2%; color: black; } @@ -90,7 +90,7 @@ body.light-mode .saveButtonPasswd { /* ====== ECRAN DEFAUT ====== */ h1{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; text-align: center; font-size: 35px; } @@ -99,7 +99,7 @@ p{ margin-top: 4%; margin-bottom: 2%; font-size: 20px; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } ::backdrop { @@ -110,12 +110,15 @@ p{ height: 60%; font-size: 15px; text-align: center; +<<<<<<< HEAD justify-content: start; align-items: flex-start; font-family: "Lemon", serif; +======= + font-family: "roboto condensed", sans-serif; +>>>>>>> 3403a5592cdba73a03915da872f39aba764534a6 display: flex; flex-wrap: wrap; - border: 15px solid; border-radius: 20px; } @@ -134,7 +137,7 @@ p{ } .buttonSudmite{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; border: none; padding: 2%; border-radius: 25px; @@ -148,7 +151,7 @@ p{ font-size: 15px; text-align: center; padding-top: 1%; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } .login{ @@ -174,7 +177,7 @@ p{ border-radius: 25px; border: none; font-size: 15px; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } diff --git a/public/styles/styleQuiz.css b/public/styles/styleQuiz.css index 8b837e3..6a50a68 100644 --- a/public/styles/styleQuiz.css +++ b/public/styles/styleQuiz.css @@ -22,7 +22,7 @@ body.dark-mode .submit-button { body.dark-mode .buttonSudmite { background: linear-gradient(90deg, #6100ff 0%, #1b0048 100%); - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; border: none; color: white; padding: 10px 20px; @@ -50,7 +50,7 @@ body.light-mode .answer { /* ====== ECRAN DEFAUT ====== */ h1, h2, p { - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; text-align: center; } diff --git a/public/styles/styleQuote.css b/public/styles/styleQuote.css index cdb801c..d1ad16e 100644 --- a/public/styles/styleQuote.css +++ b/public/styles/styleQuote.css @@ -160,7 +160,7 @@ body.light-mode .like-icon-none img { background-color: #fff; color: black; display: flex; - font-family: "Lemon", sans-serif; + font-family: "roboto condensed", sans-serif; flex-direction: column; margin-bottom: 1vh; border-radius: 20px; diff --git a/public/styles/styleQuoteLittle.css b/public/styles/styleQuoteLittle.css index e285d3f..7a0bd81 100644 --- a/public/styles/styleQuoteLittle.css +++ b/public/styles/styleQuoteLittle.css @@ -37,6 +37,7 @@ a.link-citation:hover { justify-content: space-around; width: 100%; margin: 0 auto; + font-size: medium; } a.link-citation { diff --git a/public/styles/styleQuoteLittleV1.css b/public/styles/styleQuoteLittleV1.css deleted file mode 100644 index 24c3221..0000000 --- a/public/styles/styleQuoteLittleV1.css +++ /dev/null @@ -1,120 +0,0 @@ -/* Conteneur pour les suggestions en deux colonnes */ -.suggestions-container { - display: flex; - flex-wrap: wrap; - justify-content: space-around; - width: 100%; - margin: 0 auto; -} - - - -a.link-citation { - text-decoration: none; - color: white; - width: 47.5%; - height: 100%; -} - -/* Citations */ -.citation-container { - background: linear-gradient(to right, #4a148c, #7b1fa2); - border-radius: 12px; - color: white; - display: flex; - width: 100%; - align-items: flex-start; - box-sizing: border-box; - padding: 0; - height: 150px; - overflow: hidden; - margin-bottom: 20px; - word-wrap: break-word; /* Permet de couper les mots trop longs */ - word-break: break-word; -} - -/* Fixe la taille pour s'assurer que toutes les citations restent cohérentes */ -.citation-container .text-content { - flex-grow: 1; - display: flex; - flex-direction: column; - justify-content: center; - height: 150px; -} - -.quote { - padding: 0; - overflow: hidden; -} - -.citation-image { - width: 150px; - height: 100%; - object-fit: cover; - margin: 0; - border-radius: 0; -} - -.text-content { - flex: 1; - padding: 10px; - display: flex; - flex-direction: column; - justify-content: center; /* Centre verticalement le texte */ - word-wrap: break-word; /* Permet de couper les mots trop longs */ - word-break: break-word; -} - -.quoteContent { - font-size: 1.2em; - margin-bottom: 10px; - font-style: italic; -} - - - -.citation .movie, .character, .year { - margin-bottom: 5px; -} - -/* Mode sombre */ -body.dark-mode .quote { - background: linear-gradient(45deg, #4a148c, #7b1fa2); - color:white; -} - -/* Mode clair */ -body.light-mode .quote { - background-image: linear-gradient(-28deg, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%); - color:black; /* Changer le texte en noir pour le mode clair */ -} - -body.light-mode .citation, -body.light-mode .movie, -body.light-mode .character, -body.light-mode .year { - color: black; /* Forcer le texte en noir pour le mode clair */ -} - -/* Responsive design */ -@media (max-width: 768px) { - .suggestions-container { - flex-direction: column; - width: 100%; - } - - .citation-container { - width: 100%; /* Chaque citation prend toute la largeur sur mobile */ - max-width: 100%; - height: 100px; /* Supprimer la hauteur fixe sur mobile */ - } - - .citation-image { - width: 100px; - height: 100px; - } - - .quote { - font-size: 1em; - } -} diff --git a/public/styles/styleSearch.css b/public/styles/styleSearch.css index 60c16ce..a142b5d 100644 --- a/public/styles/styleSearch.css +++ b/public/styles/styleSearch.css @@ -117,6 +117,13 @@ body.dark-mode .filtre label { body.light-mode .search-container { background: #ccc; } + +.light-mode form { + background-color: #fff; + margin-top: -30px; + padding-top: 35px; +} + body.light-mode .search-container input[type="search"] { color: #000; } diff --git a/public/styles/styleSignin.css b/public/styles/styleSignin.css index 1fc6221..4d0ef16 100644 --- a/public/styles/styleSignin.css +++ b/public/styles/styleSignin.css @@ -50,7 +50,7 @@ body.light-mode a{ /* ====== ECRAN DEFAULT ====== */ h1{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; text-align: center; font-size: 32px; margin-top: 10%; @@ -68,7 +68,7 @@ p{ margin-top: 4%; margin-bottom: 2%; font-size: 20px; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } .confirmer{ @@ -87,7 +87,7 @@ p{ } .btn{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; border: none; padding: 2%; border-radius: 25px; @@ -101,7 +101,7 @@ p{ font-size: 1em; text-align: center; padding-top: 1%; - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; } .createAccount{ diff --git a/public/styles/styleSubmitQuote.css b/public/styles/styleSubmitQuote.css index b99085b..1686902 100644 --- a/public/styles/styleSubmitQuote.css +++ b/public/styles/styleSubmitQuote.css @@ -25,7 +25,7 @@ body.light-mode #box{ /* ====== ECRAN DEFAULT ====== */ h1, h2{ - font-family: "Lemon", serif; + font-family: "roboto condensed", sans-serif; text-align: center; } diff --git a/public/styles/styleV1.css b/public/styles/styleV1.css deleted file mode 100644 index 9276d19..0000000 --- a/public/styles/styleV1.css +++ /dev/null @@ -1,108 +0,0 @@ -/* header.css */ - -/* Styles généraux */ -* { - margin: 0; - padding: 0; - box-sizing: border-box; -} - -body { - background-color: #120b1d; - font-family: "Lemon", serif; - margin-top: 200px; -} - -/* Header */ -.header { - display: flex; - position: fixed; - background-color: #000000; - right: 0; - top: 0; - width: 100%; - text-align: center; - padding: 20px; -} - -.nav { - display: flex; - align-items: center; - vertical-align: center; - gap: 30px; - width: 40%; -} - -.logo { - display: flex; - align-items: center; - justify-content: center; - width: 20%; -} - -.user { - display: flex; - flex-direction: row; - justify-content: flex-end; - align-items: center; - vertical-align: center; - gap: 30px; - width: 40%; -} - -.search { - display: flex; - flex-direction: row; - justify-content: center; - align-items: center; - vertical-align: center; - margin: 10px; - width: 70px; - height: 70px; - border-radius: 50%; -} - - -/* Mode sombre */ -body.dark-mode { - background-color: #120B1D; - color: #ffffff; -} - -body.dark-mode .header { - background-color: #000; -} - -body.dark-mode .header img { - filter: invert(0%); -} - -body.dark-mode .nav img:hover { - filter: invert(59%) sepia(96%) saturate(6733%) hue-rotate(275deg) brightness(112%) contrast(122%); -} - -body.dark-mode .search { - background: white; -} - -/* Mode clair */ -body.light-mode { - background-color: #ffffff; - color: #000000; -} - -body.light-mode .header { - background-color: #F4F1DE; -} - -body.light-mode .header img { - filter: invert(100%); -} - -body.light-mode .nav img:hover { - filter: invert(22%) sepia(6%) saturate(2269%) hue-rotate(193deg) brightness(98%) contrast(106%); -} - -body.light-mode .search { - background: black; -} diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index 2ec4320..aca86f5 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -16,7 +16,7 @@ Class FrontControler{ global $twig,$racine; $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), - 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add','deleteAccount'), + 'user' => array('quiz','randomQuiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add', 'accueilQuiz', 'deleteAccount'), 'admin' => array('null')]; $dVueEreur = []; @@ -52,16 +52,20 @@ Class FrontControler{ $router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav'); $router->map('GET|POST', '/changedata', 'UserControler','changedata'); $router->map('GET|POST', '/submit', 'UserControler', 'submit'); - $router->map('GET|POST', '/validsubmit', 'UserControler', 'validsubmit'); + $router->map('GET|POST', '/validsubmit', 'UserControler','validsubmit'); $router->map('GET|POST', '/add', 'UserControler', 'add'); + $router->map('GET|POST', '/accueilQuiz', 'UserControler', 'accueilQuiz'); + $router->map('GET|POST', '/error', 'VisitorControler','error'); + $router->map('GET|POST', '/randomQuiz', 'UserControler','randomQuiz'); $router->map('GET|POST', '/deleteAccount', 'UserControler', 'deleteAccount'); + $match = $router->match(); $action = NULL; if(!$match){ - $dVueEreur[] = "Requête introuvable"; + $dVueEreur = [404,"Page non trouvée"]; $this->vueErreur($dVueEreur); } else{ @@ -71,7 +75,7 @@ Class FrontControler{ //Si existe, on l’appelle if(!$this->ifExisteAction($action)){ - $dVueEreur[] = "Action introuvable"; + $dVueEreur = [404,"Action non trouvée"]; $this->vueErreur($dVueEreur); } @@ -112,9 +116,8 @@ Class FrontControler{ return false; } - private function vueErreur(array $dVueErreur){ + private function vueErreur(array $erreur){ global $vues; - echo "{$dVueErreur[0]}"; require_once $vues['erreur']; } diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 5a4b9f5..12a65c2 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -29,20 +29,113 @@ class UserControler { private CommentaryModel $cMod; private UserModel $uMod; private QuoteModel $qMod; - private QuestionModel $mdl; private CharacterModel $caMod; private SourceModel $srcMod; + private QuestionModel $questMod; private ImageModel $iMod; + private QuizModel $quizModel; + public function __construct() { global $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)); + $this -> questMod = new QuestionModel(new QuestionGateway($co)); $this -> caMod = new CharacterModel(new CharacterGateway($co)); $this->srcMod = new SourceModel(new SourceGateway($co)); $this->iMod = new ImageModel(new ImageGateway($co)); + $this->quizModel = new QuizModel(new QuizGateway($co)); + } + + public function accueilQuiz() { + global $vues; + $quizs = $this->quizModel->listQuiz(); + require_once $vues['accueilQuiz']; + } + + public function randomQuiz() { + global $vues; + + $canswer = Verification::verifChar($_POST['canswer'] ?? null); + + /*---------------------------------------------*/ + + if(!isset($_SESSION["no_question"])){ + $no_question = 0; + } + else{ + $no_question = Verification::verifChar($_SESSION["no_question"]); + + if($canswer!=null){ + $no_question=$no_question+1; + } + + if($no_question < 1 ){ + $no_question = 0; + } + } + $_SESSION["no_question"]=$no_question; + + /*---------------------------------------------*/ + + if(!isset($_SESSION["nbVie"])){ + $vie = 3; + } + else{ + $vie = Verification::verifChar($_SESSION["nbVie"]) ; + if($vie > 3 ){ + $vie = 3; + } + elseif($vie < 1){ + $vie = 0; + } + } + + /*---------------------------------------------*/ + + $answera = Verification::verifChar($_POST['answera'] ?? null); + $answerb = Verification::verifChar($_POST['answerb'] ?? null); + $answerc = Verification::verifChar($_POST['answerc'] ?? null); + $answerd = Verification::verifChar($_POST['answerd'] ?? null); + + + $answer = null; + + if ($answera) { + $answer = $answera; + } elseif ($answerb) { + $answer = $answerb; + } elseif ($answerc) { + $answer = $answerc; + } elseif ($answerd) { + $answer = $answerd; + } + if($answer != $canswer){ + $vie=$vie-1; + } + + /*---------------------------------------------*/ + + $_SESSION["nbVie"]=$vie; + + if($vie<=0){ + $score=($no_question - 3); + $next=false; + $nbQuestion=$no_question; + + unset($_SESSION["no_question"]); + unset($_SESSION["nbVie"]); + + require_once $vues['endQuizRandom']; + } + else{ + /*---------------------------------------------*/ + + $question = $this->questMod->QuestionForQuoteToCarac('fr'); + + require_once $vues['quizRandom']; + } } public function profil() { @@ -145,10 +238,12 @@ class UserControler { $gw = new QuizGateway($co); $mdl = new QuizModel($gw); - + $nbQuestion = $this->getNumberOfQuestion($id_quiz); if ($mdl->getQuiz($id_quiz + 1)){ + $next = true; require_once $vues['endQuiz']; } + $next = false; require_once $vues['endQuiz']; } @@ -174,7 +269,7 @@ class UserControler { $answer = explode('-', $answerd)[0]; $id = (int) explode('-', $answerd)[1]; } - $res = $this->mdl->getQuestion($id); + $res = $this->questMod->getQuestion($id); return $answer == $res->getCanswer(); } @@ -195,11 +290,20 @@ class UserControler { $q = $this->GetQuestion($id); $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); + $nbQuestion = $this->getNumberOfQuestion($id); require_once $vues['quiz']; //echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); } + public function getQuiz(int $id) : QuizModel + { + global $co; + $gw = new QuizGateway($co); + $mdl = new QuizModel($gw); + return $mdl->getQuiz($id); + } + public function getNumberOfQuestion(int $id) : int{ global $co; @@ -333,46 +437,24 @@ class UserControler { * @throws RuntimeError * @throws LoaderError */ - public function toSubmit() : ?array{ + + public function toSubmit(string $content,string $character, string $source) + { global $co; if ($_POST) { - $content = $_POST['content'] ?? null; - $character = $_POST['character'] ?? null; - $source = $_POST['src'] ?? null; - //$img = $_POST['img'] ?? null; - $errors = [null, null]; - $gw = new CharacterGateway($co); - $mdl = new CharacterModel($gw); - - $character = $mdl -> getCharacterById($character); - - $gw = new SourceGateway($co); - $mdl = new SourceModel($gw); - - $source = $mdl -> getSourceById($source); + $nameSrc = $this->srcMod->getSourceById($source)->getTitle(); + $nameChar = $this->caMod->getCharacterById($character)->getName(); if (!$character) $errors[0] = "Personnage inexistant"; if (!$source) $errors[1] = "Source inexistante"; - if ($errors[0] || $errors[1]) - { - global $twig; - $this->submit(); - exit(); - } - - $gw = new QuoteGateway($co); - $mdl = new QuoteModel($gw); - - //$mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter()); - - return [$content, $_POST['character'], $_POST['src']]; + $this -> qMod -> addQuote($content,'fr',$character,$source,$this->uMod->getIdByUsername(Verification::VerifChar($_SESSION['user']))); + $this -> recapSubmitQuote(array('content' => $content, 'src' => $nameSrc, 'character' => $nameChar)); } - return null; } /** @@ -386,6 +468,8 @@ class UserControler { global $vues; $src = true; $char = true; + $srcId = null; + $charId = null; require_once $vues['create']; exit(); } @@ -393,6 +477,8 @@ class UserControler { global $vues; $src = true; $char = false; + $srcId = null; + $charId = $_POST['character']; require_once $vues['create']; exit(); } @@ -400,32 +486,25 @@ class UserControler { global $vues; $src = false; $char = true; + $srcId = $_POST['src']; + $charId = null; require_once $vues['create']; exit(); } - if($_POST) - $recap = $this -> toSubmit(); - if ($recap) - { - $this -> recapSubmitQuote($recap); - } + $recap = $this -> toSubmit($_POST['content'],$_POST['character'],$_POST['src']); + } + + public function recapSubmitQuote(array $recap){ + global $vues; + require_once($vues["recap"]); } // ===================== SUBMIT QUOTE FUNCTION ===================== - /** - * @throws RuntimeError - * @throws SyntaxError - * @throws LoaderError - */ - public function recapSubmitQuote(?array $recap) : void{ - global $twig; - echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]); - } - - public function getIdOfUser() : ?int{ + public function getIdOfUser() : ?int + { if (isset($_SESSION['user'])) { global $co; @@ -439,17 +518,18 @@ class UserControler { public function add(){ - global $vues; - var_dump($_POST); + global $vues, $repImg; $error = []; + $src = false; + $char = false; + var_dump($_FILES); if($_POST['req'] == "both"){ $src = true; $char = true; } - elseif($_POST['req'] == "src"){ - $src = true; - $char = false; - $type = array("Movie","Serie","VideoGame","Anime"); + + if($_POST['req'] == "src" or $src == true){ + $type = array("movie","serie","video-game","anime"); if(Verification::verifNotNull($_POST["titre"])){ $_POST["titre"] = Verification::verifChar($_POST["titre"]); if($this->srcMod->existSource($_POST["titre"],$_POST["type"])){ @@ -460,8 +540,6 @@ class UserControler { $error[] = "Le titre doit être définit"; } if(Verification::verifNotNull($_POST["date"])){ - $src = true; - $char = false; $_POST["date"] = Verification::verifChar($_POST["date"]); if(intval($_POST["date"],10) < 1850 or intval($_POST["date"],10) > date( "Y", time() )){ $error[] = "La date est invalide"; @@ -480,30 +558,66 @@ class UserControler { $error[] = "Le type doit être définit"; } } - elseif($_POST['req'] == "char"){ - $src = false; - $char = true; - if(Verification::verifNotNull($_POST[""])){ + + if($_POST['req'] == "char" or $char == true){ + if(Verification::verifNotNull($_POST["name"])){ + $_POST["name"] = Verification::verifChar($_POST["name"]); + } + else{ + $error[] = "Le nom doit être définit"; + } + // upload de la photo + if (isset($_FILES['avatar'])) { + + $tabExtension = explode('.', $_FILES['avatar']['name']); + $extension = strtolower(end($tabExtension)); + $extensions = ['jpg', 'png', 'jpeg']; + if(in_array($extension, $extensions)){ + move_uploaded_file($_FILES['avatar']['tmp_name'], $repImg.$_FILES['avatar']['name']); + $filePath = $repImg.$_FILES['avatar']['name']; + } + else{ + $error[] = "Mauvaise extension"; + exit(); + } + } + else{ + $error[] = "Aucune photo"; } + } + if($error == []){ + $recap['content'] = $_POST['content']; if($_POST['req'] == "both"){ - + $this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"])); + $idImg = $this->iMod->createImgModelWithoutId($filePath); + $this->caMod->createCharacterWithoutId($_POST["name"], $idImg); + $idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter(); + $idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource(); } elseif($_POST['req'] == "src"){ - $this->srcMod->createSource($_POST["titre"], $_POST["date"], $_POST["type"]); + $this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"])); + $idC = Verification::VerifChar($_POST["character"]); + $idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource(); } elseif($_POST['req'] == "char"){ - + $idImg = $this->iMod->createImgModelWithoutId($filePath); + $this->caMod->createCharacterWithoutId($_POST["name"], $idImg); + $idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter(); + $idS = Verification::VerifChar($_POST["src"]); } + $this -> toSubmit(Verification::VerifChar($_POST["content"]),$idC,$idS); } else{ require_once($vues["create"]); - var_dump($error); } } + public function questionSuivantAleatoire(){ + + } // ===================== DELETE ACCOUNT FUNCTION ===================== diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 87cb3ee..366c692 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -56,10 +56,21 @@ Class VisitorControler { public function quote(array $arg){ global $vues; $id= $arg['idQuote'] ?? 1; + if($id > 999999999){ + $erreur = [404,"Citation inexistante pour le moment",'../']; + require_once($vues['erreur']); + exit(); + } $f = $this->uMod->isFavorite($_SESSION["user"],$id); $q = $this->qMod->searchId($id); $c = $this->cMod->getComment($id); - require_once $vues['quote']; + if($q->getContent() != 'NULL'){ + require_once $vues['quote']; + } + else{ + $erreur = [404,"Citation inexistante pour le moment","../"]; + require_once($vues['erreur']); + } } public function favorite() { diff --git a/src/Entity/QuizEntity.php b/src/Entity/QuizEntity.php index e5f31da..d440b2c 100644 --- a/src/Entity/QuizEntity.php +++ b/src/Entity/QuizEntity.php @@ -4,18 +4,26 @@ namespace Entity; class QuizEntity { - private int $id_quiz; + public int $id_quiz; - private int $nb_questions; + public int $nb_quest; + + public string $imgPath; + + public string $title; /** * @param int $id_quiz - * @param int $nb_questions + * @param int $nb_quest + * @param string $imgPath + * @param string $title */ - public function __construct(int $id_quiz, int $nb_questions) + public function __construct(int $id_quiz, int $nb_quest, string $imgPath, string $title) { $this->id_quiz = $id_quiz; - $this->nb_questions = $nb_questions; + $this->nb_quest = $nb_quest; + $this->imgPath = $imgPath; + $this->title = $title; } /** @@ -39,18 +47,46 @@ class QuizEntity */ public function getNbQuestions(): int { - return $this->nb_questions; + return $this->nb_quest; } /** - * @param int $nb_questions + * @param int $nb_quest */ - public function setNbQuestions(int $nb_questions): void + public function setNbQuestions(int $nb_quest): void { - $this->nb_questions = $nb_questions; + $this->nb_quest = $nb_quest; } + /** + * @return string + */ + public function getIdImg(): string + { + return $this->imgPath; + } + /** + * @param string $imgPath + */ + public function setIdImg(string $imgPath): void + { + $this->imgPath = $imgPath; + } + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + /** + * @param string $title + */ + public function setTitle(string $title): void + { + $this->title = $title; + } } diff --git a/src/Entity/Quote.php b/src/Entity/Quote.php index f5eb1ab..fff3141 100644 --- a/src/Entity/Quote.php +++ b/src/Entity/Quote.php @@ -1,6 +1,8 @@ id = $id; $this->content = $content; @@ -32,6 +35,7 @@ $this->dateSrc = $dateSrc; $this->like = $like; $this->langue = $langue; + $this->type = $type; } /** @@ -162,7 +166,13 @@ $this->langue = $langue; } + public function getType(): TypeSourceEnum{ + return $this->type; + } + public function setType(TypeSourceEnum $type){ + $this->type = $type; + } } ?> diff --git a/src/Enum/TypeSourceEnum.php b/src/Enum/TypeSourceEnum.php index 4a20ac1..b971c05 100644 --- a/src/Enum/TypeSourceEnum.php +++ b/src/Enum/TypeSourceEnum.php @@ -6,4 +6,14 @@ enum TypeSourceEnum : string { case VideoGame = 'video-game'; case Anime = 'anime'; case Serie = 'serie'; + + public static function fromName(string $name): string + { + foreach (self::cases() as $status) { + if( $name === $status->name ){ + return $status->value; + } + } + throw new \ValueError("$name is not a valid backing value for enum " . self::class ); + } } \ No newline at end of file diff --git a/src/Gateway/CharacterGateway.php b/src/Gateway/CharacterGateway.php index 9d4c1b7..0f7b2ef 100644 --- a/src/Gateway/CharacterGateway.php +++ b/src/Gateway/CharacterGateway.php @@ -18,7 +18,7 @@ class CharacterGateway extends Gateway return $this -> co -> executeQuery($query, [ 'id_caracter' => array($id_character, PDO::PARAM_INT), 'caracter' => array($name, PDO::PARAM_STR), - 'id_img' => array($img_char, PDO::PARAM_STR) + 'id_img' => array($img_char, PDO::PARAM_INT) ]); } @@ -61,8 +61,24 @@ class CharacterGateway extends Gateway return $this -> co -> executeQuery($query, [ "id_c" => array($id_char, PDO::PARAM_INT), "caracter" => array($name, PDO::PARAM_STR), - "i" => array($img_char, PDO::PARAM_STR) + "i" => array($img_char, PDO::PARAM_INT) ]); } + public function getLastId():int{ + $query = "SELECT id_caracter FROM Caracter;"; + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); + foreach($res as $r){ + $tab[] = $r["id_caracter"]; + } + $id = 1; + while(in_array($id,$tab)) + { + $id=$id+1; + } + return $id; + } + + } \ No newline at end of file diff --git a/src/Gateway/ImageGateway.php b/src/Gateway/ImageGateway.php index b001554..4e6d0af 100644 --- a/src/Gateway/ImageGateway.php +++ b/src/Gateway/ImageGateway.php @@ -65,4 +65,19 @@ class ImageGateway extends Gateway 'img_path' => array($imgPath, PDO::PARAM_STR) ]); } + + public function getLastId():int{ + $query = "SELECT id_img FROM Image;"; + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); + foreach($res as $r){ + $tab[] = $r["id_img"]; + } + $id = 1; + while(in_array($id,$tab)) + { + $id=$id+1; + } + return $id; + } } \ No newline at end of file diff --git a/src/Gateway/QuestionGateway.php b/src/Gateway/QuestionGateway.php index d67e175..54ab309 100644 --- a/src/Gateway/QuestionGateway.php +++ b/src/Gateway/QuestionGateway.php @@ -98,4 +98,75 @@ class QuestionGateway extends Gateway return $this -> co -> getResults(); } + public function getQuestionQuoteSrc(string $l) : array{ + + } + + + /*--------------------------------------- Quiz Aléatoire ---------------------------------------*/ + + /*----------------------- Question + Reponce Corecte -----------------------*/ + public function QuestionToReponceForQuoteToCarac(string $lang) : array + { + $query = "Select q.content as Question ,c.caracter as Reponce + from Quote Q + join Caracter c on c.id_caracter=q.id_caracter + where q.langue=:lang and q.isValide = 'true' + ORDER BY RANDOM() + LIMIT 1;"; + $this -> co -> executeQuery($query, [':lang' => array($lang, PDO::PARAM_STR)]); + return $this -> co -> getResults(); + } + + + public function QuestionToReponceForQuoteToTitle(string $lang) : array + { + $query = "Select q.content as Question ,s.title as Reponce + from Quote Q + join Source s on s.id_source=q.id_source + where q.langue=:lang and q.isValide = 'true' + ORDER BY RANDOM() + LIMIT 1;"; + $this -> co -> executeQuery($query, [':lang' => array($lang, PDO::PARAM_STR)]); + return $this -> co -> getResults(); + } + + /*----------------------- Reponce Fausse -----------------------*/ + + public function FakeReponceForQuoteToCarac(string $lang,string $corecteReponce) : array + { + $query = "Select c.caracter as Reponce + from Quote Q + join Caracter c on c.id_caracter=q.id_caracter + where q.langue = :lang And c.caracter != :corecteReponce and q.isValide = 'true' + ORDER BY RANDOM() + LIMIT 3;"; + + $this -> co -> executeQuery($query, [ + ':lang' => array($lang, PDO::PARAM_STR), + ':corecteReponce' => array($lang, PDO::PARAM_STR) + ]); + return $this -> co -> getResults(); + } + + + + public function FakeReponceForQuoteToTitle(string $lang,string $corecteReponce) : array + { + $query = "Select s.title as Reponce + from Quote Q + join Source s on s.id_source=q.id_source + where q.langue = :lang And s.title != :corecteReponce and q.isValide = 'true' + ORDER BY RANDOM() + LIMIT 3;"; + + $this -> co -> executeQuery($query, [ + ':lang' => array($lang, PDO::PARAM_STR), + ':corecteReponce' => array($lang, PDO::PARAM_STR) + ]); + return $this -> co -> getResults(); + } + + + } diff --git a/src/Gateway/QuizGateway.php b/src/Gateway/QuizGateway.php index 9bf4ff1..c80d372 100644 --- a/src/Gateway/QuizGateway.php +++ b/src/Gateway/QuizGateway.php @@ -8,22 +8,24 @@ use PDO; class QuizGateway extends Gateway { - public function create(int $id_quiz, int $nb_questions) : bool + public function create(int $id_quiz, int $nb_questions, string $id_img, string $title) : bool { $query = " INSERT INTO Quiz - VALUES (:id_q, :nb_q) + VALUES (:id_q, :nb_q, :id_img, :title) "; return $this -> co -> executeQuery($query, [ ':id_q' => array($id_quiz, PDO::PARAM_INT), - ':nb_q' => array($nb_questions, PDO::PARAM_INT) + ':nb_q' => array($nb_questions, PDO::PARAM_INT), + ':id_img' => array($id_img, PDO::PARAM_STR), + ':title' => array($title, PDO::PARAM_STR) ]); } public function findQuizById(int $id) : array { - $query = "SELECT * FROM Quiz WHERE id_quiz = :id_q"; + $query = "SELECT id_quiz, title, imgPath, nb_quest FROM Quiz q JOIN Image i on q.img = i.id_img WHERE id_quiz = :id_q"; $this -> co -> executeQuery($query, [':id_q' => array($id, PDO::PARAM_INT)]); return $this -> co -> getResults(); } @@ -36,9 +38,15 @@ class QuizGateway extends Gateway public function findAll() : array { - $query = "SELECT * FROM Quiz"; + $query = "SELECT id_quiz, title, imgPath, nb_quest FROM Quiz q JOIN Image i on q.img = i.id_img"; $this -> co -> executeQuery($query); return $this -> co -> getResults(); } + public function getNumberOfQuestion(int $id) : intdiv{ + $query = "SELECT nb_quest FROM quiz WHERE id_quiz = :id_q"; + $this -> co -> executeQuery($query, [':id_q' => array($id, PDO::PARAM_INT)]); + return $this -> co -> getResults(); + } + } \ No newline at end of file diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php index d5ace1f..92adefd 100644 --- a/src/Gateway/QuoteGateway.php +++ b/src/Gateway/QuoteGateway.php @@ -151,23 +151,38 @@ Class QuoteGateway extends Gateway{ return ($this -> co ->getResults())[0]['id']; } - public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool - { - $query = " - INSERT INTO Quote (id_quote, content, langue, reason, id_source, id_caracter, id_user_verif, img_path) - VALUES (:id, :content, :langage, :reason, :source, :character, :user, :img_path) - "; - - return $this->co->executeQuery($query, [ - ':id' => array($this->autoincrement(), PDO::PARAM_INT), - ':content' => array($content, PDO::PARAM_STR), - ':img_path' => array($img_path, PDO::PARAM_STR), - ':langage' => array($langage, PDO::PARAM_STR), - ':user' => array($user, PDO::PARAM_INT), - ':reason' => array('À vérifier', PDO::PARAM_STR), - ':source' => array($source, PDO::PARAM_STR), - ':character' => array($character, PDO::PARAM_STR) - ]); + public function addQuote(string $content, string $lang, int $idChar, int $idSrc, int $idUsr){ + $id = $this->getLastId(); + $query = "INSERT INTO Quote Values (:id,:content,0,:lang,false,'',:charac,:src,:user);"; + try { + $this->co->executeQuery($query,[ + ':id' => [$id,PDO::PARAM_INT], + ':content' => [$content,PDO::PARAM_STR], + ':lang' => [$lang,PDO::PARAM_STR], + ':charac' => [$idChar,PDO::PARAM_INT], + ':src' => [$idSrc,PDO::PARAM_INT], + ':user' => [$idUsr,PDO::PARAM_INT], + ]); + } + catch (PDOException $e){ + $error['501'] = 'Erreur lors de la création de la citation'; + return error; + } + } + + public function getLastId():int{ + $query = "SELECT id_quote FROM Quote;"; + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); + foreach($res as $r){ + $tab[] = $r["id_quote"]; + } + $id = 1; + while(in_array($id,$tab)) + { + $id=$id+1; + } + return $id; } //======================== PARTI ADMIN ======================== diff --git a/src/Gateway/SourceGateway.php b/src/Gateway/SourceGateway.php index 402d30b..456eab7 100644 --- a/src/Gateway/SourceGateway.php +++ b/src/Gateway/SourceGateway.php @@ -10,10 +10,11 @@ class SourceGateway extends Gateway{ { $query = " INSERT INTO Source - VALUES( :title, :date) + VALUES(:id, :title, :date) "; return $this -> co -> executeQuery($query, [ + "id" => array($s->getIdSource(), PDO::PARAM_INT), "title" => array($s->getTitle(), PDO::PARAM_STR), "date" => array($s->getDate(), PDO::PARAM_STR), #"type" => array($s->getType(), PDO::PARAM_STR) @@ -81,4 +82,19 @@ class SourceGateway extends Gateway{ ]); } + public function getLastId():int{ + $query = "SELECT id_source FROM Source;"; + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); + foreach($res as $r){ + $tab[] = $r["id_source"]; + } + $id = 1; + while(in_array($id,$tab)) + { + $id=$id+1; + } + return $id; + } + } diff --git a/src/Model/CharacterModel.php b/src/Model/CharacterModel.php index 5259c60..ac0655a 100644 --- a/src/Model/CharacterModel.php +++ b/src/Model/CharacterModel.php @@ -9,11 +9,17 @@ use Gateway\Gateway; class CharacterModel extends Model { - public function createCharacter(int $id_character, string $name , string $img_char) : bool + public function createCharacter(int $id_character, string $name , int $img_char) : bool { return $this -> gateway -> create($id_character, $name, $img_char); } + public function createCharacterWithoutId(string $name , int $img_char) : bool + { + $id_character = $this -> gateway -> getLastId(); + return $this -> gateway -> create($id_character, $name, $img_char); + } + public function getCharacterById(int $id_character) : ?CharacterEntity { $c = $this -> gateway -> findById($id_character); @@ -72,7 +78,7 @@ class CharacterModel extends Model return $this -> gateway -> delete($id_character); } - public function updateCharacter(int $id_character, string $name, string $img_char) : bool + public function updateCharacter(int $id_character, string $name, int $img_char) : bool { return $this -> gateway -> update($id_character, $name, $img_char); } diff --git a/src/Model/ImageModel.php b/src/Model/ImageModel.php index 9192ecc..74a8330 100644 --- a/src/Model/ImageModel.php +++ b/src/Model/ImageModel.php @@ -13,6 +13,13 @@ class ImageModel extends Model return $this -> gateway -> createImgGateway($idImg, $imgPath); } + public function createImgModelWithoutId (string $imgPath) : int + { + $idImg = $this->gateway ->getLastId() ; + $this -> gateway -> createImgGateway($idImg, $imgPath, false); + return $idImg; + } + public function getImgById(int $idImg) : ?ImageEntity { $res = $this -> gateway -> findImgById($idImg); diff --git a/src/Model/QuestionModel.php b/src/Model/QuestionModel.php index d560b18..33fd767 100644 --- a/src/Model/QuestionModel.php +++ b/src/Model/QuestionModel.php @@ -79,4 +79,82 @@ class QuestionModel extends Model ); return null; } + + public function getRandomQuestion(string $quesType, string $repType, string $langue) : ?QuestionEntity{ + switch([$questType,$repType]){ + case ["Quote","Src"]: + $q = $this -> gateway -> getQuestionQuoteSrc($langue); + return new QuestionEntity( + $q[], //idQuote + $q[], //Quote + $q[], //SrcJuste + $q[], //rndSrc 1 + $q[], //rndSrc 2 + $q[], //rndSrc 3 + $q[], //SrcJuste + ); + case ["Quote","Charac"]: + $q = $this -> gateway -> getQuestionQuoteCharac($langue); + + case ["Charac","Src"]: + $q = $this -> gateway -> getQuestionCharacSrc($langue); + + case ["Charac","Quote"]: + $q = $this -> gateway -> getQuestionCharacQuote($langue); + + case ["Src","Quote"]: + $q = $this -> gateway -> getQuestionSrcQuote($langue); + + case ["Src","Charac"]: + $q = $this -> gateway -> getQuestionSrcCharac($langue); + + case ["Test","Test"]: + return new QuestionEntity(-1,"1","1","2","3","4","1"); + default : + return null; + } + } + + + /*--------------------------------------- Quiz Aléatoire ---------------------------------------*/ + + /*----------------------- Question compléte -----------------------*/ + + public function QuestionForQuoteToCarac(string $lang) : QuestionEntity + { + $questRep = $this->gateway->QuestionToReponceForQuoteToCarac($lang); + + + $quest = $questRep[0]['question']; + $cAnswer = $questRep[0]['reponce']; + + $fake = $this->gateway->FakeReponceForQuoteToCarac($lang,$cAnswer); + + $fakeRep = [$cAnswer]; + foreach ($fake as $rep){ + $fakeRep[]=$rep['reponce']; + } + shuffle($fakeRep); + + + return new QuestionEntity(-1,$quest,$fakeRep[0],$fakeRep[1],$fakeRep[2],$fakeRep[3],$cAnswer); + } + + public function QuestionForQuoteToTitle(string $lang) : QuestionEntity + { + $questRep = $this->gateway->QuestionToReponceForQuoteToTitle($lang); + + $quest = $questRep['question']; + $cAnswer = $questRep['reponce']; + + $fake = $this->gateway->FakeReponceForQuoteToTitle($lang,$cAnswer); + + $fakeRep = [$cAnswer]; + foreach ($fake as $rep){ + $fakeRep[]=$rep['reponce']; + } + $fakeRep=array_rand($fakeRep); + + return new QuestionEntity(-1,$quest,$fakeRep[0],$fakeRep[1],$fakeRep[2],$fakeRep[3],$cAnswer); + } } \ No newline at end of file diff --git a/src/Model/QuizModel.php b/src/Model/QuizModel.php index c38581e..cb12dac 100644 --- a/src/Model/QuizModel.php +++ b/src/Model/QuizModel.php @@ -2,24 +2,26 @@ namespace Model; -use Entity\quizEntity; +use Entity\QuizEntity; use Gateway\QuizGateway; use Gateway\Gateway; class QuizModel extends Model{ - public function createQuiz(int $id_quiz, int $nb_questions) : bool + public function createQuiz(int $id_quiz, int $nb_questions, String $id_img, string $title) : bool { - return $this -> gateway -> create($id_quiz, $nb_questions); + return $this -> gateway -> create($id_quiz, $nb_questions, $id_img, $title); } - public function getQuiz(int $id_quiz): ?quizEntity + public function getQuiz(int $id_quiz): ?QuizEntity { $q = $this -> gateway -> findQuizById($id_quiz); if ($q) { - return new quizEntity( + return new QuizEntity( $q[0]['id_quiz'], - $q[0]['nb_quest'] + $q[0]['nb_quest'], + $q[0]['imgpath'], + $q[0]['title'] ); } return null; @@ -30,20 +32,22 @@ class QuizModel extends Model{ return $this -> gateway -> delete($id_quiz); } - public function getAllQuiz() : array + public function listQuiz() : array { - $q = $this -> gateway -> findAll(); + $res = $this -> gateway -> findAll(); - $quizzes = []; + $quizs = []; - foreach ($q as $quiz) { - $quizzes[] = new quizEntity( + foreach ($res as $quiz) + { + $quizs[] = new QuizEntity( $quiz['id_quiz'], - $quiz['nb_questions'] + $quiz['nb_quest'], + $quiz['imgpath'], + $quiz['title'] ); } - return $quizzes; + return $quizs; } - } \ No newline at end of file diff --git a/src/Model/QuoteModel.php b/src/Model/QuoteModel.php index b0bcff3..0c70fb5 100644 --- a/src/Model/QuoteModel.php +++ b/src/Model/QuoteModel.php @@ -3,6 +3,7 @@ use Entity\Quote; use Gateway\QuoteGateway; use Gateway\Gateway; + use Enum\TypeSourceEnum; class QuoteModel extends Model { @@ -12,7 +13,7 @@ if( count($res) == 0) return new Quote(-1,"NULL","NULL","NULL","NULL","NULL",0,"Default"); 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"]); + 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"],TypeSourceEnum::Movie); } public function getSuggest(int $numpage, string $language):array{ @@ -21,7 +22,7 @@ foreach($res as $q ){ $q["content"] = (strlen($q["content"]) > 153) ? substr($q["content"],0,150).'...' : $q["content"]; - $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"]) ; + $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"],TypeSourceEnum::Movie) ; } return $tabQ; } @@ -29,10 +30,10 @@ 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"); + return new Quote(-1,"NULL","NULL","NULL","NULL","NULL",0,"Default",TypeSourceEnum::Movie); else $res["content"] = (strlen($res["content"]) > 153) ? substr($res["content"],0,150).'...' : $res["content"]; - return new Quote($res["id_quote"],$res["content"],$res["caracter"],$res["imgpath"],$res["title"],$res["dates"],$res["likes"],$res["langue"]) ; + return new Quote($res["id_quote"],$res["content"],$res["caracter"],$res["imgpath"],$res["title"],$res["dates"],$res["likes"],$res["langue"],TypeSourceEnum::Movie) ; } public function getFavorites(string $userId): array { @@ -41,16 +42,14 @@ foreach($res as $q ){ $q["content"] = (strlen($q["content"]) > 153) ? substr($q["content"],0,150).'...' : $q["content"]; - $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"]) ; + $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"],TypeSourceEnum::Movie) ; } return $tabQ; } - public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool - { - return $this->gateway->insert4User($content, $img_path, $langage, $user, $source, $character); + public function addQuote(string $content, string $lang, int $idChar, int $idSrc, int $idUsr){ + $this -> gateway -> addQuote($content,$lang,$idChar,$idSrc,$idUsr); } - } ?> diff --git a/src/Model/SearchModel.php b/src/Model/SearchModel.php index 48bd1f6..0762bf0 100644 --- a/src/Model/SearchModel.php +++ b/src/Model/SearchModel.php @@ -3,6 +3,7 @@ use Entity\Quote; use Gateway\QuoteGateway; use Gateway\Gateway; + use Enum\TypeSourceEnum; class SearchModel extends Model { @@ -14,7 +15,7 @@ foreach($res as $q ){ $q["content"] = (strlen($q["content"]) > 153) ? substr($q["content"],0,150).'...' : $q["content"]; - $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"]) ; + $tabQ[]= new Quote($q["id_quote"],$q["content"],$q["caracter"],$q["imgpath"],$q["title"],$q["dates"],$q["likes"],$q["langue"],TypeSourceEnum::Movie) ; } return $tabQ; } diff --git a/src/Model/SourceModel.php b/src/Model/SourceModel.php index d43579b..9c54cce 100644 --- a/src/Model/SourceModel.php +++ b/src/Model/SourceModel.php @@ -8,8 +8,8 @@ class SourceModel extends Model public function createSource(string $title, string $date, TypeSourceEnum $type) : bool { - $q = new SourceEntity(-1,$title, $date, TypeSourceEnum::Movie/*$type*/); - + $id = $this -> gateway -> getLastId(); + $q = new SourceEntity($id,$title, $date, $type); return $this -> gateway -> create($q); } @@ -106,7 +106,7 @@ class SourceModel extends Model public function existSource(string $name, string $type) : bool{ $q = $this -> getSourceByTitle($name); - return isset($q[0]); + return isset($q); } } diff --git a/src/Verification/Verification.php b/src/Verification/Verification.php index eef98ab..e8ae8ba 100644 --- a/src/Verification/Verification.php +++ b/src/Verification/Verification.php @@ -7,8 +7,8 @@ namespace Verification; if($text==NULL){ return NULL; } - $charInterdi=['|','/','\\','%','$','=','<','>','(',')']; - $chaineInterdi=["AND","OR","WHERE","FROM","SELECT"]; + $charInterdi=['|','/','\\','%','$','=','<','>','(',')',';']; + $chaineInterdi=["AND","OR","WHERE","FROM","SELECT","DROP","DELETE","TABLE","Users"]; $textVerif=""; foreach( str_split($text,1) as $char){ diff --git a/vue/accueilQuiz.php b/vue/accueilQuiz.php new file mode 100644 index 0000000..2a5572b --- /dev/null +++ b/vue/accueilQuiz.php @@ -0,0 +1,16 @@ +render('head.html.twig', [ + 'title' => "Quiz", + 'style' => "public/styles/styleAccueilQuiz.css", + 'scripts' => array("public/script/theme-toggle.js") +]); + +echo $twig->render('bandeau.html.twig'); + +echo $twig->render('accueilQuiz.html.twig', [ + 'quizs' => $quizs +]); +?> \ No newline at end of file diff --git a/vue/create.php b/vue/create.php index e0a16eb..f7c7f5b 100644 --- a/vue/create.php +++ b/vue/create.php @@ -14,6 +14,9 @@ echo $twig->render('bandeau.html.twig'); echo $twig->render('create.html.twig', [ 'src' => $src, - 'char' => $char + 'char' => $char, + 'content' => $_POST['content'], + 'charId' => $charId, + 'srcId' => $srcId ]); ?> diff --git a/vue/endQuiz.php b/vue/endQuiz.php index 8d4d68c..64e46f4 100644 --- a/vue/endQuiz.php +++ b/vue/endQuiz.php @@ -8,11 +8,13 @@ echo $twig->render('head.html.twig', [ 'scripts' => array("../public/script/theme-toggle-double-param.js") ]); - // Rendu du bandeau echo $twig->render('bandeau.html.twig'); -echo $twig->render('endQuiz.html.twig', ['score' => $score, 'nextquiz' => $id_quiz + 1]) +echo $twig->render('endQuiz.html.twig', + ['score' => $score, + 'isNextQuiz' => $next, + 'nb' => $nbQuestion]); ?> diff --git a/vue/endQuizRandom.php b/vue/endQuizRandom.php new file mode 100644 index 0000000..1ca94de --- /dev/null +++ b/vue/endQuizRandom.php @@ -0,0 +1,17 @@ +render('head.html.twig', [ + 'title' => "Quiz", + 'style' => "public/styles/styleEndQuiz.css", + 'scripts' => array("public/script/theme-toggle.js") +]); + +// Rendu du bandeau +echo $twig->render('bandeau.html.twig'); + +echo $twig->render('endQuizRandom.html.twig', + ['score' => $score +]); +?> \ No newline at end of file diff --git a/vue/erreur.php b/vue/erreur.php index dc283d5..f3b64f5 100644 --- a/vue/erreur.php +++ b/vue/erreur.php @@ -1,5 +1,25 @@ -