connection = connect(); } public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId): array { $result = $this->getResponsesIdByIdListCandidate($listResponsesOfCandidateId); $tab = []; foreach ($result as $row) { $tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']); } return array($result, $tab); } 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( ':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 $questionContent, array $category): int { $query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)"; $this->connection->executeQuery($query, array( ':content' => array($content, PDO::PARAM_STR), ':questionContent' => array($questionContent, 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) )); } return $idResponse; } }