From 22f7ea87fd5bfb54770f9ce736ce630b7693e0e1 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 2 Feb 2023 14:35:45 +0100 Subject: [PATCH] User can submit a form, and admin can add keywords --- Source/API/script/Gateway/GatewayKeyword.php | 14 ++--- Source/BusinessClass/CheckBoxQuestion.php | 3 +- Source/BusinessClass/ListBoxQuestion.php | 7 +-- Source/Controller/ControllerAdmin.php | 5 ++ Source/Model/ModelAdmin.php | 7 +++ Source/Model/ModelCandidate.php | 54 ++++++++++++-------- Source/Views/HTML/admin.php | 12 ++++- 7 files changed, 68 insertions(+), 34 deletions(-) diff --git a/Source/API/script/Gateway/GatewayKeyword.php b/Source/API/script/Gateway/GatewayKeyword.php index 5068a8d..969ece6 100644 --- a/Source/API/script/Gateway/GatewayKeyword.php +++ b/Source/API/script/Gateway/GatewayKeyword.php @@ -4,6 +4,7 @@ namespace API\script\Gateway; use API\script\Config\Connection; use BusinessClass\Keyword; +use PDO; class GatewayKeyword { @@ -14,20 +15,19 @@ class GatewayKeyword $this->connection = connect(); } - public function insertKeyword(Keyword $keyword) + public function insertKeyword(string $word): void { - $query = "INSERT INTO Keyword(id, word) VALUES(:id, :word)"; + $query = "INSERT INTO Keyword(word) VALUES(:word)"; $this->connection->executeQuery($query, array( - ':id' => array($keyword->getId(), PDO::PARAM_INT), - ':word' => array($keyword->getWord(), PDO::PARAM_INT) + ':word' => array($word, PDO::PARAM_STR) )); } - public function deleteKeyword(Keyword $keyword) + public function deleteKeyword(string $word): void { - $query = "DELETE FROM Keyword WHERE id = :id"; + $query = "DELETE FROM Keyword WHERE word = :word"; $this->connection->executeQuery($query, array( - ':id' => array($keyword->getId(), PDO::PARAM_INT) + ':word' => array($word, PDO::PARAM_STR) )); } diff --git a/Source/BusinessClass/CheckBoxQuestion.php b/Source/BusinessClass/CheckBoxQuestion.php index e1276b1..23676f6 100644 --- a/Source/BusinessClass/CheckBoxQuestion.php +++ b/Source/BusinessClass/CheckBoxQuestion.php @@ -22,6 +22,7 @@ class CheckBoxQuestion extends BoxQuestion public function printStrategy(): string { + $id = $this->getId(); $content = $this->getContent(); $possibleResponses = $this->getPossibleResponses(); $categories = $this->getCategories(); @@ -31,7 +32,7 @@ class CheckBoxQuestion extends BoxQuestion for($i = 0; $i < count($possibleResponses); $i++) { - $categoriesSplit = $possibleResponses[$i]."||"; + $categoriesSplit = $id."#".$possibleResponses[$i]."||"; foreach ($categories[$i] as $category) { $categoriesSplit.= $category."_"; diff --git a/Source/BusinessClass/ListBoxQuestion.php b/Source/BusinessClass/ListBoxQuestion.php index 7a6dddd..2def8bf 100644 --- a/Source/BusinessClass/ListBoxQuestion.php +++ b/Source/BusinessClass/ListBoxQuestion.php @@ -22,6 +22,7 @@ class ListBoxQuestion extends BoxQuestion public function printStrategy(): string { + $id = $this->getId(); $content = $this->getContent(); $possibleResponses = $this->getPossibleResponses(); $categories = $this->getCategories(); @@ -32,12 +33,12 @@ class ListBoxQuestion extends BoxQuestion for($i = 0; $i < count($possibleResponses); $i++) { - $categoriesAndResponsesSplit = $possibleResponses[$i]."_"; + $categoriesSplit = $id."#".$possibleResponses[$i]."||"; foreach ($categories[$i] as $category) { - $categoriesAndResponsesSplit.= $category."_"; + $categoriesSplit.= $category."_"; } - $html.= "\t\t\t\t\t\n"; + $html.= "\t\t\t\t\t\n"; } $html.= "\t\t\t\t \n"; diff --git a/Source/Controller/ControllerAdmin.php b/Source/Controller/ControllerAdmin.php index f46df58..3e67b59 100644 --- a/Source/Controller/ControllerAdmin.php +++ b/Source/Controller/ControllerAdmin.php @@ -21,4 +21,9 @@ class ControllerAdmin global $rep, $views; require($rep.$views['admin']); } + + public function addKeyword(): void + { + (new ModelAdmin())->addKeyword(); + } } diff --git a/Source/Model/ModelAdmin.php b/Source/Model/ModelAdmin.php index ac9f831..4c2934e 100644 --- a/Source/Model/ModelAdmin.php +++ b/Source/Model/ModelAdmin.php @@ -3,6 +3,7 @@ namespace Model; use API\script\Gateway\GatewayForm; +use API\script\Gateway\GatewayKeyword; use API\script\Gateway\GatewayQuestion; use BusinessClass\Form; use BusinessClass\ListBoxQuestion; @@ -53,4 +54,10 @@ class ModelAdmin (new GatewayForm())->insertForm($form); } } + + public function addKeyword(): void + { + $keyword = $_POST['keyword']; + (new GatewayKeyword())->insertKeyword($keyword); + } } diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 6b83fe0..078d02b 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -12,42 +12,47 @@ class ModelCandidate { $answersAndCategories = $_POST['answers']; - $answers = array(); + $id = []; + $answer = []; + $category = []; + foreach ($answersAndCategories as $answerAndCategory) { - $answer = explode("_", $answerAndCategory); - $answer = reset($answer); - $answers[] = $answer; + $idAndAnswer = explode("||", $answerAndCategory)[0]; + $id[] = explode("#", $idAndAnswer)[0]; + $answer[] = explode("#", $idAndAnswer)[1]; + + $categs = explode("||", $answerAndCategory)[1]; + $categs = explode("_", $categs); + array_pop($categs); + $category[] = $categs; + } + + var_dump($id); + echo "
"; + var_dump($answer); + echo "
"; + var_dump($category); + echo "

"; + + for($i = 0; $i < count($answer); $i++) + { + // (new GatewayResponse())->insertResponse($id[$i], $answer[$i], $category[$i]); } } public function getForm(): string { - /* - $title = "Candidature à un témoignage"; - $description = "Ce formulaire vous permet de candidater à un potentiel témoignage vidéo."; - $questions = array( - new TextQuestion("Décrivez-nous votre parcours en quelques lignes :"), - new ListBoxQuestion(array("Oui", "Non"), "Êtes-vous originaire de Clermont et ses alentours ? (- de 2 heures de trajet)", array(array("Clermont"), array("OrigineLointaine"))), - new ListBoxQuestion(array("BAC Général", "BAC Pro", "Étude supérieure"), "Quel étude avez-vous réalisé avant l'IUT?", array(array("Général"), array("Pro"), array("EtudSupp"))), - new CheckBoxQuestion(array("Mathématiques", "Web", "Mobile", "Gestion"), "Quels matières appréciez-vous ?", array(array("Maths", "Maths2", "Maths3"), array("Web"), array(""), array("Gestion", "Gestion2"))), - ); - $form = new Form($title, $description, $questions); - */ - - $form = (new GatewayForm())->getForm(); if(empty($form)) { return "PAS DE FORMULAIRE\n"; } - $title = $form[0]['title']; $description = $form[0]['description']; $questionsTab = (new GatewayQuestion())->getAllQuestions($form[0]['id']); - $questions = []; for($i = 0; $i < count($questionsTab[0]); $i++) @@ -75,16 +80,23 @@ class ModelCandidate
\n
\n"; - foreach ($questions as $question) { $html.= $question->printStrategy()."\n"; } - $html.= "\t\t\t\n + if(count($questions) > 0) + { + $html.= "\t\t\t\n \t\t\t \t\t
\n \t
\n"; + } + else + { + $html.= "\t\t\n +\t\n"; + } return $html; } diff --git a/Source/Views/HTML/admin.php b/Source/Views/HTML/admin.php index 995d87d..777e954 100644 --- a/Source/Views/HTML/admin.php +++ b/Source/Views/HTML/admin.php @@ -15,6 +15,14 @@ logo UCA

Administration

+

Ajouter une catégories :

+
+ + + + +
+

Ajouter une question :

@@ -26,8 +34,8 @@