You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
<?php
|
|
|
|
namespace API\script\Gateway;
|
|
|
|
use API\script\Config\Connection;
|
|
use PDO;
|
|
|
|
class GatewayResponse
|
|
{
|
|
private Connection $connection;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->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;
|
|
}
|
|
}
|