diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index ebf57fb..f8ed3b8 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -59,7 +59,40 @@ class GatewayQuestion } } - public function updateQuestion(Question $question){ + public function deleteQuestion(Question $question) + { + if(get_class($question) == BoxQuestion::class) { + $query = "DELETE FROM Propose WHERE question = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($question->getId(), PDO::PARAM_INT) + )); + $this->connection->executeQuery(); + + $listPossibleResponse = $question->getPossibleResponses(); + for ($i = 0; $i < count($listPossibleResponse); $i++){ + $query = "DELETE FROM Reference WHERE response = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT) + )); + $this->connection->executeQuery(); + + $query = "DELETE FROM PossibleResponse WHERE id = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT) + )); + $this->connection->executeQuery(); + } + } + + $query = "DELETE FROM Question WHERE id = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($question->getId(), PDO::PARAM_INT) + )); + $this->connection->executeQuery(); + } + + public function updateQuestion(Question $question) + { $query = "UPDATE Question SET content = :content, type = :type, form = :form WHERE id = :id"; $this->connection->executeQuery($query, array( ':content' => array($question->getContent(), PDO::PARAM_STR),