diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index d110df0..80093cc 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -17,7 +17,19 @@ class GatewayQuestion $this->connection = connect(); } - public function insertQuestion(Question $question, int $idForm): void + public function addQuestion(Question $question, int $idForm): int + { + $query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)"; + $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) + )); + + return $this->connection->lastInsertId(); + } + + public function insertQuestion(Question $question, int $idForm): int { $gatewayPossibleResponse = new GatewayPossibleResponse(); @@ -31,6 +43,7 @@ class GatewayQuestion $idQuestion = $this->connection->lastInsertId(); if (get_class($question) != TextQuestion::class) { + var_dump($question); $listPossibleResponse = $question->getPossibleResponses(); for ($i = 0; $i < count($listPossibleResponse); $i++) { @@ -51,6 +64,7 @@ class GatewayQuestion } } + return $idQuestion; } public function deleteQuestion(Question $question): void diff --git a/Source/BusinessClass/BoxQuestion.php b/Source/BusinessClass/BoxQuestion.php index 74b260f..8a16276 100644 --- a/Source/BusinessClass/BoxQuestion.php +++ b/Source/BusinessClass/BoxQuestion.php @@ -20,7 +20,7 @@ abstract class BoxQuestion extends Question $this->possibleResponses = $args[0]; break; case 2: - parent::__construct($args[3], $args[1]); + parent::__construct($args[0], $args[1]); break; default: break; diff --git a/Source/BusinessClass/ListBoxQuestion.php b/Source/BusinessClass/ListBoxQuestion.php index 750c240..00f81da 100644 --- a/Source/BusinessClass/ListBoxQuestion.php +++ b/Source/BusinessClass/ListBoxQuestion.php @@ -14,7 +14,7 @@ class ListBoxQuestion extends BoxQuestion parent::__construct($args[0], $args[2], $args[3], $args[1]); break; case 2: - parent::__construct($args[3], $args[1]); + parent::__construct($args[0], $args[1]); break; default: break; diff --git a/Source/Controller/ControllerAdmin.php b/Source/Controller/ControllerAdmin.php index 400b2e9..7f41975 100644 --- a/Source/Controller/ControllerAdmin.php +++ b/Source/Controller/ControllerAdmin.php @@ -8,10 +8,13 @@ class ControllerAdmin { public function addQuestion(): void { - $id = $_POST['id']; - (new ModelAdmin())->addQuestion($id); - } + $idQuestion = (new ModelAdmin())->addQuestion(); + if($idQuestion != -1) + $_POST['idQuestion'] = $idQuestion; + else + $_POST['idQuestion'] = null; + } public function chooseQuestionAndType(): void { @@ -24,8 +27,6 @@ class ControllerAdmin 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 fd4ff79..605605a 100644 --- a/Source/Model/ModelAdmin.php +++ b/Source/Model/ModelAdmin.php @@ -40,18 +40,19 @@ class ModelAdmin } }*/ - public function addQuestion(int|null $id): void + public function addQuestion(): int { $questionContent = $_POST['question']; $type = $_POST['type']; - $question = new $type($questionContent, 0); - + $question = new $type(0, $questionContent); $form = (new GatewayForm())->getForm(); if (!empty($form)) { - (new GatewayQuestion())->insertQuestion($question, $form[0]['id']); + return (new GatewayQuestion())->addQuestion($question, $form[0]['id']); } + + return -1; } public function createForm(): void diff --git a/Source/Views/HTML/admin.php b/Source/Views/HTML/admin.php index 5aff60b..0a5fee2 100644 --- a/Source/Views/HTML/admin.php +++ b/Source/Views/HTML/admin.php @@ -108,7 +108,7 @@