connection = connect(); } public function insertForm(Form $form): void { if (empty($this->getForm())) { $query = "INSERT INTO Form(title, description) VALUES(:title, :desc)"; $this->connection->executeQuery($query, array( ':title' => array($form->getTitle(), PDO::PARAM_STR), ':desc' => array($form->getDescription(), PDO::PARAM_STR) )); } } public function getForm(): array { $query = "SELECT * FROM Form"; $this->connection->executeQuery($query); return $this->connection->getResults(); } public function deleteForm(Form $form): void { $query = "DELETE FROM Form WHERE id = :id"; $this->connection->executeQuery($query, array( ':id' => array($form->getId(), PDO::PARAM_INT) )); } public function assignKeywordToQuestion(string $keyword, string $response, int $idQuestion): void { $query = "SELECT pr.id FROM Propose p, PossibleResponse pr WHERE p.question = :id AND p.possibleResponse = pr.id AND pr.content = :response"; $this->connection->executeQuery($query, array( ':id' => array($idQuestion, PDO::PARAM_INT), ':response' => array($response, PDO::PARAM_STR) )); $idPossibleResponse = $this->connection->getResults()[0][0]; $query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)"; $this->connection->executeQuery($query, array( ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT), ':keyword' => array($keyword, PDO::PARAM_STR) )); } public function deleteKeywordFromQuestion(string $keyword, string $response, Question $question): void { $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_INT), ':response' => array($response, PDO::PARAM_STR) )); $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, PDO::PARAM_INT) )); } public function updateTitleToForm(string $title, Form $form): void { $query = "UPDATE Form SET title = :title WHERE id = :id"; $this->connection->executeQuery($query, array( ':title' => array($title, PDO::PARAM_STR), ':id' => array($form->getId(), PDO::PARAM_INT) )); } public function updateDescriptionToForm(string $description, Form $form): void { $query = "UPDATE Form SET title = :title WHERE description = :description"; $this->connection->executeQuery($query, array( ':description' => array($description, PDO::PARAM_STR), ':id' => array($form->getId(), PDO::PARAM_INT) )); } public function deleteDescriptionToForm(Form $form): void { $query = "UPDATE Form SET title = :title WHERE description = :descript"; $this->connection->executeQuery($query, array( ':descript' => array('', PDO::PARAM_STR), ':id' => array($form->getId(), PDO::PARAM_INT) )); } }