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/GatewayListResponseOfCandid...

86 lines
2.8 KiB

<?php
namespace API\script\Gateway;
use API\script\Config\Connection;
use PDO;
class GatewayListResponseOfCandidate
{
private Connection $connection;
public function __construct()
{
$this->connection = connect();
}
public function getDetailsListResponsesOfCandidate(int $idListResponse)
{
$gatewayResponse = new GatewayResponse();
$gatewayKeyword = new GatewayKeyword();
$tabKeywords = [];
$query = "SELECT * FROM ListResponsesOfCandidate WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($idListResponse, PDO::PARAM_INT)
));
$questionList = $this->connection->getResults()[0];
$responses = $gatewayResponse->getResponsesByIdListCandidate($questionList['id']);
foreach ($responses as $row) {
$tabKeywords[] = $gatewayKeyword->getKeywordsContentByCategorieze($row['id']);
}
return array($questionList, $responses, $tabKeywords);
}
public function getAllListResponsesOfCandidate(): array
{
$query = "SELECT * FROM ListResponsesOfCandidate";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
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('Y-m-d 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)
));
}
}
}