From 43a09cf6cf45afe7ce0ce8145874d88f51322052 Mon Sep 17 00:00:00 2001 From: Ness Gaster Date: Thu, 2 Feb 2023 10:13:42 +0100 Subject: [PATCH 1/3] gatewayForm updateTitleToForm updateDescriptionToForm deleteDescriptionToForm --- Source/API/script/Gateway/GatewayForm.php | 46 ++++++++++++++++--- Source/API/script/Gateway/GatewayKeyword.php | 4 +- Source/API/script/Gateway/GatewayQuestion.php | 2 +- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Source/API/script/Gateway/GatewayForm.php b/Source/API/script/Gateway/GatewayForm.php index 738dd7b..1154665 100644 --- a/Source/API/script/Gateway/GatewayForm.php +++ b/Source/API/script/Gateway/GatewayForm.php @@ -37,16 +37,23 @@ class GatewayForm return $this->connection->getResults(); } - public function assignKeywordToQuestion(string $keyword, string $response, int $idQuestion) + 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 { echo $keyword; $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_STR), + ':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)"; @@ -56,11 +63,11 @@ class GatewayForm )); } - public function deleteKeywordFromQuestion(string $keyword, string $response, Question $question) + 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_STR), + ':id' => array($question->getId(), PDO::PARAM_INT), ':response' => array($response, PDO::PARAM_STR) )); @@ -69,7 +76,34 @@ class GatewayForm $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) + ':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 = :description"; + $this->connection->executeQuery($query, array( + ':description' => array('', PDO::PARAM_STR), + ':id' => array($form->getId(), PDO::PARAM_INT) )); } } \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayKeyword.php b/Source/API/script/Gateway/GatewayKeyword.php index 5068a8d..75e4a44 100644 --- a/Source/API/script/Gateway/GatewayKeyword.php +++ b/Source/API/script/Gateway/GatewayKeyword.php @@ -14,7 +14,7 @@ class GatewayKeyword $this->connection = connect(); } - public function insertKeyword(Keyword $keyword) + public function insertKeyword(Keyword $keyword): void { $query = "INSERT INTO Keyword(id, word) VALUES(:id, :word)"; $this->connection->executeQuery($query, array( @@ -23,7 +23,7 @@ class GatewayKeyword )); } - public function deleteKeyword(Keyword $keyword) + public function deleteKeyword(Keyword $keyword): void { $query = "DELETE FROM Keyword WHERE id = :id"; $this->connection->executeQuery($query, array( diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index bfc9aac..aeffcdb 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -95,7 +95,7 @@ class GatewayQuestion )); } - public function getAllQuestions(string $idForm): array //revoie un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox + public function getAllQuestions(string $idForm): array //renvoie un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox { $query = "SELECT * FROM Question WHERE form = :form"; $this->connection->executeQuery($query, array( From 6ee05447aaf17b9b2aac176d176733720122d759 Mon Sep 17 00:00:00 2001 From: Ness Gaster Date: Sat, 4 Feb 2023 13:55:12 +0100 Subject: [PATCH 2/3] gateway response getByListCandidate insert delete --- Source/API/script/Gateway/GatewayKeyword.php | 32 ++++++++ .../GatewayListResponseOfCandidate.php | 51 ++++++++++++ .../Gateway/GatewayPossibleResponse.php | 37 +++++++++ Source/API/script/Gateway/GatewayQuestion.php | 78 ++++--------------- Source/API/script/Gateway/GatewayResponse.php | 61 +++++++++++++++ 5 files changed, 197 insertions(+), 62 deletions(-) create mode 100644 Source/API/script/Gateway/GatewayListResponseOfCandidate.php create mode 100644 Source/API/script/Gateway/GatewayPossibleResponse.php create mode 100644 Source/API/script/Gateway/GatewayResponse.php diff --git a/Source/API/script/Gateway/GatewayKeyword.php b/Source/API/script/Gateway/GatewayKeyword.php index 75e4a44..74b1d7a 100644 --- a/Source/API/script/Gateway/GatewayKeyword.php +++ b/Source/API/script/Gateway/GatewayKeyword.php @@ -4,6 +4,7 @@ namespace API\script\Gateway; use API\script\Config\Connection; use BusinessClass\Keyword; +use PDO; class GatewayKeyword { @@ -38,4 +39,35 @@ class GatewayKeyword return $this->connection->getResults(); } + + public function getKeywordsContentByReference(string $possibleResponseId): array + { + $query = "SELECT k.* FROM Keyword k, Reference r + WHERE k.word = r.keyword AND r.possibleResponse = :id"; + + return $this->getKeywordsContentByIdJonction($possibleResponseId, $query); + } + + public function getKeywordsContentByCategorieze(string $responseId): array + { + $query = "SELECT k.* FROM Keyword k, Categorize r + WHERE k.word = r.keyword AND r.reponse = :id"; + + return $this->getKeywordsContentByIdJonction($responseId, $query); + } + + private function getKeywordsContentByIdJonction(string $id, string $query): array + { + $this->connection->executeQuery($query, array( + ':id' => array($id, PDO::PARAM_INT) + )); + + $tabTmp = []; + foreach ($this->connection->getResults() as $keywords) + { + $tabTmp[] = $keywords["word"]; + } + return $tabTmp; + } + } \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayListResponseOfCandidate.php b/Source/API/script/Gateway/GatewayListResponseOfCandidate.php new file mode 100644 index 0000000..3898bad --- /dev/null +++ b/Source/API/script/Gateway/GatewayListResponseOfCandidate.php @@ -0,0 +1,51 @@ +connection = connect(); + } + + public function getDetailsListResponsesOfCandidate(int $idListResponse) + { + $gatewayResponse = new GatewayResponse(); + $gatewayKeyword = new GatewayKeyword(); + $tabKeywords = []; + + $query = "SELECT * FROM ListResponsesOfCandidate WHERE id = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($idListResponse, PDO::PARAM_INT) + )); + + $questionList = $this->connection->getResults()[0]; + + $responses = $gatewayResponse->getResponsesByIdListCandidate($questionList['id']); + + foreach ($responses as $row) { + $tabKeywords[] = $gatewayKeyword->getKeywordsContentByCategorieze($row['id']); + } + + return array($questionList, $responses, $tabKeywords); + } + + public function getAllListResponsesOfCandidate(): array + { + $query = "SELECT * FROM ListResponsesOfCandidate"; + $this->connection->executeQuery($query); + + return $this->connection->getResults(); + } + + public function deleteListResponseOfCandidate(): void + { + + } +} diff --git a/Source/API/script/Gateway/GatewayPossibleResponse.php b/Source/API/script/Gateway/GatewayPossibleResponse.php new file mode 100644 index 0000000..6aa3c73 --- /dev/null +++ b/Source/API/script/Gateway/GatewayPossibleResponse.php @@ -0,0 +1,37 @@ +connection = connect(); + } + + public function getPossibleResponseByQuestion(string $idQuestion): array + { + $query = "SELECT pr.* FROM Propose p, PossibleResponse pr + WHERE p.question = :questionId AND p.possibleResponse = pr.id"; + $this->connection->executeQuery($query, array( + ':questionId' => array($idQuestion, PDO::PARAM_INT) + )); + + return $this->connection->getResults(); + } + + public function insertPossibleResponse(string $contentPossibleResponse): int + { + $query = "INSERT INTO PossibleResponse(content) VALUES(:content)"; + $this->connection->executeQuery($query, array( + ':content' => array($contentPossibleResponse, PDO::PARAM_STR) + )); + + return $this->connection->lastInsertId(); + } +} \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index bbb083a..6c2866d 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -19,6 +19,8 @@ class GatewayQuestion public function insertQuestion(Question $question, int $idForm): void { + $gatewayPossibleResponse = new GatewayPossibleResponse(); + $query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)"; $this->connection->executeQuery($query, array( ':content' => array($question->getContent(), PDO::PARAM_STR), @@ -33,12 +35,7 @@ class GatewayQuestion for($i = 0; $i < count($listPossibleResponse); $i++){ - $query = "INSERT INTO PossibleResponse(content) VALUES(:content)"; - $this->connection->executeQuery($query, array( - ':content' => array($listPossibleResponse[$i], PDO::PARAM_STR) - )); - - $idPossibleResponse = $this->connection->lastInsertId(); + $idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($listPossibleResponse[$i]); $query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)"; $this->connection->executeQuery($query, array( @@ -103,40 +100,22 @@ class GatewayQuestion )); $listQuestions = $this->connection->getResults(); - $possibleResponses = []; $possibleResponsesContent = []; $keywordsResponses = []; + $gatewayKeyword = new GatewayKeyword(); + $gatewayPossibleResponse = new GatewayPossibleResponse(); if(!empty($listQuestions)) { for ($i = 0; $i < count($listQuestions); $i++) { if ($listQuestions[$i]["type"] != "BusinessClass/TextQuestion") { - - $query = "SELECT pr.* FROM Propose p, PossibleResponse pr - WHERE p.question = :questionId AND p.possibleResponse = pr.id"; - $this->connection->executeQuery($query, array( - ':questionId' => array($listQuestions[$i]["id"], PDO::PARAM_INT) - )); - - $possibleResponses[] = $this->connection->getResults(); - + $possibleResponses = $gatewayPossibleResponse->getPossibleResponseByQuestion($listQuestions[$i]["id"]); //$this->connection->getResults(); $tmpTabKeyword = []; $tmpTabPossibleResponse = []; - foreach ($possibleResponses[$i] as $row){ - $query = "SELECT k.* FROM Keyword k, Reference r - WHERE k.word = r.keyword AND r.possibleResponse = :id"; - $this->connection->executeQuery($query, array( - ':id' => array($row["id"], PDO::PARAM_INT) - )); - - $tabTmp = []; - foreach ($this->connection->getResults() as $keywords) - { - $tabTmp[] = $keywords["word"]; - } - $tmpTabKeyword[] = $tabTmp; + foreach ($possibleResponses as $row){ + $tmpTabKeyword[] = $gatewayKeyword->getKeywordsContentByReference($row["id"]); $tmpTabPossibleResponse[] = $row["content"]; } @@ -151,40 +130,15 @@ class GatewayQuestion return array($listQuestions, $possibleResponsesContent, $keywordsResponses); } return array(); + } + public function getQuestionContentById(string $id): string + { + $query = "SELECT content FROM Question WHERE id = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($id, PDO::PARAM_INT) + )); - /* - if(!empty($resultQuestion)) - { - for ($i=0; $i < count($resultQuestion); $i++) - { - if($resultQuestion[$i]["type"]!="BusinessClass/TextQuestion") - { - $tmpTab = []; - foreach ($possibleResponse[$i] as $row){ - $query = "SELECT k.* FROM Keyword k, Reference r - WHERE k.word = r.keyword AND r.possibleResponse = :id"; - $this->connection->executeQuery($query, array( - ':id' => array($row["id"], PDO::PARAM_INT) - )); - - $tmpTab[] = $this->connection->getResults(); - - var_dump($tmpTab); - - $possibleResponsesContent[] = $row["content"]; - } - $keywordResponse[] = $tmpTab["word"]; - } - else{ - $possibleResponse[] = null; - $keywordResponse[] = null; - } - } - return array($resultQuestion, $possibleResponsesContent, $keywordResponse); - } - return array(); - - */ + return $this->connection->getResults()[0][0]; } } \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayResponse.php b/Source/API/script/Gateway/GatewayResponse.php new file mode 100644 index 0000000..e8c9fb8 --- /dev/null +++ b/Source/API/script/Gateway/GatewayResponse.php @@ -0,0 +1,61 @@ +connection = connect(); + } + + 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(); + $tab = []; + foreach ($result as $row){ + $tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']); + } + + return array($result, $tab); + } + + public function deleteResponseById(int $responseId): void + { + $query = "DELETE FROM Categorize WHERE response = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($responseId, PDO::PARAM_INT) + )); + + $query = "DELETE FROM Submit WHERE response = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($responseId, PDO::PARAM_INT) + )); + + $query = "DELETE FROM Response WHERE id = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($responseId, PDO::PARAM_INT) + )); + } + + public function insertResponse(string $content, string $question): int + { + $query = "INSERT INTO Response(content, question) VALUES (:content, :question)"; + $this->connection->executeQuery($query, array( + ':content' => array($content, PDO::PARAM_STR), + ':question' => array($question, PDO::PARAM_STR) + )); + + return $this->connection->lastInsertId(); + } +} \ No newline at end of file From cb5df46a941f0e2959404ee84d6971f2f46493c8 Mon Sep 17 00:00:00 2001 From: Ness Gaster Date: Mon, 6 Feb 2023 13:34:06 +0100 Subject: [PATCH 3/3] 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