Update of all gateways, and add new routes to new methods in gateway
continuous-integration/drone/push Build is passing Details

master
dorian.hodin 2 years ago
parent 9fc2b85f80
commit 68d7af0515

@ -487,12 +487,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/slimphp/Slim-Psr7.git", "url": "https://github.com/slimphp/Slim-Psr7.git",
"reference": "2d53022f48bd2583911d2a10de5529c10453346a" "reference": "a6f0caef429144986bd3d1325f4924f7c3b75969"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim-Psr7/zipball/2d53022f48bd2583911d2a10de5529c10453346a", "url": "https://api.github.com/repos/slimphp/Slim-Psr7/zipball/a6f0caef429144986bd3d1325f4924f7c3b75969",
"reference": "2d53022f48bd2583911d2a10de5529c10453346a", "reference": "a6f0caef429144986bd3d1325f4924f7c3b75969",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -512,10 +512,10 @@
"ext-json": "*", "ext-json": "*",
"http-interop/http-factory-tests": "^0.9.0", "http-interop/http-factory-tests": "^0.9.0",
"php-http/psr7-integration-tests": "dev-master", "php-http/psr7-integration-tests": "dev-master",
"phpspec/prophecy": "^1.16", "phpspec/prophecy": "^1.17",
"phpspec/prophecy-phpunit": "^2.0", "phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.9", "phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.7" "squizlabs/php_codesniffer": "^3.7"
}, },
"default-branch": true, "default-branch": true,
@ -562,7 +562,7 @@
"issues": "https://github.com/slimphp/Slim-Psr7/issues", "issues": "https://github.com/slimphp/Slim-Psr7/issues",
"source": "https://github.com/slimphp/Slim-Psr7/tree/master" "source": "https://github.com/slimphp/Slim-Psr7/tree/master"
}, },
"time": "2023-02-13T07:36:36+00:00" "time": "2023-03-07T02:37:20+00:00"
}, },
{ {
"name": "slim/slim", "name": "slim/slim",

@ -0,0 +1,46 @@
<?php
namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
/**
* Permet d'accéder, d'écrire ou de modifier les données contenues dans la table Admin afin de gérer l'espace administrateur.
*/
class GatewayAdmin
{
/**
* @var Connection
*/
private Connection $connection;
public function __construct()
{
try{
$this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Permet de récupérer le mot de passe de l'administrateur en fonction de son login.
* @param String $login Le login de l'administrateur.
* @return String|null Le mot de passe de l'administrateur ou null si l'administrateur n'existe pas.
*/
public function getPasswordWithLogin(String $login): ?string
{
$query = "SELECT password FROM ADMIN WHERE login = :login";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR)
));
$result = $this->connection->getResults();
if(empty($result))
return null;
return $result[0]['password'];
}
}

@ -47,31 +47,42 @@ class GatewayForm
)); ));
} }
public function selectForDeleteAndInsert(int $idQuestion, string $response){ public function assignKeywordToQuestion(string $keyword, int $idQuestion, string $response): void
$query = "SELECT pr.id FROM Propose p, PossibleResponse pr WHERE p.question = :id AND p.possibleResponse = pr.id AND pr.content = :response"; {
$query = "SELECT pr.id
FROM Propose p, PossibleResponse pr
WHERE p.question = :id AND p.possibleResponse = pr.id
AND pr.content = :response";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
':id' => array($idQuestion, PDO::PARAM_INT), ':id' => array($idQuestion, PDO::PARAM_INT),
':response' => array($response, PDO::PARAM_STR) ':response' => array($response, PDO::PARAM_STR)
)); ));
return $this->connection->getResults()[0][0]; $idPossibleResponse = $this->connection->getResults()[0][0];
}
public function assignKeywordToQuestion(string $keyword, int $idQuestion, string $response): void
{
$query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)"; $query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
':possibleResponse' => array($this->selectForDeleteAndInsert($idQuestion,$response), PDO::PARAM_INT), ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT),
':keyword' => array($keyword, PDO::PARAM_STR) ':keyword' => array($keyword, PDO::PARAM_STR)
)); ));
} }
public function deleteKeywordFromQuestion(string $keyword, int $idQuestion, string $response): void public function deleteKeywordFromQuestion(string $keyword, int $idQuestion, string $response): void
{ {
$query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeword"; $query = "SELECT pr.id FROM Propose p, PossibleResponse r
WHERE p.question = :id AND p.possibleResponse = pr.id
AND pr.content = :response";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
':possibleResponse' => array($this->selectForDeleteAndInsert($idQuestion,$response), PDO::PARAM_INT), ':id' => array($idQuestion, PDO::PARAM_INT),
':keyword' => array($keyword, PDO::PARAM_STR) ':response' => array($response, PDO::PARAM_STR)
));
$idPossibleResponse = $this->connection->getResults()[0][0];
$query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeyword";
$this->connection->executeQuery($query, array(
':idResponse' => array($idPossibleResponse, PDO::PARAM_INT),
':idKeyword' => array($keyword, PDO::PARAM_INT)
)); ));
} }
@ -101,4 +112,11 @@ class GatewayForm
':id' => array($idForm, PDO::PARAM_INT) ':id' => array($idForm, PDO::PARAM_INT)
)); ));
} }
public function existsForm(): bool
{
$query = "SELECT * FROM Form";
$this->connection->executeQuery($query);
return !empty($this->connection->getResults());
}
} }

@ -59,4 +59,41 @@ class GatewayKeyword
} }
return $tab; return $tab;
} }
/**
* Permet de récupérer tous les Keyword qui font référence à l'id de la réponse d'un candidat passée en paramètre.
*
* @param int $id Id de la réponse que l'on veut connaitre ses catégories
*
* @return array Retourne l'ensemble de tous les Keyword associer à la réponse
*/
public function getKeywordsContentByCategorize(int $id): array
{
$query = "SELECT k.* FROM Keyword k, Categorize c
WHERE k.word = c.keyword AND c.response = :id";
return $this->getKeywordByAssociation($id , $query);
}
/**
* Permet de récupérer une liste de Keyword selon une requête donnée et un id associé.
*
* @param int $id Id de l'objet dont on veut ses Keyword associé
* @param string $query Requête que l'on veut exécuter
*
* @return array Retourne la liste des différents Keyword associé à l'objet voulu
*/
private function getKeywordByAssociation(int $id, string $query): array
{
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_STR)
));
$tab = [];
foreach ($this->connection->getResults() as $result) {
$tab[] = $result["word"];
}
return $tab;
}
} }

@ -40,4 +40,17 @@ class GatewayPossibleResponse
return $this->connection->lastInsertId(); return $this->connection->lastInsertId();
} }
public function deletePossibleResponse(int $id): void
{
$query = "DELETE FROM Reference WHERE response = :id";
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_INT)
));
$query = "DELETE FROM PossibleResponse WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_INT)
));
}
} }

@ -20,24 +20,21 @@ class GatewayQuestion
} }
} }
public function insertQuestion(string $contentQuestion, string $classQuestion, int $idForm, array $listPossibleResponse, array $listOfCategories): void
{
$gatewayPossibleResponse = new GatewayPossibleResponse();
public function addQuestion(string $contentQuestion, string $classQuestion, int $idForm): int
{
$query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)"; $query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
':content' => array($contentQuestion, PDO::PARAM_STR), ':content' => array($contentQuestion, PDO::PARAM_STR),
':type' => array($classQuestion, PDO::PARAM_STR), ':type' => array($classQuestion, PDO::PARAM_STR),
':form' => array($idForm, PDO::PARAM_INT) ':form' => array($idForm, PDO::PARAM_INT)
)); ));
return $this->connection->lastInsertId();
$idQuestion = $this->connection->lastInsertId(); }
public function insertResponseInQuestion(string $response, array $categories, int $idQuestion): void
if($classQuestion != "TextQuestionAPI"){ {
$gatewayPossibleResponse = new GatewayPossibleResponse();
for($i = 0; $i < count($listPossibleResponse); $i++){ $idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($response);
$idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($listPossibleResponse[$i]);
$query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)"; $query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
@ -45,14 +42,13 @@ class GatewayQuestion
':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT) ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT)
)); ));
foreach ($listOfCategories[$i] as $keyword){ foreach ($categories as $keyword){
$gatewayForm = new GatewayForm(); $gatewayForm = new GatewayForm();
$gatewayForm->assignKeywordToQuestion($keyword, $listPossibleResponse[$i], $idQuestion); $gatewayForm->assignKeywordToQuestion($keyword, $response, $idQuestion);
}
}
} }
} }
public function deleteQuestion(string $questionClass, int $idQuestion, array $questionGetPossibleResponse): void public function deleteQuestion(string $questionClass, int $idQuestion, array $questionGetPossibleResponse): void
{ {
if($questionClass == "BoxQuestionAPI") { if($questionClass == "BoxQuestionAPI") {

@ -20,6 +20,33 @@ class GatewayResponse
} }
} }
/**
* Permet de récupérer la liste des réponses d'un candidat ainsi que les Keyword couvert pour chaque réponse.
*
* @param int $listResponsesOfCandidateId Id du candidat
*
* @return array Retourne une liste contenant à l'indice 0 la liste de réponse
* et à l'indice 1 une liste de Keyword,
* où chaque indice d'une liste de question est associé au même indice une réponse
*/
public function getCategorizeOfResponsesIdByIdListCandidate(int $listResponsesOfCandidateId): array
{
$result = $this->getResponsesByIdListCandidate($listResponsesOfCandidateId);
$tab = [];
foreach ($result as $row) {
$tab[] = (new GatewayKeyword())->getKeywordsContentByCategorize($row['id']);
}
return array($result, $tab);
}
/**
* Permet de récupérer la liste des réponses d'un candidat par son id.
*
* @param int $listResponsesOfCandidateId Id du candidat
*
* @return array Retourne la list des réponses du candidat
*/
public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId): array public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId): array
{ {
@ -32,6 +59,13 @@ class GatewayResponse
return array($result, $tab); return array($result, $tab);
} }
/**
* Permet de récupérer la liste des id des réponses d'un candidat par son id.
*
* @param int $listResponsesOfCandidateId Id du candidat
*
* @return array Retourne la list des id des réponses du candidat
*/
public function getResponsesIdByIdListCandidate(int $listResponsesOfCandidateId): array public function getResponsesIdByIdListCandidate(int $listResponsesOfCandidateId): array
{ {
$query = "SELECT r.id FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response"; $query = "SELECT r.id FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response";
@ -41,6 +75,14 @@ class GatewayResponse
return $this->connection->getResults(); return $this->connection->getResults();
} }
/**
* Permet de supprimer la réponse et ses liens avec les différents Keyword
* selon l'id de la réponse passée en paramètre
*
* @param int $responseId Id de la réponse à supprimer
*
* @return void
*/
public function deleteResponseById(int $responseId): void public function deleteResponseById(int $responseId): void
{ {
$query = "DELETE FROM Categorize WHERE response = :id"; $query = "DELETE FROM Categorize WHERE response = :id";
@ -59,6 +101,15 @@ class GatewayResponse
)); ));
} }
/**
* Permet d'insérer une réponse ainsi que de la lier avec les Keywords passés en paramètre.
*
* @param string $content Contenu de la réponse
* @param string $questionContent Contenu de la question, dans le cas où la question viendra à changer dans le futur
* @param array $category Liste des Keyword associé à la réponse
*
* @return int Retourne l'Id de la réponse insérée
*/
public function insertResponse(string $content, string $questionContent, array $category): int public function insertResponse(string $content, string $questionContent, array $category): int
{ {
$query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)"; $query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)";
@ -80,4 +131,22 @@ class GatewayResponse
return $idResponse; return $idResponse;
} }
/**
* Permet de récupérer une liste de format de réponse définit par la commande sql passé en paramètre,
* dont l'id du candidat, ayant formulé ces réponses, est passé en paramètre.
*
* @param string $query Requête du format de liste de réponse voulu
* @param int $id Id du candidat cible
*
* @return array Retourne la liste des réponses d'un candidat selon le format voulu
*/
public function getResponsesByQueryAndIdListCandidate(string $query, int $id): array
{
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_INT)
));
return $this->connection->getResults();
}
} }

@ -8,6 +8,7 @@ use Gateway\GatewayKeyword;
use Gateway\GatewayListResponseOfCandidate; use Gateway\GatewayListResponseOfCandidate;
use Gateway\GatewayPossibleResponse; use Gateway\GatewayPossibleResponse;
use Gateway\GatewayQuestion; use Gateway\GatewayQuestion;
use Gateway\GatewayAdmin;
use Gateway\GatewayResponse; use Gateway\GatewayResponse;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
@ -72,13 +73,13 @@ $app->delete('/deleteForm', function(Request $request){
} }
}); });
$app->get('/selectForDeleteAndInsert', function(Request $request, Response $response){ $app->get('/existsForm', function(Request $request, Response $response){
$parameters = $request->getQueryParams(); $parameters = $request->getQueryParams();
if (empty($parameters['id']) || empty($parameters['response'])){ if (empty($parameters['id']) || empty($parameters['response'])){
throw new TypeErrorParameters($request); throw new TypeErrorParameters($request);
} }
try{ try{
$response->getBody()->write(json_encode((new GatewayForm)->selectForDeleteAndInsert($parameters['id'],$parameters['response']), JSON_UNESCAPED_UNICODE)); $response->getBody()->write(json_encode((new GatewayForm)->existsForm(), JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){ }catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e); throw new PDOError($request,$e->getMessage(),$e);
} }
@ -315,16 +316,17 @@ $app->post('/insertResponse', function(Request $request, Response $response){
return $response->withHeader('Content-type', 'application/json')->withStatus(200); return $response->withHeader('Content-type', 'application/json')->withStatus(200);
}); });
$app->post('/insertQuestion', function(Request $request){ $app->post('/addQuestion', function(Request $request, Response $response){
$parameters = $request->getQueryParams(); $parameters = $request->getQueryParams();
if (empty($parameters['content']) || empty($parameters['classQuestion']) || empty($parameters['idForm']) || empty($parameters['listPossibleResponse']) || empty($parameters['listOfCategories'])){ if (empty($parameters['content']) || empty($parameters['classQuestion']) || empty($parameters['idForm'])){
throw new TypeErrorParameters($request); throw new TypeErrorParameters($request);
} }
try{ try{
(new GatewayQuestion)->insertQuestion($parameters['content'],$parameters['classQuestion'],$parameters['idForm'], $parameters['listPossibleResponse'], $parameters['listOfCategories']); $response->getBody()->write(json_encode((new GatewayQuestion)->addQuestion($parameters['content'],$parameters['classQuestion'],$parameters['idForm']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){ }catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e); throw new PDOError($request,$e->getMessage(),$e);
} }
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
}); });
$app->delete('/deleteQuestion', function(Request $request){ $app->delete('/deleteQuestion', function(Request $request){
@ -377,5 +379,81 @@ $app->get('/getQuestionContentById', function(Request $request, Response $respon
return $response->withHeader('Content-type', 'application/json')->withStatus(200); return $response->withHeader('Content-type', 'application/json')->withStatus(200);
}); });
$app->get('/getKeywordContentByCategorize', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayKeyword)->getKeywordsContentByCategorize($parameters['id']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getPasswordWithLogin', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['login'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayAdmin())->getPasswordWithLogin($parameters['login']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->delete('/deletePossibleResponse', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayPossibleResponse)->deletePossibleResponse($parameters['id']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->post('/insertResponseInQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['response']) || empty($parameters['categories']) || empty($parameters['idQuestion'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayQuestion)->insertResponseInQuestion($parameters['response'],$parameters['categories'],$parameters['idQuestion']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->get('/getCategorizeOfResponsesIdByIdListCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['listResponse'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getCategorizeOfResponsesIdByIdListCandidate($parameters['listResponse']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getResponsesByQueryAndIdListCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['query']) || empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesByQueryAndIdListCandidate($parameters['query'],$parameters['id']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
// Run app // Run app
$app->run(); $app->run();

Loading…
Cancel
Save