From b1a080252493b99636d4697c66b2e139a5d64c91 Mon Sep 17 00:00:00 2001 From: Ness Gaster Date: Mon, 30 Jan 2023 23:20:00 +0100 Subject: [PATCH] Gateway Form assignKeywordToQuestion deleteKeywordFromQuestion --- Source/API/script/Gateway/GatewayForm.php | 55 +++++++++++++++++++ Source/API/script/Gateway/GatewayQuestion.php | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 Source/API/script/Gateway/GatewayForm.php diff --git a/Source/API/script/Gateway/GatewayForm.php b/Source/API/script/Gateway/GatewayForm.php new file mode 100644 index 0000000..208a3a7 --- /dev/null +++ b/Source/API/script/Gateway/GatewayForm.php @@ -0,0 +1,55 @@ +connection = $connection; + } + + public function assignKeywordToQuestion(Keyword $keyword, string $response, int $idQuestion) + { + $query = "SELECT pr.id FROM Propose p, PossibleResponse r WHERE p.question = :id AND p.possibleResponse = pr.id AND pr.content = :response"; + $this->connection->executeQuery($query, array( + ':id' => array($idQuestion, PDO::PARAM_STR), + ':response' => array($response, PDO::PARAM_STR) + )); + $this->connection->executeQuery(); + + $idPossibleResponse = $this->connection->getResults()[0][0]; + + + $query = "INSERT INTO Reference(id, word) VALUES(:id, :word)"; + $this->connection->executeQuery($query, array( + ':idResponse' => array($idPossibleResponse, PDO::PARAM_INT), + ':idKeword' => array($keyword->getId(), PDO::PARAM_INT) + )); + $this->connection->executeQuery(); + } + + public function deleteKeywordFromQuestion(Keyword $keyword, string $response, Question $question) + { + $query = "SELECT pr.id FROM Propose p, PossibleResponse r WHERE p.question = :id AND p.possibleResponse = pr.id AND pr.content = :response"; + $this->connection->executeQuery($query, array( + ':id' => array($question->getId(), PDO::PARAM_STR), + ':response' => array($response, PDO::PARAM_STR) + )); + $this->connection->executeQuery(); + + $idPossibleResponse = $this->connection->getResults()[0][0]; + + $query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeword"; + $this->connection->executeQuery($query, array( + ':idResponse' => array($idPossibleResponse, PDO::PARAM_INT), + ':idKeword' => array($keyword->getId(), PDO::PARAM_INT) + )); + $this->connection->executeQuery(); + } +} \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index d21a3a5..dc87851 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -53,7 +53,7 @@ class GatewayQuestion foreach ($question->getCategories()[$i] as $keyword){ $gatewayForm = new GatewayForm($this->connection); - $gatewayForm->assignKeywordToQuestion($keyword, $idQuestion); + $gatewayForm->assignKeywordToQuestion($keyword, $listPossibleResponse[$i], $idQuestion); } } }