diff --git a/Source/API/script/Gateway/GatewayKeyword.php b/Source/API/script/Gateway/GatewayKeyword.php index 5068a8d..37bd310 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 { @@ -14,20 +15,19 @@ class GatewayKeyword $this->connection = connect(); } - public function insertKeyword(Keyword $keyword) + public function insertKeyword(string $keyword) { - $query = "INSERT INTO Keyword(id, word) VALUES(:id, :word)"; + $query = "INSERT INTO Keyword(word) VALUES(:word)"; $this->connection->executeQuery($query, array( - ':id' => array($keyword->getId(), PDO::PARAM_INT), - ':word' => array($keyword->getWord(), PDO::PARAM_INT) + ':word' => array($keyword, PDO::PARAM_STR) )); } - public function deleteKeyword(Keyword $keyword) + public function deleteKeyword(string $keyword) { - $query = "DELETE FROM Keyword WHERE id = :id"; + $query = "DELETE FROM Keyword WHERE word = :word"; $this->connection->executeQuery($query, array( - ':id' => array($keyword->getId(), PDO::PARAM_INT) + ':word' => array($keyword, PDO::PARAM_STR) )); } @@ -38,4 +38,22 @@ class GatewayKeyword return $this->connection->getResults(); } + + public function getKeywordsContentByReference(int $id): array + { + $query = "SELECT k.* FROM Keyword k, Reference r + WHERE k.word = r.keyword AND r.possibleResponse = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($id, PDO::PARAM_STR) + )); + + + $tab = []; + foreach ($this->connection->getResults() as $result) + { + $tab[] = $result["word"]; + } + + return $tab; + } } \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayResponse.php b/Source/API/script/Gateway/GatewayResponse.php index a2191ed..4c4b921 100644 --- a/Source/API/script/Gateway/GatewayResponse.php +++ b/Source/API/script/Gateway/GatewayResponse.php @@ -14,7 +14,7 @@ class GatewayResponse $this->connection = connect(); } - public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId) + public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId): array { $result = $this->getResponsesIdByIdListCandidate($listResponsesOfCandidateId); @@ -26,7 +26,7 @@ class GatewayResponse return array($result, $tab); } - public function getResponsesIdByIdListCandidate(int $listResponsesOfCandidateId) + public function getResponsesIdByIdListCandidate(int $listResponsesOfCandidateId): array { $query = "SELECT r.id FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response"; $this->connection->executeQuery($query, array( @@ -53,7 +53,7 @@ class GatewayResponse )); } - public function insertResponse(string $content, string $question, array $category): void + public function insertResponse(string $content, string $question, array $category): int { $query = "INSERT INTO Response(content, question) VALUES (:content, :question)"; $this->connection->executeQuery($query, array( @@ -70,5 +70,7 @@ class GatewayResponse 'keyword' => array($keyword, PDO::PARAM_STR) )); } + + return $idResponse; } } \ No newline at end of file diff --git a/Source/Model/FactoryQuestion.php b/Source/Model/FactoryQuestion.php index 1192df1..1e54e4b 100644 --- a/Source/Model/FactoryQuestion.php +++ b/Source/Model/FactoryQuestion.php @@ -10,24 +10,28 @@ class FactoryQuestion extends Factory public function create(array $results): array { $questions = []; - for($i = 0; $i < count($results[0]); $i++) + if($results[0] != null) { - if(strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0) + for($i = 0; $i < count($results[0]); $i++) { - $questions[] = new TextQuestion($results[0][$i]['content'], $results[0][$i]['id']); - } - else - { - $possiblesResponses = $results[1][$i]; - $content = $results[0][$i]['content']; + if(strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0) + { + $questions[] = new TextQuestion($results[0][$i]['content'], $results[0][$i]['id']); + } + else + { + $possiblesResponses = $results[1][$i]; + $content = $results[0][$i]['content']; - $categories = $results[2][$i]; + $categories = $results[2][$i]; - $id = $results[0][$i]['id']; + $id = $results[0][$i]['id']; - $questions[] = new $results[0][$i]['type']($possiblesResponses, $content, $categories, $id); + $questions[] = new $results[0][$i]['type']($possiblesResponses, $content, $categories, $id); + } } } + return $questions; } } diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 80df2f2..4dbe3c9 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -4,6 +4,7 @@ namespace Model; use API\script\Gateway\GatewayForm; use API\script\Gateway\GatewayQuestion; +use API\script\Gateway\GatewayResponse; use BusinessClass\TextQuestion; class ModelCandidate @@ -35,10 +36,7 @@ class ModelCandidate var_dump($category); echo "

"; - for($i = 0; $i < count($answer); $i++) - { - // (new GatewayResponse())->insertResponse($id[$i], $answer[$i], $category[$i]); - } + (new GatewayResponse())->insertResponse($id, $answer, $category); } public function getForm(): string