diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index 80093cc..643c7b8 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -29,39 +29,21 @@ class GatewayQuestion return $this->connection->lastInsertId(); } - public function insertQuestion(Question $question, int $idForm): int + public function insertResponseInQuestion(string $response, array $categories, int $idQuestion): int { $gatewayPossibleResponse = new GatewayPossibleResponse(); + $idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($response); - $query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)"; + $query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)"; $this->connection->executeQuery($query, array( - ':content' => array($question->getContent(), PDO::PARAM_STR), - ':type' => array(get_class($question), PDO::PARAM_STR), - ':form' => array($idForm, PDO::PARAM_INT) + ':question' => array($idQuestion, PDO::PARAM_INT), + ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT) )); - $idQuestion = $this->connection->lastInsertId(); - - if (get_class($question) != TextQuestion::class) { - var_dump($question); - $listPossibleResponse = $question->getPossibleResponses(); - - for ($i = 0; $i < count($listPossibleResponse); $i++) { - $idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($listPossibleResponse[$i]); - - $query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)"; - $this->connection->executeQuery($query, array( - ':question' => array($idQuestion, PDO::PARAM_INT), - ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT) - )); - - - foreach ($question->getCategories()[$i] as $keyword) { - $gatewayForm = new GatewayForm(); - $gatewayForm->assignKeywordToQuestion($keyword, $listPossibleResponse[$i], $idQuestion); - } - } + foreach ($categories as $keyword) { + $gatewayForm = new GatewayForm(); + $gatewayForm->assignKeywordToQuestion($keyword, $response, $idQuestion); } return $idQuestion; diff --git a/Source/BusinessClass/BoxQuestion.php b/Source/BusinessClass/BoxQuestion.php index 8a16276..0d77a56 100644 --- a/Source/BusinessClass/BoxQuestion.php +++ b/Source/BusinessClass/BoxQuestion.php @@ -14,7 +14,7 @@ abstract class BoxQuestion extends Question $args = func_get_args(); switch($ctp) { - case 5: + case 4: parent::__construct($args[3], $args[1]); $this->categories = $args[2]; $this->possibleResponses = $args[0]; diff --git a/Source/BusinessClass/CheckBoxQuestion.php b/Source/BusinessClass/CheckBoxQuestion.php index 391ee5c..389da16 100644 --- a/Source/BusinessClass/CheckBoxQuestion.php +++ b/Source/BusinessClass/CheckBoxQuestion.php @@ -10,10 +10,8 @@ class CheckBoxQuestion extends BoxQuestion $args = func_get_args(); switch($ctp) { - case 5: - parent::__construct($args[3], $args[1]); - $this->categories = $args[2]; - $this->possibleResponses = $args[0]; + case 4: + parent::__construct($args[0], $args[1], $args[2], $args[3]); break; case 2: parent::__construct($args[3], $args[1]); diff --git a/Source/BusinessClass/ListBoxQuestion.php b/Source/BusinessClass/ListBoxQuestion.php index 00f81da..c01c514 100644 --- a/Source/BusinessClass/ListBoxQuestion.php +++ b/Source/BusinessClass/ListBoxQuestion.php @@ -11,7 +11,7 @@ class ListBoxQuestion extends BoxQuestion switch($ctp) { case 4: - parent::__construct($args[0], $args[2], $args[3], $args[1]); + parent::__construct($args[0], $args[1], $args[2], $args[3]); break; case 2: parent::__construct($args[0], $args[1]); diff --git a/Source/Config/config.php b/Source/Config/config.php index 7d11c4b..82ca409 100644 --- a/Source/Config/config.php +++ b/Source/Config/config.php @@ -6,6 +6,7 @@ $rep = __DIR__ . '/../'; $views['form'] = 'Views/HTML/form.php'; $views['admin'] = 'Views/HTML/admin.php'; $views['possibleResponsesForm'] = 'Views/HTML/possibleResponsesForm.php'; +$views['continue'] = 'Views/HTML/continue.php'; $googleApis = "https://fonts.googleapis.com"; $googleStatic = "https://fonts.gstatic.com"; diff --git a/Source/Controller/ControllerAdmin.php b/Source/Controller/ControllerAdmin.php index ff75502..e410c3b 100644 --- a/Source/Controller/ControllerAdmin.php +++ b/Source/Controller/ControllerAdmin.php @@ -20,7 +20,25 @@ class ControllerAdmin public function addResponse(): void { + (new ModelAdmin())->addResponse(); + global $rep, $views; + $idQuestion = $_POST['idQuestion']; + require_once($rep.$views['continue']); + } + + public function continueResponse(): void + { + global $rep, $views; + + $idQuestion = $_POST['idQuestion']; + $choose = $_POST['choose']; + if($choose == "Oui") { + require_once($rep.$views['possibleResponsesForm']); + } + else { + require_once($rep.$views['']); + } } public function createForm(): void diff --git a/Source/Model/ModelAdmin.php b/Source/Model/ModelAdmin.php index 605605a..9c54a69 100644 --- a/Source/Model/ModelAdmin.php +++ b/Source/Model/ModelAdmin.php @@ -55,6 +55,14 @@ class ModelAdmin return -1; } + public function addResponse(): void + { + $idQuestion = $_POST['idQuestion']; + $response = $_POST['response']; + $categories = $_POST['categories']; + (new GatewayQuestion())->insertResponseInQuestion($response, $categories, $idQuestion); + } + public function createForm(): void { if (empty((new GatewayForm())->getForm())) { diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 1f8ab2c..0bacf37 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -42,6 +42,7 @@ class ModelCandidate $questions = Factory::getBuiltObjects($questionsTab, "Question"); + $html = "

$title

\n

$description

\n diff --git a/Source/Views/HTML/continue.php b/Source/Views/HTML/continue.php new file mode 100644 index 0000000..d5f2673 --- /dev/null +++ b/Source/Views/HTML/continue.php @@ -0,0 +1,85 @@ + + + + + + + + + + Formulaire de témoignage + + + + + + +logo UCA +

Administration

+ + + +
+

Continuer d'ajouter des possibilités de réponses ?

+
+ + + + + +
+
+ + + + diff --git a/Source/Views/HTML/possibleResponsesForm.php b/Source/Views/HTML/possibleResponsesForm.php index 9284377..b1a53e5 100644 --- a/Source/Views/HTML/possibleResponsesForm.php +++ b/Source/Views/HTML/possibleResponsesForm.php @@ -70,10 +70,8 @@ -->
-
- -

Votre question :