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.
SAE4.01_FORMULAIRE/Source/Model/ModelAdmin.php

73 lines
2.0 KiB

<?php
namespace Model;
use API\script\Gateway\GatewayForm;
use API\script\Gateway\GatewayKeyword;
use API\script\Gateway\GatewayQuestion;
use BusinessClass\Form;
class ModelAdmin
{
public function addQuestion(): void
{
$questionContent = $_POST['question'];
$type = $_POST['type'];
$responses = $_POST['responses'];
$categories = $_POST['categories'];
$responses = explode(";", $responses);
array_pop($responses);
$categories = explode(";", $categories);
$tmp = [];
foreach ($categories as $category) {
$tmp[] = explode(",", $category);
}
$categories = $tmp;
array_pop($categories);
if (strcmp($type, "BusinessClass\TextQuestion") == 0) {
$question = new $type($questionContent, 0);
} else {
$question = new $type($responses, $questionContent, $categories, 0);
}
$form = (new GatewayForm())->getForm();
if (!empty($form)) {
(new GatewayQuestion())->insertQuestion($question, $form[0]['id']);
}
}
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);
}
}
public function addKeyword(): void
{
$keyword = $_POST['keyword'];
(new GatewayKeyword())->insertKeyword($keyword);
}
public function getCategories(): array
{
$categories = [];
foreach ((new GatewayKeyword())->getAllKeyword() as $category)
$categories[] = $category["word"];
return $categories;
}
public function getQuestions(): array
{
$idForm = (new GatewayForm())->getForm()[0]["id"];
$questionsArray = (new GatewayQuestion())->getAllQuestions($idForm);
return Factory::getBuiltObjects($questionsArray, "Question");
}
}