You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.5 KiB
138 lines
3.5 KiB
<?php
|
|
|
|
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 PDOException;
|
|
|
|
/**
|
|
* Permet de développer les fonctions appelées par le controllerAdmin pour gérer
|
|
* les actions de l'administrateur
|
|
*/
|
|
class ModelAdmin
|
|
{
|
|
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($question, $form[0]['id']);
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
|
|
/**
|
|
* 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 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 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
|
|
{
|
|
$idForm = (new GatewayForm())->getForm()[0]["id"];
|
|
$questionsArray = (new GatewayQuestion())->getAllQuestions($idForm);
|
|
return Factory::getBuiltObjects($questionsArray, "Question");
|
|
}
|
|
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|