From f19398eb73f4a4e803bf4335c1798a547ac6cc48 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 1 Feb 2023 21:06:36 +0100 Subject: [PATCH] add question interface --- Source/Config/config.php | 1 + Source/Controller/ControllerAdmin.php | 6 +++ Source/Controller/FrontController.php | 2 +- Source/Model/ModelAdmin.php | 29 +++++++++++-- Source/Model/ModelCandidate.php | 2 +- Source/Views/HTML/admin.php | 60 +++++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 Source/Views/HTML/admin.php diff --git a/Source/Config/config.php b/Source/Config/config.php index a36c020..161d220 100644 --- a/Source/Config/config.php +++ b/Source/Config/config.php @@ -5,3 +5,4 @@ $rep = __DIR__ . '/../'; // Vues $views['form'] = 'Views/HTML/form.php'; +$views['admin'] = 'Views/HTML/admin.php'; diff --git a/Source/Controller/ControllerAdmin.php b/Source/Controller/ControllerAdmin.php index 0ac775d..f46df58 100644 --- a/Source/Controller/ControllerAdmin.php +++ b/Source/Controller/ControllerAdmin.php @@ -15,4 +15,10 @@ class ControllerAdmin { (new ModelAdmin())->createForm(); } + + public function goToAdminPage(): void + { + global $rep, $views; + require($rep.$views['admin']); + } } diff --git a/Source/Controller/FrontController.php b/Source/Controller/FrontController.php index 7e5155e..e1617d4 100644 --- a/Source/Controller/FrontController.php +++ b/Source/Controller/FrontController.php @@ -36,4 +36,4 @@ class FrontController exit(0); } -} \ No newline at end of file +} diff --git a/Source/Model/ModelAdmin.php b/Source/Model/ModelAdmin.php index 87f81b8..ac9f831 100644 --- a/Source/Model/ModelAdmin.php +++ b/Source/Model/ModelAdmin.php @@ -11,9 +11,32 @@ class ModelAdmin { public function addQuestion(): void { - $question = new ListBoxQuestion(array("Réponse1", "Réponse2", "Réponse3"), - "Quelle est votre réponse préférée ?", - array(array("Catégorie1.1", "Catégorie 1.2", "Catégorie1.3"), array("Catégorie2.1", "Catégorie 2.2"), array("Catégorie3")), 0); + $questionContent = $_POST['question']; + $type = $_POST['type']; + $responses = $_POST['responses']; + $categories = $_POST['categories']; + + $responses = explode(";", $responses); + array_pop($responses); + $categories = explode(";", $categories); + + $tmp = []; + foreach($categories as $category) + { + $tmp[] = explode(",", $category); + } + $categories = $tmp; + array_pop($categories); + + if(strcmp($type,"BusinessClass\TextQuestion") == 0) + { + $question = new $type($questionContent, 0); + } + else + { + $question = new $type($responses, $questionContent, $categories, 0); + } + $form = (new GatewayForm())->getForm(); if(!empty($form)) diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 635fdf9..164a6c7 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -44,7 +44,7 @@ class ModelCandidate for($i = 0; $i < count($questionsTab[0]); $i++) { - if(strcmp($questionsTab[0][$i]['type'], "TextQuestion") == 0) + if(strcmp($questionsTab[0][$i]['type'], "BusinessClass\TextQuestion") == 0) { $questions[] = new TextQuestion($questionsTab[0][$i]['content'], $questionsTab[0][$i]['id']); } diff --git a/Source/Views/HTML/admin.php b/Source/Views/HTML/admin.php new file mode 100644 index 0000000..995d87d --- /dev/null +++ b/Source/Views/HTML/admin.php @@ -0,0 +1,60 @@ + + + + + + + + + Formulaire de témoignage + + + + + + logo UCA +

Administration

+ +

Ajouter une question :

+
+ + +
+ + +

+ + +
+ + +

+ +
+ + +

+ +
+ + +

+ + +
+ + + +