From cb5df46a941f0e2959404ee84d6971f2f46493c8 Mon Sep 17 00:00:00 2001 From: Ness Gaster Date: Mon, 6 Feb 2023 13:34:06 +0100 Subject: [PATCH] gateway List Response --- .../GatewayListResponseOfCandidate.php | 39 ++++++++++++++++++- Source/API/script/Gateway/GatewayResponse.php | 27 +++++++++---- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Source/API/script/Gateway/GatewayListResponseOfCandidate.php b/Source/API/script/Gateway/GatewayListResponseOfCandidate.php index 3898bad..7416537 100644 --- a/Source/API/script/Gateway/GatewayListResponseOfCandidate.php +++ b/Source/API/script/Gateway/GatewayListResponseOfCandidate.php @@ -44,8 +44,43 @@ class GatewayListResponseOfCandidate return $this->connection->getResults(); } - public function deleteListResponseOfCandidate(): void + public function deleteListResponseOfCandidate($id): void { - + $gatewayResponse = new GatewayResponse(); + + foreach ( $gatewayResponse->getResponsesIdByIdListCandidate($id) as $response){ + $gatewayResponse->deleteResponseById($response); + } + + $query = "DELETE FROM ListResponsesOfCandidate WHERE id = :id"; + $this->connection->executeQuery($query, array( + 'id' => array($id, PDO::PARAM_STR) + )); + } + + public function insertListResponsesOfCandidate($id, $answer, $category, $titleForm) + { + $gatewayResponse = new GatewayResponse(); + $gatewayQuestion = new GatewayQuestion(); + + $query = "INSERT INTO ListResponsesOfCandidate(date, titleForm) VALUES(:date, :titleForm)"; + $this->connection->executeQuery($query, array( + ':date' => array(date('d-m-y h:i:s'), PDO::PARAM_STR), + 'titleForm' => array($titleForm, PDO::PARAM_STR) + )); + + $idListQuestion = $this->connection->lastInsertId(); + + for($i = 0; $i < count($answer); $i++) + { + $idResponse = $gatewayResponse->insertResponse($gatewayQuestion->getQuestionContentById($id[$i]), $answer[$i], $category[$i]); + + + $query = "INSERT INTO Submit (responsesCandidate, response) VALUES(:responsesCandidate, :response)"; + $this->connection->executeQuery($query, array( + ':responsesCandidate' => array($idListQuestion, PDO::PARAM_STR), + 'response' => array($idResponse, PDO::PARAM_STR) + )); + } } } diff --git a/Source/API/script/Gateway/GatewayResponse.php b/Source/API/script/Gateway/GatewayResponse.php index e8c9fb8..a2191ed 100644 --- a/Source/API/script/Gateway/GatewayResponse.php +++ b/Source/API/script/Gateway/GatewayResponse.php @@ -16,12 +16,8 @@ class GatewayResponse public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId) { - $query = "SELECT r.* FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response"; - $this->connection->executeQuery($query, array( - ':id' => array($listResponsesOfCandidateId, PDO::PARAM_INT) - )); - $result = $this->connection->getResults(); + $result = $this->getResponsesIdByIdListCandidate($listResponsesOfCandidateId); $tab = []; foreach ($result as $row){ $tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']); @@ -30,6 +26,15 @@ class GatewayResponse return array($result, $tab); } + public function getResponsesIdByIdListCandidate(int $listResponsesOfCandidateId) + { + $query = "SELECT r.id FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response"; + $this->connection->executeQuery($query, array( + ':id' => array($listResponsesOfCandidateId, PDO::PARAM_INT) + )); + return $this->connection->getResults(); + } + public function deleteResponseById(int $responseId): void { $query = "DELETE FROM Categorize WHERE response = :id"; @@ -48,7 +53,7 @@ class GatewayResponse )); } - public function insertResponse(string $content, string $question): int + public function insertResponse(string $content, string $question, array $category): void { $query = "INSERT INTO Response(content, question) VALUES (:content, :question)"; $this->connection->executeQuery($query, array( @@ -56,6 +61,14 @@ class GatewayResponse ':question' => array($question, PDO::PARAM_STR) )); - return $this->connection->lastInsertId(); + $idResponse = $this->connection->lastInsertId(); + + foreach ($category as $keyword){ + $query = "INSERT INTO Categorize (response, keyword) VALUES(:response, :keyword)"; + $this->connection->executeQuery($query, array( + ':response' => array($idResponse, PDO::PARAM_STR), + 'keyword' => array($keyword, PDO::PARAM_STR) + )); + } } } \ No newline at end of file