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.
SAE4.01_FORMULAIRE/Source/API/script/Gateway/GatewayResponse.php

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