|
|
|
@ -7,6 +7,8 @@ use Exception;
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
|
use PDOException;
|
|
|
|
|
use Config\Validate;
|
|
|
|
|
use Config\Clean;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permet de développer les fonctions appelées par le controllerAdmin pour gérer
|
|
|
|
@ -39,26 +41,29 @@ class ModelAdmin
|
|
|
|
|
*/
|
|
|
|
|
public function addQuestion(): int
|
|
|
|
|
{
|
|
|
|
|
$questionContent = $_POST['question'];
|
|
|
|
|
$type = $_POST['type'];
|
|
|
|
|
$questionContent = Clean::simpleString($_POST['question']);
|
|
|
|
|
$type = Clean::simpleString($_POST['type']);
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (validate::type($type)) {
|
|
|
|
|
$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/addQuestion?
|
|
|
|
|
content='.$questionContent.'&
|
|
|
|
|
classQuestion='.get_class($question).'&
|
|
|
|
|
idForm='.$form[0]['id']
|
|
|
|
|
$res = $this->client->request(
|
|
|
|
|
'POST',
|
|
|
|
|
'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/addQuestion?
|
|
|
|
|
content='.$questionContent.'&
|
|
|
|
|
classQuestion='.get_class($question).'&
|
|
|
|
|
idForm='.$form[0]['id']
|
|
|
|
|
);
|
|
|
|
|
return json_decode($res->getBody());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('Type de question invalide');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException $g){
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -70,9 +75,12 @@ class ModelAdmin
|
|
|
|
|
*/
|
|
|
|
|
public function deleteQuestion():void
|
|
|
|
|
{
|
|
|
|
|
$idQuestion = $_POST["idQuestion"];
|
|
|
|
|
$type = $_POST["type"];
|
|
|
|
|
$idQuestion = Clean::int($_POST["idQuestion"]);
|
|
|
|
|
$type = Clean::simpleString($_POST["type"]);
|
|
|
|
|
try {
|
|
|
|
|
if (!validate::type($type)) {
|
|
|
|
|
throw new Exception('Type de question invalide');
|
|
|
|
|
}
|
|
|
|
|
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteQuestion?
|
|
|
|
|
classQuestion='.$type.'&
|
|
|
|
|
id='.$idQuestion
|
|
|
|
@ -93,13 +101,16 @@ class ModelAdmin
|
|
|
|
|
*/
|
|
|
|
|
public function addResponse(): void
|
|
|
|
|
{
|
|
|
|
|
$idQuestion = $_POST['idQuestion'];
|
|
|
|
|
$response = $_POST['response'];
|
|
|
|
|
$categories = $_POST['categories'];
|
|
|
|
|
$idQuestion = Clean::int($_POST['idQuestion']);
|
|
|
|
|
$response = Clean::simpleString($_POST['response']);
|
|
|
|
|
$categories = Clean::simpleStringArray($_POST['categories']);
|
|
|
|
|
if ($categories == null) {
|
|
|
|
|
$categories = [];
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if(!validate::categories($categories)){
|
|
|
|
|
throw new Exception('Categories invalides');
|
|
|
|
|
}
|
|
|
|
|
$this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertResponseInQuestion?
|
|
|
|
|
response='.$response.'&
|
|
|
|
|
categories='.$categories.'&
|
|
|
|
@ -162,8 +173,11 @@ class ModelAdmin
|
|
|
|
|
*/
|
|
|
|
|
public function addKeyword(): void
|
|
|
|
|
{
|
|
|
|
|
$keyword = $_POST['keyword'];
|
|
|
|
|
$keyword = Clean::simpleString($_POST['keyword']);
|
|
|
|
|
try {
|
|
|
|
|
if(!validate::keyword($keyword)){
|
|
|
|
|
throw new Exception('Mot-clef invalide');
|
|
|
|
|
}
|
|
|
|
|
$this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertKeyword?
|
|
|
|
|
keyword='.$keyword
|
|
|
|
|
);
|
|
|
|
@ -276,7 +290,7 @@ class ModelAdmin
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteListResponseOfCandidate?
|
|
|
|
|
id='.$_POST["idResponseCandidate"]
|
|
|
|
|
id='.Clean::int($_POST["idResponseCandidate"])
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
throw new Exception('DeleteListResponseOfCandidate failed');
|
|
|
|
|