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 969ece6..5068a8d 100644 --- a/Source/API/script/Gateway/GatewayKeyword.php +++ b/Source/API/script/Gateway/GatewayKeyword.php @@ -4,7 +4,6 @@ namespace API\script\Gateway; use API\script\Config\Connection; use BusinessClass\Keyword; -use PDO; class GatewayKeyword { @@ -15,19 +14,20 @@ class GatewayKeyword $this->connection = connect(); } - public function insertKeyword(string $word): void + public function insertKeyword(Keyword $keyword) { - $query = "INSERT INTO Keyword(word) VALUES(:word)"; + $query = "INSERT INTO Keyword(id, word) VALUES(:id, :word)"; $this->connection->executeQuery($query, array( - ':word' => array($word, PDO::PARAM_STR) + ':id' => array($keyword->getId(), PDO::PARAM_INT), + ':word' => array($keyword->getWord(), PDO::PARAM_INT) )); } - public function deleteKeyword(string $word): void + public function deleteKeyword(Keyword $keyword) { - $query = "DELETE FROM Keyword WHERE word = :word"; + $query = "DELETE FROM Keyword WHERE id = :id"; $this->connection->executeQuery($query, array( - ':word' => array($word, PDO::PARAM_STR) + ':id' => array($keyword->getId(), PDO::PARAM_INT) )); } diff --git a/Source/API/script/Gateway/GatewayListResponseOfCandidate.php b/Source/API/script/Gateway/GatewayListResponseOfCandidate.php new file mode 100644 index 0000000..7416537 --- /dev/null +++ b/Source/API/script/Gateway/GatewayListResponseOfCandidate.php @@ -0,0 +1,86 @@ +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($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/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 121f39d..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( @@ -95,7 +92,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( @@ -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..a2191ed --- /dev/null +++ b/Source/API/script/Gateway/GatewayResponse.php @@ -0,0 +1,74 @@ +connection = connect(); + } + + public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId) + { + + $result = $this->getResponsesIdByIdListCandidate($listResponsesOfCandidateId); + $tab = []; + foreach ($result as $row){ + $tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']); + } + + 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"; + $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, array $category): void + { + $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) + )); + + $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