From c86de066fdbdf7879269763a537fb3373980a042 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Mon, 13 Jan 2025 09:53:00 +0100 Subject: [PATCH] modif ajout citation --- config/config.php | 1 + src/Controleur/FrontControler.php | 3 +-- src/Controleur/UserControler.php | 10 +++++----- src/Enum/TypeSourceEnum.php | 10 ++++++++++ src/Gateway/SourceGateway.php | 18 +++++++++++++++++- src/Model/SourceModel.php | 4 ++-- vue/create.php | 3 ++- vue/recap.php | 16 ++++++++++++++++ vue/templates/create.html.twig | 19 +++++++++++++++---- 9 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 vue/recap.php diff --git a/config/config.php b/config/config.php index 13c4fe2..93fc1eb 100644 --- a/config/config.php +++ b/config/config.php @@ -29,6 +29,7 @@ $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'; //Style css diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index e38d0c8..ec503b3 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'), + 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'add'), 'admin' => array('null')]; $dVueEreur = []; @@ -52,7 +52,6 @@ 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', '/add', 'UserControler', 'add'); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index e7e5ac6..a7c4042 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -446,16 +446,15 @@ class UserControler { public function add(){ global $vues; - var_dump($_POST); $error = []; if($_POST['req'] == "both"){ $src = true; $char = true; } - elseif($_POST['req'] == "src"){ + elseif($_POST['req'] == "src" or $src == true){ $src = true; $char = false; - $type = array("Movie","Serie","VideoGame","Anime"); + $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"])){ @@ -486,7 +485,7 @@ class UserControler { $error[] = "Le type doit être définit"; } } - elseif($_POST['req'] == "char"){ + elseif($_POST['req'] == "char" or $char == true){ $src = false; $char = true; if(Verification::verifNotNull($_POST[""])){ @@ -498,11 +497,12 @@ class UserControler { } elseif($_POST['req'] == "src"){ - $this->srcMod->createSource($_POST["titre"], $_POST["date"], $_POST["type"]); + $this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"])); } elseif($_POST['req'] == "char"){ } + require_once($vues["recap"]); //A changer pour recapSubmitQuote } else{ require_once($vues["create"]); 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/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/SourceModel.php b/src/Model/SourceModel.php index d43579b..000a01e 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); } diff --git a/vue/create.php b/vue/create.php index e0a16eb..451cbc2 100644 --- a/vue/create.php +++ b/vue/create.php @@ -14,6 +14,7 @@ echo $twig->render('bandeau.html.twig'); echo $twig->render('create.html.twig', [ 'src' => $src, - 'char' => $char + 'char' => $char, + 'content' => $_POST['content'] ]); ?> diff --git a/vue/recap.php b/vue/recap.php new file mode 100644 index 0000000..ad7c557 --- /dev/null +++ b/vue/recap.php @@ -0,0 +1,16 @@ +render('head.html.twig', array( + 'title' => "Recap Quote", + 'style' => "../public/styles/styleSubmitQuote.css", + 'scripts' => array("../../public/script/theme-toggle.js") + )); + echo $twig->render('bandeau.html.twig'); + echo $twig -> render("recapSubmitQuote.html.twig", [' + content' => $_POST["content"], + 'character' => $_POST["character"], + 'source' => $_POST["src"] + ]); +?> \ No newline at end of file diff --git a/vue/templates/create.html.twig b/vue/templates/create.html.twig index 4eae2d1..4f85cc0 100644 --- a/vue/templates/create.html.twig +++ b/vue/templates/create.html.twig @@ -1,11 +1,22 @@
{% if src == true and char == true %} + + + {% elseif src == true %} + + {# a completer #} + + {% elseif char == true %} + + {# a completer #} + + {% endif %} {% if src == true %}

Source

@@ -15,16 +26,16 @@ - +
- + - +
- + {% endif %}