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.
113 lines
3.7 KiB
113 lines
3.7 KiB
<?php
|
|
|
|
namespace API\script\Gateway;
|
|
|
|
use API\script\Config\Connection;
|
|
use PDO;
|
|
|
|
/**
|
|
* Permet d'accéder, d'écrire ou de modifier les données contenues dans la table ListResponseOfCandidate
|
|
* afin de gérer les réponses fournit des candidats.
|
|
*/
|
|
class GatewayListResponseOfCandidate
|
|
{
|
|
/**
|
|
* @var Connection
|
|
*/
|
|
private Connection $connection;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->connection = connect();
|
|
}
|
|
|
|
/**
|
|
* Permet de récupérer l'ensemble des réponses d'un candidat ansi que les Keywords associer à chaque réponse.
|
|
*
|
|
* @param int $idListResponse Id de la liste de réponse d'un candidat
|
|
*
|
|
* @return array Retourne une liste contenant
|
|
* à l'indice 0 les informations globale de la liste des réponses du candidat, à l'indice 1 la liste de réponse
|
|
* et à l'indice 2 une liste de liste de Keword,
|
|
* où chaque indice d'une liste de question est associé au même indice une réponse
|
|
*/
|
|
public function getDetailsListResponsesOfCandidate(int $idListResponse)
|
|
{
|
|
$gatewayResponse = new GatewayResponse();
|
|
|
|
$query = "SELECT * FROM ListResponsesOfCandidate WHERE id = :id";
|
|
$this->connection->executeQuery($query, array(
|
|
':id' => array($idListResponse, PDO::PARAM_INT)
|
|
));
|
|
|
|
$questionList = $this->connection->getResults()[0];
|
|
|
|
$result = $gatewayResponse->getCatgoriezeOfResponsesIdByIdListCandidate($questionList['id']);
|
|
|
|
return array($questionList, $result[0], $result[1]);
|
|
}
|
|
|
|
/**
|
|
* Permet de recupérer seulement les informations globales de toutes listes de réponses de candidat.
|
|
*
|
|
* @return array Retourne une liste d'informations globale de la liste des réponses du candidat
|
|
*/
|
|
public function getAllListResponsesOfCandidate(): array
|
|
{
|
|
$query = "SELECT * FROM ListResponsesOfCandidate";
|
|
$this->connection->executeQuery($query);
|
|
|
|
return $this->connection->getResults();
|
|
}
|
|
|
|
/**
|
|
* @param $id
|
|
* @return 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)
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @param $id
|
|
* @param $answer
|
|
* @param $category
|
|
* @param $titleForm
|
|
* @return void
|
|
*/
|
|
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++) {
|
|
$question = $gatewayQuestion->getQuestionContentById($id[$i]);
|
|
$idResponse = $gatewayResponse->insertResponse($question, $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)
|
|
));
|
|
}
|
|
}
|
|
}
|