Modification of ModelAdmin.php with call of the Gateways
continuous-integration/drone/push Build is passing Details

interestingProfiles
dorian.hodin 2 years ago
parent 6cf3254c07
commit 3246a60cb3

@ -14,4 +14,10 @@ steps:
SONAR_TOKEN:
from_secret: SONARQ_TOKEN
commands:
- sonar-scanner -Dsonar.projectKey=SAE4.01_FORMULAIRE -Dsonar.sources=. -Dsonar.login=$${SONAR_TOKEN} -Dsonar.language=php -Dsonar.host.url=https://codefirst.iut.uca.fr/sonar -Dsonar.php.coverage.reportPaths=coverage.xml
- sonar-scanner -Dsonar.projectKey=SAE4.01_FORMULAIRE -Dsonar.sources=. -Dsonar.login=$${SONAR_TOKEN} -Dsonar.language=php -Dsonar.host.url=https://codefirst.iut.uca.fr/sonar -Dsonar.php.coverage.reportPaths=coverage.xml

1
.gitignore vendored

@ -0,0 +1 @@
./Source/Config/vendor/

@ -1,91 +0,0 @@
<?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 Admin afin de gérer l'espace administrateur.
*/
class GatewayAdmin
{
/**
* @var Connection
*/
private Connection $connection;
public function __construct()
{
$this->connection = connect();
}
/**
* Permet d'ajouter un administrateur dans la base de données.
*
* @param string $login Login du nouvel adimin
* @param string $hash Mot de passe au format hash du nouvel admin
*
* @return void
*/
public function addAdmin(string $login, string $hash): void
{
$query = "INSERT INTO Admin(login, hash) VALUES(:login, :hash)";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR),
':hash' => array($hash, PDO::PARAM_STR)
));
}
/**
* Permet de récupérer le mot de passe en format hash du login passé en argument,
* afin de vérifier si la connection de l'utilisateur.
*
* @param string $login Login du coup duquel on veut récupérer le hash associé
*
* @return array
*/
public function getPassword(string $login): array
{
$query = 'SELECT Hash FROM Admin WHERE Login = :login';
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR)
));
return $this->connection->getResults();
}
/**
* Permet de changer le mot de passe de l'administrateur dont le login
* et le nouveau mot de passe au format hash est passé en argument.
*
* @param string $login Login dont on change le mot de passe
* @param string $hash Nouveau mot de passe au format hash
*
* @return void
*/
public function changePassword(string $login, string $hash): void
{
$query = "UPDATE Admin SET hash = :hash WHERE login = :login";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR),
':hash' => array($hash, PDO::PARAM_STR)
));
}
/**
* Permet de supprimer un administrateur de la base de donnée par un login passé en paramètre.
*
* @param string $login Login du compte qui sera supprimé
*
* @return void
*/
public function deleteAdmin(string $login): void
{
$query = "DELETE FROM Admin WHERE login = :login";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR)
));
}
}

@ -1,111 +0,0 @@
<?php
namespace API\script\Gateway;
use API\script\Config\Connection;
use BusinessClass\Form;
use BusinessClass\Question;
use PDO;
class GatewayForm
{
private Connection $connection;
public function __construct()
{
$this->connection = connect();
}
public function insertForm(Form $form): void
{
if (empty($this->getForm())) {
$query = "INSERT INTO Form(title, description) VALUES(:title, :desc)";
$this->connection->executeQuery($query, array(
':title' => array($form->getTitle(), PDO::PARAM_STR),
':desc' => array($form->getDescription(), PDO::PARAM_STR)
));
}
}
public function getForm(): array
{
$query = "SELECT * FROM Form";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
public function deleteForm(Form $form): void
{
$query = "DELETE FROM Form WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($form->getId(), PDO::PARAM_INT)
));
}
public function assignKeywordToQuestion(string $keyword, string $response, int $idQuestion): void
{
$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(
':id' => array($idQuestion, PDO::PARAM_INT),
':response' => array($response, PDO::PARAM_STR)
));
$idPossibleResponse = $this->connection->getResults()[0][0];
$query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)";
$this->connection->executeQuery($query, array(
':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT),
':keyword' => array($keyword, PDO::PARAM_STR)
));
}
public function deleteKeywordFromQuestion(string $keyword, string $response, Question $question): void
{
$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(
':id' => array($question->getId(), PDO::PARAM_INT),
':response' => array($response, PDO::PARAM_STR)
));
$idPossibleResponse = $this->connection->getResults()[0][0];
$query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeword";
$this->connection->executeQuery($query, array(
':idResponse' => array($idPossibleResponse, PDO::PARAM_INT),
':idKeword' => array($keyword, PDO::PARAM_INT)
));
}
public function updateTitleToForm(string $title, Form $form): void
{
$query = "UPDATE Form SET title = :title WHERE id = :id";
$this->connection->executeQuery($query, array(
':title' => array($title, PDO::PARAM_STR),
':id' => array($form->getId(), PDO::PARAM_INT)
));
}
public function updateDescriptionToForm(string $description, Form $form): void
{
$query = "UPDATE Form SET title = :title WHERE description = :description";
$this->connection->executeQuery($query, array(
':description' => array($description, PDO::PARAM_STR),
':id' => array($form->getId(), PDO::PARAM_INT)
));
}
public function deleteDescriptionToForm(Form $form): void
{
$query = "UPDATE Form SET title = :title WHERE description = :descript";
$this->connection->executeQuery($query, array(
':descript' => array('', PDO::PARAM_STR),
':id' => array($form->getId(), PDO::PARAM_INT)
));
}
}

@ -1,124 +0,0 @@
<?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 Keyword
* afin de gérer les catégories disponibles et associer aux différentes réponses des questions.
*/
class GatewayKeyword
{
/**
* @var Connection
*/
private Connection $connection;
/**
*
*/
public function __construct()
{
$this->connection = connect();
}
/**
* Permet d'ajouter un Keyword dans la base de donnée.
*
* @param string $keyword Keyword à ajouter
*
* @return void
*/
public function insertKeyword(string $keyword)
{
$query = "INSERT INTO Keyword(word) VALUES(:word)";
$this->connection->executeQuery($query, array(
':word' => array($keyword, PDO::PARAM_STR)
));
}
/**
* Permet de supprimer un keyword de la base de donnée.
*
* @param string $keyword Keyword à supprimer
*
* @return void
*/
public function deleteKeyword(string $keyword)
{
$query = "DELETE FROM Keyword WHERE word = :word";
$this->connection->executeQuery($query, array(
':word' => array($keyword, PDO::PARAM_STR)
));
}
/**
* Permet de récupérer l'ensemble des Keyword disponible.
*
* @return array Retourne la liste de l'ensemble des keyword sauvé dans la base de donnée
*/
public function getAllKeyword(): array
{
$query = "SELECT * FROM Keyword";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
/**
* Permet de récupérer tous les Keyword qui font référence à l'id de la réponse possible à une question passée en paramètre.
*
* @param int $id Id de la possible 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 getKeywordsContentByReference(int $id): array
{
$query = "SELECT k.* FROM Keyword k, Reference r
WHERE k.word = r.keyword AND r.possibleResponse = :id";
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_STR)
));
return $this->getKeywordByAssotiation($id , $query);
}
/**
* 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 getKeywordsContentByCategorieze(int $id): array
{
$query = "SELECT k.* FROM Keyword k, Categorize c
WHERE k.word = c.keyword AND c.response = :id";
return $this->getKeywordByAssotiation($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 getKeywordByAssotiation(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;
}
}

@ -1,129 +0,0 @@
<?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 PossibleResponse
* afin de gérer la liste des réponses et les catégories associer d'un candidat.
*/
class GatewayListResponseOfCandidate
{
/**
* @var Connection
*/
private Connection $connection;
/**
*
*/
public function __construct()
{
$this->connection = connect();
}
/**
* Permet de récupérer la liste détaillée des réponses avec leurs catégories associer
* aux différentes questions qu'un candidat cible a répondu
*
* @param int $idListResponse Id du candidat pour lequel on veut récupérer ses réponses
*
* @return array Retourne une liste qui pour
* l'indice 0 a la liste des infos du candidat
* l'indice 1 la liste des réponses
* l'indice 2 une liste de liste de catégories, qui pour chaque même indice correspont à la liste des catégories de la réponse
*/
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);
}
/**
* Permet de récupérer la liste des personnes ayant répondu aux formulaire
*
* @return array Retourne la liste brute des informations de tous les candidats ayant répondu au formulaire
*/
public function getAllListResponsesOfCandidate(): array
{
$query = "SELECT * FROM ListResponsesOfCandidate";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
/**
* Permet de supprimer la liste des réponses d'un candidat de la base de donnée
*
* @param int $id Id du candidat à supprimer
*
* @return void
*/
public function deleteListResponseOfCandidate(int $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_INT)
));
}
/**
* Permet d'insérer dans la base de données les réponses aux questions d'un candidat
* ainsi que les catégories associées à chaque réponse
*
* @param array $id Liste des id des questions répondue
* @param array $answer Liste des réponses à chaque question
* @param array $category Liste des catégories attribuées à chaque réponse
* @param string $titleForm Titre du formulaire
*
* @return void
*/
public function insertListResponsesOfCandidate(array $id, array $answer, array $category, string $titleForm): void
{
$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)
));
}
}
}

@ -1,79 +0,0 @@
<?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 PossibleResponse.
*/
class GatewayPossibleResponse
{
/**
* @var Connection
*/
private Connection $connection;
/**
*
*/
public function __construct()
{
$this->connection = connect();
}
/**
* Permet de récupérer les différentes réponses possibles à une question donnée.
*
* @param string $idQuestion Id de la question pour laquelle on veut récupérer les réponses possibles
*
* @return array Retourne la liste de possibles réponses
*/
public function getPossibleResponseByQuestion(string $idQuestion): array
{
$query = "SELECT pr.* FROM Propose p, PossibleResponse pr
WHERE p.question = :questionId AND p.possibleResponse = pr.id";
$this->connection->executeQuery($query, array(
':questionId' => array($idQuestion, PDO::PARAM_INT)
));
return $this->connection->getResults();
}
/**
* Permet d'insérer une possible réponse dans la base de donnée.
*
* @param string $contentPossibleResponse Contenu de la possible réponse
* @return int
*/
public function insertPossibleResponse(string $contentPossibleResponse): int
{
$query = "INSERT INTO PossibleResponse(content) VALUES(:content)";
$this->connection->executeQuery($query, array(
':content' => array($contentPossibleResponse, PDO::PARAM_STR)
));
return $this->connection->lastInsertId();
}
/**
* Permet de supprimer une possible réponse de la base de donnée par son id.
*
* @param int $id Id de la possible réponse à supprimer
*
* @return void
*/
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)
));
}
}

@ -1,193 +0,0 @@
<?php
namespace API\script\Gateway;
use API\script\Config\Connection;
use BusinessClass\BoxQuestion;
use BusinessClass\Question;
use BusinessClass\TextQuestion;
use PDO;
/**
* Permet d'accéder, d'écrire ou de modifier les données contenues dans la table Question
* afin de rendre le formulaire modulable.
*/
class GatewayQuestion
{
/**
* @var Connection
*/
private Connection $connection;
/**
*
*/
public function __construct()
{
$this->connection = connect();
}
/**
* Permet d'ajouter une question dans la base de donnée.
*
* @param Question $question Information sur la question ajouter
* @param int $idForm Id du formulaire associer
*
* @return int Id de la question ajouté en base
*/
public function addQuestion(Question $question, int $idForm): int
{
$query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)";
$this->connection->executeQuery($query, array(
':content' => array($question->getContent(), PDO::PARAM_STR),
':type' => array(get_class($question), PDO::PARAM_STR),
':form' => array($idForm, PDO::PARAM_INT)
));
return $this->connection->lastInsertId();
}
/**
* Ajoute une possible réponse à une question cible et associe à la possible réponse des catégories.
*
* @param string $response Contenu de la réponse possible
* @param array $categories Liste des catégories attribuées à la possible réponse
* @param int $idQuestion Id de la question associée à cette possible réponse
*
* @return int Retourne l'id de la possible réponse insérée en base
*/
public function insertResponseInQuestion(string $response, array $categories, int $idQuestion): int
{
$gatewayPossibleResponse = new GatewayPossibleResponse();
$idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($response);
$query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)";
$this->connection->executeQuery($query, array(
':question' => array($idQuestion, PDO::PARAM_INT),
':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT)
));
foreach ($categories as $keyword) {
$gatewayForm = new GatewayForm();
$gatewayForm->assignKeywordToQuestion($keyword, $response, $idQuestion);
}
return $idQuestion;
}
/**
* Permet de supprimer une question dans la base ainsi que ses dépendances
*
* @param Question $question Information de la question à supprimer
*
* @return void
*/
public function deleteQuestion(Question $question): void
{
if (get_class($question) == BoxQuestion::class) {
$query = "DELETE FROM Propose WHERE question = :id";
$this->connection->executeQuery($query, array(
':id' => array($question->getId(), PDO::PARAM_INT)
));
$listPossibleResponse = $question->getPossibleResponses();
for ($i = 0; $i < count($listPossibleResponse); $i++) {
$gatewayPossibleResponse = new GatewayPossibleResponse();
$gatewayPossibleResponse->deletePossibleResponse($listPossibleResponse[$i]->getId());
}
}
$query = "DELETE FROM Question WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($question->getId(), PDO::PARAM_INT)
));
}
/**
* Permet de modifier dans la base de données les informations de la question.
*
* @param Question $question Question modifier à changer en base
*
* @return void
*/
public function updateQuestion(Question $question): void
{
$query = "UPDATE Question SET content = :content, type = :type, form = :frm WHERE id = :id";
$this->connection->executeQuery($query, array(
':content' => array($question->getContent(), PDO::PARAM_STR),
':type' => array(get_class($question), PDO::PARAM_STR),
':frm' => array($question->getForm(), PDO::PARAM_STR),
':id' => array($question->getId(), PDO::PARAM_STR)
));
}
/**
* Permet de récupérer toutes les questions, possibles réponses et catégories associées d'un formualire cible.
*
* @param string $idForm Id du formulaire
*
* @return array Retourne une liste qui pour
* l'indice 0 la liste des questions
* l'indice 1 une liste de liste de réponses, qui pour chaque même indice correspond à la liste des réponses possibles de la question
* l'indice 2 une liste de liste de liste de catégories qui pour chaque indice de questions,
* on a une liste de liste de catégories qui pour chaque indice de réponses est associer une liste de catégories
* Ou vide s'il n'y a pas de question dans la base
*/
public function getAllQuestions(string $idForm): array
{
$query = "SELECT * FROM Question WHERE form = :fom";
$this->connection->executeQuery($query, array(
':fom' => array($idForm, PDO::PARAM_INT)
));
$listQuestions = $this->connection->getResults();
$possibleResponsesContent = [];
$keywordsResponses = [];
$gatewayKeyword = new GatewayKeyword();
$gatewayPossibleResponse = new GatewayPossibleResponse();
if (!empty($listQuestions)) {
for ($i = 0; $i < count($listQuestions); $i++) {
if ($listQuestions[$i]["type"] != "BusinessClass/TextQuestion") {
$idQuestion = $listQuestions[$i]["id"];
$possibleResponses = $gatewayPossibleResponse->getPossibleResponseByQuestion($idQuestion);
$tmpTabKeyword = [];
$tmpTabPossibleResponse = [];
foreach ($possibleResponses as $row) {
$tmpTabKeyword[] = $gatewayKeyword->getKeywordsContentByReference($row["id"]);
$tmpTabPossibleResponse[] = $row["content"];
}
$possibleResponsesContent[] = $tmpTabPossibleResponse;
$keywordsResponses[] = $tmpTabKeyword;
} else {
$possibleResponsesContent[] = null;
$keywordsResponses[] = null;
}
}
return array($listQuestions, $possibleResponsesContent, $keywordsResponses);
}
return array();
}
/**
* Permet de récupérer le contenu d'une réponse à une question par son id.
*
* @param string $id Id de la question cible
*
* @return string Retourne le contenu de la question ciblé
*/
public function getQuestionContentById(string $id): string
{
$query = "SELECT content FROM Question WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_INT)
));
return $this->connection->getResults()[0][0];
}
}

@ -1,142 +0,0 @@
<?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 Response
* afin de récupérer les réponses d'un utilisateur.
*/
class GatewayResponse
{
/**
* @var Connection
*/
private Connection $connection;
public function __construct()
{
$this->connection = connect();
}
/**
* 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 liste de Keword,
* où chaque indice d'une liste de question est associé au même indice une réponse
*/
public function getCatgoriezeOfResponsesIdByIdListCandidate(int $listResponsesOfCandidateId): array
{
$result = $this->getResponsesByIdListCandidate($listResponsesOfCandidateId);
$tab = [];
foreach ($result as $row) {
$tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($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
{
$query = "SELECT r.* FROM Response r, Submit s WHERE s.responsesCandidate = :id AND r.id = s.response";
return $this->getResponsesByQueryAndIdListCandidate($query, $listResponsesOfCandidateId);
}
/**
* 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
{
$query = "SELECT r.id FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response";
return $this->getResponsesByQueryAndIdListCandidate($query, $listResponsesOfCandidateId);
}
/**
* 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
*/
private function getResponsesByQueryAndIdListCandidate(string $query, int $id): array
{
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_INT)
));
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
{
$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)
));
}
/**
* 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
{
$query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)";
$this->connection->executeQuery($query, array(
':content' => array($content, PDO::PARAM_STR),
':questionContent' => array($questionContent, 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)
));
}
return $idResponse;
}
}

@ -0,0 +1,9 @@
{
"name": "dorian/config",
"description": "composer for guzzle client",
"require": {
"guzzle/guzzle": "^3.9",
"guzzlehttp/psr7": "^2.4",
"guzzlehttp/guzzle": "^7.5"
}
}

@ -0,0 +1,784 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "453f177e189a55adc413c1f52956898c",
"packages": [
{
"name": "guzzle/guzzle",
"version": "v3.9.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle3.git",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.3",
"symfony/event-dispatcher": "~2.1"
},
"replace": {
"guzzle/batch": "self.version",
"guzzle/cache": "self.version",
"guzzle/common": "self.version",
"guzzle/http": "self.version",
"guzzle/inflection": "self.version",
"guzzle/iterator": "self.version",
"guzzle/log": "self.version",
"guzzle/parser": "self.version",
"guzzle/plugin": "self.version",
"guzzle/plugin-async": "self.version",
"guzzle/plugin-backoff": "self.version",
"guzzle/plugin-cache": "self.version",
"guzzle/plugin-cookie": "self.version",
"guzzle/plugin-curlauth": "self.version",
"guzzle/plugin-error-response": "self.version",
"guzzle/plugin-history": "self.version",
"guzzle/plugin-log": "self.version",
"guzzle/plugin-md5": "self.version",
"guzzle/plugin-mock": "self.version",
"guzzle/plugin-oauth": "self.version",
"guzzle/service": "self.version",
"guzzle/stream": "self.version"
},
"require-dev": {
"doctrine/cache": "~1.3",
"monolog/monolog": "~1.0",
"phpunit/phpunit": "3.7.*",
"psr/log": "~1.0",
"symfony/class-loader": "~2.1",
"zendframework/zend-cache": "2.*,<2.3",
"zendframework/zend-log": "2.*,<2.3"
},
"suggest": {
"guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.9-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle": "src/",
"Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Guzzle Community",
"homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"support": {
"issues": "https://github.com/guzzle/guzzle3/issues",
"source": "https://github.com/guzzle/guzzle3/tree/master"
},
"abandoned": "guzzlehttp/guzzle",
"time": "2015-03-18T18:23:50+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "7.5.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/b50a2a1251152e43f6a37f0fa053e730a67d25ba",
"reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^1.5",
"guzzlehttp/psr7": "^1.9 || ^2.4",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.1",
"ext-curl": "*",
"php-http/client-integration-tests": "^3.0",
"phpunit/phpunit": "^8.5.29 || ^9.5.23",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"suggest": {
"ext-curl": "Required for CURL handler support",
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
},
"branch-alias": {
"dev-master": "7.5-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Jeremy Lindblom",
"email": "jeremeamia@gmail.com",
"homepage": "https://github.com/jeremeamia"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle is a PHP HTTP client library",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"psr-18",
"psr-7",
"rest",
"web service"
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.5.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
"type": "tidelift"
}
],
"time": "2022-08-28T15:39:27+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "1.5.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "b94b2807d85443f9719887892882d0329d1e2598"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/b94b2807d85443f9719887892882d0329d1e2598",
"reference": "b94b2807d85443f9719887892882d0329d1e2598",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.4 || ^5.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/1.5.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
"type": "tidelift"
}
],
"time": "2022-08-28T14:55:35+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "2.4.4",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf",
"reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"ralouphie/getallheaders": "^3.0"
},
"provide": {
"psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.1",
"http-interop/http-factory-tests": "^0.9",
"phpunit/phpunit": "^8.5.29 || ^9.5.23"
},
"suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
},
"branch-alias": {
"dev-master": "2.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://sagikazarmark.hu"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"psr-7",
"request",
"response",
"stream",
"uri",
"url"
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.4.4"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
"type": "tidelift"
}
],
"time": "2023-03-09T13:19:02+00:00"
},
{
"name": "psr/http-client",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-client.git",
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"psr/http-message": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP clients",
"homepage": "https://github.com/php-fig/http-client",
"keywords": [
"http",
"http-client",
"psr",
"psr-18"
],
"support": {
"source": "https://github.com/php-fig/http-client/tree/master"
},
"time": "2020-06-29T06:28:15+00:00"
},
{
"name": "psr/http-factory",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-factory.git",
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
"shasum": ""
},
"require": {
"php": ">=7.0.0",
"psr/http-message": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interfaces for PSR-7 HTTP message factories",
"keywords": [
"factory",
"http",
"message",
"psr",
"psr-17",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-factory/tree/master"
},
"time": "2019-04-30T12:38:16+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-message/tree/master"
},
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/ralouphie/getallheaders.git",
"reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
"reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5 || ^6.5"
},
"type": "library",
"autoload": {
"files": [
"src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ralph Khattar",
"email": "ralph.khattar@gmail.com"
}
],
"description": "A polyfill for getallheaders.",
"support": {
"issues": "https://github.com/ralouphie/getallheaders/issues",
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
},
"time": "2019-03-08T08:55:37+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e",
"reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.3-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-03-01T10:25:55+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.8.52",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "a77e974a5fecb4398833b0709210e3d5e334ffb0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a77e974a5fecb4398833b0709210e3d5e334ffb0",
"reference": "a77e974a5fecb4398833b0709210e3d5e334ffb0",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "^2.0.5|~3.0.0",
"symfony/dependency-injection": "~2.6|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"symfony/stopwatch": "~2.3|~3.0.0"
},
"suggest": {
"symfony/dependency-injection": "",
"symfony/http-kernel": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\EventDispatcher\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/event-dispatcher/tree/v2.8.50"
},
"time": "2018-11-21T14:20:20+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

@ -2,11 +2,10 @@
namespace Model;
use API\script\Gateway\GatewayForm;
use API\script\Gateway\GatewayKeyword;
use API\script\Gateway\GatewayListResponseOfCandidate;
use API\script\Gateway\GatewayQuestion;
use BusinessClass\Form;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/**
* Permet de développer les fonctions appelées par le controllerAdmin pour gérer
@ -14,22 +13,41 @@ use BusinessClass\Form;
*/
class ModelAdmin
{
private Client $client;
public function __construct(){
$this->client = new Client();
}
/**
* Permet de créer et d'ajouter une question et de retourner son ID afin de la
* reconnaitre facilement dans la suite du code.
*
* @return int
* @throws Exception
*/
public function addQuestion(): int
{
$questionContent = $_POST['question'];
$type = $_POST['type'];
$question = new $type(0, $questionContent);
$form = (new GatewayForm())->getForm();
if (!empty($form)) {
return (new GatewayQuestion())->addQuestion($question, $form[0]['id']);
try {
$question = new $type(0, $questionContent);
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
$form = json_decode($res->getBody());
if (!empty($form)) {
$res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertQuestion?
content='.$questionContent.'&
classQuestion='.get_class($question).'&
idForm='.$form[0]['id'].'&
listPossibleResponse='.$question->getPossibleResponses().'&
listOfCategories='.$question->getCategories()
);
return json_decode($res->getBody());
}
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
return -1;
@ -41,7 +59,9 @@ class ModelAdmin
*
* @return void
*/
public function addResponse(): void
/*
* TODO: Changer les gateways et savoir qui garder parce que la ça commence à me casser les couilles
public function addResponse(): void
{
$idQuestion = $_POST['idQuestion'];
$response = $_POST['response'];
@ -51,18 +71,28 @@ class ModelAdmin
}
(new GatewayQuestion())->insertResponseInQuestion($response, $categories, $idQuestion);
}
*/
/**
* Permet de créer un nouveau formulaire en précisant son titre et sa description.
*
* @return void
* @throws Exception
*/
public function createForm(): void
{
if (empty((new GatewayForm())->getForm())) {
$form = new Form(0, "Votre avis nous intéresse !!!", "Description de notrer formulaire", array());
(new GatewayForm())->insertForm($form);
try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
$formulaire = json_decode($res->getBody());
if (empty($formulaire)) {
$form = new Form(0, "Votre avis nous intéresse !!!", "Description de notre formulaire", array());
$this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertForm?
title='.$form->getTitle().'&
description='.$form->getDescription()
);
}
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
}
@ -71,11 +101,18 @@ class ModelAdmin
* Permet d'ajouter une nouvelle catégorie (mot-clef)
*
* @return void
* @throws Exception
*/
public function addKeyword(): void
{
$keyword = $_POST['keyword'];
(new GatewayKeyword())->insertKeyword($keyword);
try {
$this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertKeyword?
keyword='.$keyword
);
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
}
@ -83,12 +120,19 @@ class ModelAdmin
* Permet de récupérer toutes les catégories existantes.
*
* @return array
* @throws Exception
*/
public function getCategories(): array
{
$categories = [];
foreach ((new GatewayKeyword())->getAllKeyword() as $category) {
$categories[] = $category["word"];
try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllKeyword');
$res = json_decode($res->getBody());
foreach ($res as $category) {
$categories[] = $category["word"];
}
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
return $categories;
@ -99,12 +143,21 @@ class ModelAdmin
* Permet de récupérer toutes les questions existantes.
*
* @return array
* @throws Exception
*/
public function getQuestions(): array
{
$idForm = (new GatewayForm())->getForm()[0]["id"];
$questionsArray = (new GatewayQuestion())->getAllQuestions($idForm);
return Factory::getBuiltObjects($questionsArray, "Question");
try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
$idForm = json_decode($res->getBody())[0]["id"];
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllQuestions?
idForm='.$idForm
);
$questionsArray = json_decode($res->getBody());
return Factory::getBuiltObjects($questionsArray, "Question");
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
}
@ -112,15 +165,23 @@ class ModelAdmin
* Permet de récupérer toutes les réponses existantes.
*
* @return array
* @throws Exception
*/
public function getResponsesCandidate(): array
{
$responsesCandidate = (new GatewayListResponseOfCandidate())->getAllListResponsesOfCandidate();
$results = [];
foreach ($responsesCandidate as $response) {
$results[] = (new GatewayListResponseOfCandidate())->getDetailsListResponsesOfCandidate($response["id"]);
try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllListResponsesOfCandidate');
$responsesCandidate = json_decode($res->getBody());
$results = [];
foreach ($responsesCandidate as $response) {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getDetailsListResponsesOfCandidate?
id='.$response["id"]
);
$results[] = json_decode($res->getBody());
}
return $results;
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
return $results;
}
}

Loading…
Cancel
Save