diff --git a/Source/BusinessClass/BoxQuestion.php b/Source/BusinessClass/BoxQuestion.php index cc82dfe..74b260f 100644 --- a/Source/BusinessClass/BoxQuestion.php +++ b/Source/BusinessClass/BoxQuestion.php @@ -7,19 +7,27 @@ abstract class BoxQuestion extends Question private array $possibleResponses; private array $categories; - /** - * @param array $possibleResponses - * @param string $content - * @param array $categories - * @param int $id - */ - public function __construct(array $possibleResponses, string $content, array $categories, int $id) + + public function __construct() { - parent::__construct($id, $content); - $this->categories = $categories; - $this->possibleResponses = $possibleResponses; + $ctp = func_num_args(); + $args = func_get_args(); + switch($ctp) + { + case 5: + parent::__construct($args[3], $args[1]); + $this->categories = $args[2]; + $this->possibleResponses = $args[0]; + break; + case 2: + parent::__construct($args[3], $args[1]); + break; + default: + break; + } } + abstract public function responseStrategy(); abstract public function printStrategy(): string; diff --git a/Source/BusinessClass/CheckBoxQuestion.php b/Source/BusinessClass/CheckBoxQuestion.php index 42a8251..391ee5c 100644 --- a/Source/BusinessClass/CheckBoxQuestion.php +++ b/Source/BusinessClass/CheckBoxQuestion.php @@ -4,6 +4,25 @@ namespace BusinessClass; class CheckBoxQuestion extends BoxQuestion { + public function __construct() + { + $ctp = func_num_args(); + $args = func_get_args(); + switch($ctp) + { + case 5: + parent::__construct($args[3], $args[1]); + $this->categories = $args[2]; + $this->possibleResponses = $args[0]; + break; + case 2: + parent::__construct($args[3], $args[1]); + break; + default: + break; + } + } + public function responseStrategy(): void { echo "Implement responseStrategy() method."; diff --git a/Source/BusinessClass/ListBoxQuestion.php b/Source/BusinessClass/ListBoxQuestion.php index 186b179..750c240 100644 --- a/Source/BusinessClass/ListBoxQuestion.php +++ b/Source/BusinessClass/ListBoxQuestion.php @@ -4,6 +4,24 @@ namespace BusinessClass; class ListBoxQuestion extends BoxQuestion { + public function __construct() + { + $ctp = func_num_args(); + $args = func_get_args(); + switch($ctp) + { + case 4: + parent::__construct($args[0], $args[2], $args[3], $args[1]); + break; + case 2: + parent::__construct($args[3], $args[1]); + break; + default: + break; + } + } + + public function responseStrategy(): void { echo "Implement responseStrategy() method."; diff --git a/Source/Config/config.php b/Source/Config/config.php index ca79ae9..7d11c4b 100644 --- a/Source/Config/config.php +++ b/Source/Config/config.php @@ -5,6 +5,7 @@ $rep = __DIR__ . '/../'; // Vues $views['form'] = 'Views/HTML/form.php'; $views['admin'] = 'Views/HTML/admin.php'; +$views['possibleResponsesForm'] = 'Views/HTML/possibleResponsesForm.php'; $googleApis = "https://fonts.googleapis.com"; $googleStatic = "https://fonts.gstatic.com"; diff --git a/Source/Controller/ControllerAdmin.php b/Source/Controller/ControllerAdmin.php index e3e17ec..400b2e9 100644 --- a/Source/Controller/ControllerAdmin.php +++ b/Source/Controller/ControllerAdmin.php @@ -8,9 +8,24 @@ class ControllerAdmin { public function addQuestion(): void { - (new ModelAdmin())->addQuestion(); + $id = $_POST['id']; + (new ModelAdmin())->addQuestion($id); } + + public function chooseQuestionAndType(): void + { + global $rep, $views; + + $categories = (new ModelAdmin())->getCategories(); + $questionContent = $_POST['question']; + $type = $_POST['type']; + + require_once($rep.$views['possibleResponsesForm']); + } + + + public function createForm(): void { (new ModelAdmin())->createForm(); diff --git a/Source/Model/ModelAdmin.php b/Source/Model/ModelAdmin.php index e03db40..fd4ff79 100644 --- a/Source/Model/ModelAdmin.php +++ b/Source/Model/ModelAdmin.php @@ -9,7 +9,7 @@ use BusinessClass\Form; class ModelAdmin { - public function addQuestion(): void + /*public function addQuestion(int|null $id): void { $questionContent = $_POST['question']; $type = $_POST['type']; @@ -34,6 +34,20 @@ class ModelAdmin } + $form = (new GatewayForm())->getForm(); + if (!empty($form)) { + (new GatewayQuestion())->insertQuestion($question, $form[0]['id']); + } + }*/ + + public function addQuestion(int|null $id): void + { + $questionContent = $_POST['question']; + $type = $_POST['type']; + + $question = new $type($questionContent, 0); + + $form = (new GatewayForm())->getForm(); if (!empty($form)) { (new GatewayQuestion())->insertQuestion($question, $form[0]['id']); diff --git a/Source/Views/HTML/admin.php b/Source/Views/HTML/admin.php index a302d2f..5aff60b 100644 --- a/Source/Views/HTML/admin.php +++ b/Source/Views/HTML/admin.php @@ -101,6 +101,37 @@ + +
+ + +
+ @@ -112,6 +143,9 @@ const printQuestionButton = document.querySelector('#printQuestion'); printQuestionButton.addEventListener('click', printQuestion); + + const printFormQuestionButton = document.querySelector('#addNewQuestion'); + printFormQuestionButton.addEventListener('click', addQuestion); diff --git a/Source/Views/HTML/possibleResponsesForm.php b/Source/Views/HTML/possibleResponsesForm.php new file mode 100644 index 0000000..b5158e0 --- /dev/null +++ b/Source/Views/HTML/possibleResponsesForm.php @@ -0,0 +1,118 @@ + + + + + + + + + + Formulaire de témoignage + + + + + + +logo UCA +

Administration

+ + + +
+
+ +

Votre question :

+

+ + + +


+ +

+ + + + + +

+ + +
+
+ + + + + + + diff --git a/Source/Views/JS/form_question.js b/Source/Views/JS/form_question.js index d06f1c4..5c10b26 100644 --- a/Source/Views/JS/form_question.js +++ b/Source/Views/JS/form_question.js @@ -9,4 +9,17 @@ function printQuestion() { printQuestionButton.innerText = "Les questions ▲"; ul.style.visibility = "visible"; } +} + +function addQuestion() { + const printAddQuestionFormButton = document.querySelector('#addNewQuestion'); + const form = document.querySelector('#addQuestionForm'); + + if(printAddQuestionFormButton.innerText === "Ajouter une question ▲") { + printAddQuestionFormButton.innerText = "Ajouter une question ▼"; + form.style.visibility = "hidden"; + } else { + printAddQuestionFormButton.innerText = "Ajouter une question ▲"; + form.style.visibility = "visible"; + } } \ No newline at end of file