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.
77 lines
2.6 KiB
77 lines
2.6 KiB
<?php
|
|
|
|
namespace Gateway;
|
|
|
|
use Config\Connection;
|
|
use PDO;
|
|
|
|
class GatewayResponse
|
|
{
|
|
private Connection $connection;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->connection = connect();
|
|
}
|
|
|
|
public function getResponsesByIdListCandidate(array $listResponsesOfCandidateId): array
|
|
{
|
|
|
|
$result = $this->getResponsesIdByIdListCandidate(array($listResponsesOfCandidateId[0]));
|
|
$tab = [];
|
|
foreach ($result as $row){
|
|
$tab[] = (new GatewayKeyword())->getKeywordsContentByReference(array($row['id']));
|
|
}
|
|
|
|
return array($result, $tab);
|
|
}
|
|
|
|
public function getResponsesIdByIdListCandidate(array $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[0], PDO::PARAM_INT)
|
|
));
|
|
return $this->connection->getResults();
|
|
}
|
|
|
|
public function deleteResponseById(array $responseId): void
|
|
{
|
|
$query = "DELETE FROM Categorize WHERE response = :id";
|
|
$this->connection->executeQuery($query, array(
|
|
':id' => array($responseId[0], PDO::PARAM_INT)
|
|
));
|
|
|
|
$query = "DELETE FROM Submit WHERE response = :id";
|
|
$this->connection->executeQuery($query, array(
|
|
':id' => array($responseId[0], PDO::PARAM_INT)
|
|
));
|
|
|
|
$query = "DELETE FROM Response WHERE id = :id";
|
|
$this->connection->executeQuery($query, array(
|
|
':id' => array($responseId[0], PDO::PARAM_INT)
|
|
));
|
|
}
|
|
|
|
public function insertResponse(array $parameters): int
|
|
{
|
|
$query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)";
|
|
$this->connection->executeQuery($query, array(
|
|
':content' => array($parameters[0], PDO::PARAM_STR), //parameters[0] = content
|
|
':questionContent' => array($parameters[1], PDO::PARAM_STR) //parameters[1] = questionContent
|
|
));
|
|
|
|
$idResponse = $this->connection->lastInsertId();
|
|
|
|
|
|
foreach ($parameters[2] as $keyword){ //parameters[2] = category (array)
|
|
$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;
|
|
}
|
|
} |