client = new Client(); } public function goToAdmin(): void { global $rep, $views; try{ require_once($rep . $views['admin']); } catch (PDOException $e) { $error = $e->getMessage(); require_once($rep . $views['form']); } } /** * 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 */ 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(array(get_class($question) ,$question->getContent()), $form[0]['id']); } return -1; } /** * Permet de supprimer une question du formulaire * * @return void * @throws Exception */ public function deleteQuestion():void { $idQuestion = $_POST["idQuestion"]; $type = $_POST["type"]; try { $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteQuestion? classQuestion='.$type.'& id='.$idQuestion ); if ($res->getStatusCode()!=200){ throw new Exception('DeleteQuestion failed'); } }catch (GuzzleException $g){ throw new Exception($g->getMessage(),$g->getCode(),$g); } } /** * Permet d'ajouter une possibilité de réponse à une question en l'assignant à des catégories. * * @return void */ public function addResponse(): void { $idQuestion = $_POST['idQuestion']; $response = $_POST['response']; $categories = $_POST['categories']; if ($categories == null) { $categories = []; } (new GatewayQuestion())->insertResponseInQuestion($response, $categories, $idQuestion); } /** * Permet de supprimer une possible réponse à une question * * @return void * @throws Exception */ public function deleteResponse(): void { try { $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deletePossibleResponse? id='.$_POST["possibleResponse"] ); if ($res->getStatusCode()!=200){ throw new Exception('DeletePossibleResponse failed'); } }catch (GuzzleException $g){ throw new Exception($g->getMessage(),$g->getCode(),$g); } } /** * Permet de créer un nouveau formulaire en précisant son titre et sa description. * * @return void */ 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); } } /** * Permet d'ajouter une nouvelle catégorie (mot-clef) * * @return void */ public function addKeyword(): void { $keyword = $_POST['keyword']; (new GatewayKeyword())->insertKeyword($keyword); } /** * Permet de supprimer une catégorie (mot-clef) * * @return void * @throws Exception */ public function deleteKeyword(): void { try { $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteKeyword? keyword='.$_POST["idCateg"] ); if ($res->getStatusCode()!=200){ throw new Exception('DeleteKeyword failed'); } }catch (GuzzleException $g){ throw new Exception($g->getMessage(),$g->getCode(),$g); } } /** * Permet de récupérer toutes les catégories existantes. * * @return array */ public function getCategories(): array { $categories = []; foreach ((new GatewayKeyword())->getAllKeyword() as $category) { $categories[] = $category["word"]; } return $categories; } /** * Permet de récupérer toutes les questions existantes. * * @return array */ public function getQuestions(): array { if((new GatewayForm())->existsForm()) { $idForm = (new GatewayForm())->getForm()[0]["id"]; $questionsArray = (new GatewayQuestion())->getAllQuestions($idForm); return Factory::getBuiltObjects($questionsArray, "Question"); } else { return array(); } } /** * Permet de récupérer toutes les réponses existantes. * * @return array */ public function getResponsesCandidate(): array { $responsesCandidate = (new GatewayListResponseOfCandidate())->getAllListResponsesOfCandidate(); $results = []; foreach ($responsesCandidate as $response) { $results[] = (new GatewayListResponseOfCandidate())->getDetailsListResponsesOfCandidate($response["id"]); } return $results; } /** * Permet de supprimer les réponses d'une personne d'un formulaire * * @return void * @throws Exception */ public function deleteResponsesCandidate(): void { try { $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteListResponseOfCandidate? id='.$_POST["idResponseCandidate"] ); if ($res->getStatusCode()!=200){ throw new Exception('DeleteListResponseOfCandidate failed'); } }catch (GuzzleException $g){ throw new Exception($g->getMessage(),$g->getCode(),$g); } } }