gateway List Response
continuous-integration/drone/push Build is passing Details

LoginModification
Ness Gaster 2 years ago
parent 6ee05447aa
commit cb5df46a94

@ -44,8 +44,43 @@ class GatewayListResponseOfCandidate
return $this->connection->getResults(); 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)
));
}
} }
} }

@ -16,12 +16,8 @@ class GatewayResponse
public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId) 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 = []; $tab = [];
foreach ($result as $row){ foreach ($result as $row){
$tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']); $tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']);
@ -30,6 +26,15 @@ class GatewayResponse
return array($result, $tab); 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 public function deleteResponseById(int $responseId): void
{ {
$query = "DELETE FROM Categorize WHERE response = :id"; $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)"; $query = "INSERT INTO Response(content, question) VALUES (:content, :question)";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
@ -56,6 +61,14 @@ class GatewayResponse
':question' => array($question, PDO::PARAM_STR) ':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)
));
}
} }
} }
Loading…
Cancel
Save