|
|
|
@ -19,14 +19,15 @@ class ModelAdmin
|
|
|
|
|
{
|
|
|
|
|
private Client $client;
|
|
|
|
|
|
|
|
|
|
public function __construct(){
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->client = new Client(['headers' => ['Content-Type' => 'application/json'], 'verify' => false]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function goToAdmin(): void
|
|
|
|
|
{
|
|
|
|
|
global $rep, $views;
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
require_once($rep . $views['admin']);
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
$error = $e->getMessage();
|
|
|
|
@ -45,33 +46,33 @@ class ModelAdmin
|
|
|
|
|
$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');
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
throw new Exception('GetForm failed');
|
|
|
|
|
}
|
|
|
|
|
$form = json_decode($res->getBody());
|
|
|
|
|
echo $form;
|
|
|
|
|
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']
|
|
|
|
|
);
|
|
|
|
|
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');
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
throw new Exception('AddQuestion failed');
|
|
|
|
|
throw new Exception('GetForm failed');
|
|
|
|
|
}
|
|
|
|
|
return json_decode($res->getBody());
|
|
|
|
|
$form = json_decode($res->getBody());
|
|
|
|
|
echo $form;
|
|
|
|
|
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']
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('AddQuestion failed');
|
|
|
|
|
}
|
|
|
|
|
return json_decode($res->getBody());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('Type de question invalide');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('Type de question invalide');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g) {
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
@ -94,12 +95,12 @@ class ModelAdmin
|
|
|
|
|
'classQuestion='.$type.'&'.
|
|
|
|
|
'id='.$idQuestion
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('DeleteQuestion failed');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g) {
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -118,7 +119,7 @@ class ModelAdmin
|
|
|
|
|
$categories = [];
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if(!validate::categories($categories)){
|
|
|
|
|
if (!validate::categories($categories)) {
|
|
|
|
|
throw new Exception('Categories invalides');
|
|
|
|
|
}
|
|
|
|
|
$res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertResponseInQuestion?'.
|
|
|
|
@ -126,12 +127,12 @@ class ModelAdmin
|
|
|
|
|
'categories='.json_encode($categories).'&'.
|
|
|
|
|
'idQuestion='.$idQuestion
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('InsertResponseInQuestion failed');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -147,12 +148,12 @@ class ModelAdmin
|
|
|
|
|
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deletePossibleResponse?'.
|
|
|
|
|
'id='.$_POST["possibleResponse"]
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('DeletePossibleResponse failed');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException $g) {
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -176,13 +177,13 @@ class ModelAdmin
|
|
|
|
|
'title='.$form->getTitle().'&'.
|
|
|
|
|
'description='.$form->getDescription()
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('InsertForm failed');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException $g) {
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -197,18 +198,18 @@ class ModelAdmin
|
|
|
|
|
{
|
|
|
|
|
$keyword = Clean::simpleString($_POST['keyword']);
|
|
|
|
|
try {
|
|
|
|
|
if(!validate::keyword($keyword)){
|
|
|
|
|
if (!validate::keyword($keyword)) {
|
|
|
|
|
throw new Exception('Mot-clef invalide');
|
|
|
|
|
}
|
|
|
|
|
$res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertKeyword?'.
|
|
|
|
|
'keyword='.$keyword
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('InsertKeyword failed');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -224,12 +225,12 @@ class ModelAdmin
|
|
|
|
|
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteKeyword?'.
|
|
|
|
|
'keyword='.$_POST["idCateg"]
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('DeleteKeyword failed');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -244,16 +245,16 @@ class ModelAdmin
|
|
|
|
|
$categories = [];
|
|
|
|
|
try {
|
|
|
|
|
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllKeyword');
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('GetAllKeyword failed');
|
|
|
|
|
}
|
|
|
|
|
$res = json_decode($res->getBody());
|
|
|
|
|
foreach ($res as $category) {
|
|
|
|
|
$categories[] = $category["word"];
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException $g){
|
|
|
|
|
} catch (GuzzleException $g) {
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $categories;
|
|
|
|
@ -270,28 +271,28 @@ class ModelAdmin
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/existsForm');
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('Exists failed');
|
|
|
|
|
}
|
|
|
|
|
if (json_decode($res->getBody())){
|
|
|
|
|
if (json_decode($res->getBody())) {
|
|
|
|
|
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('GetForm failed');
|
|
|
|
|
}
|
|
|
|
|
$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);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('GetAllQuestions failed');
|
|
|
|
|
}
|
|
|
|
|
$questionsArray = json_decode($res->getBody());
|
|
|
|
|
return Factory::getBuiltObjects($questionsArray, "Question");
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -306,7 +307,7 @@ class ModelAdmin
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllListResponseOfCandidate');
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('GetAllListResponsesOfCandidate failed');
|
|
|
|
|
}
|
|
|
|
|
$responsesCandidate = json_decode($res->getBody());
|
|
|
|
@ -314,15 +315,15 @@ class ModelAdmin
|
|
|
|
|
foreach ($responsesCandidate as $response) {
|
|
|
|
|
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getDetailsListResponseOfCandidate?'.
|
|
|
|
|
'id='.$response->id);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('GetDetailsListResponsesOfCandidate failed');
|
|
|
|
|
}
|
|
|
|
|
$results[] =json_decode($res->getBody());
|
|
|
|
|
}
|
|
|
|
|
return $results;
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -338,12 +339,12 @@ class ModelAdmin
|
|
|
|
|
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteListResponseOfCandidate?'.
|
|
|
|
|
'id='.Clean::int($_POST["idResponseCandidate"])
|
|
|
|
|
);
|
|
|
|
|
if ($res->getStatusCode()!=200){
|
|
|
|
|
if ($res->getStatusCode() != 200) {
|
|
|
|
|
throw new Exception('DeleteListResponseOfCandidate failed');
|
|
|
|
|
}
|
|
|
|
|
}catch (GuzzleException | ClientException $g){
|
|
|
|
|
echo "Error : ".$g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(),$g->getCode(),$g);
|
|
|
|
|
} catch (GuzzleException | ClientException $g) {
|
|
|
|
|
echo "Error : " . $g->getMessage();
|
|
|
|
|
throw new Exception($g->getMessage(), $g->getCode(), $g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|