User can submit a form, and admin can add keywords
continuous-integration/drone/push Build is passing Details

LoginModification
Alexis 2 years ago
parent 0f2971594e
commit 22f7ea87fd

@ -4,6 +4,7 @@ namespace API\script\Gateway;
use API\script\Config\Connection; use API\script\Config\Connection;
use BusinessClass\Keyword; use BusinessClass\Keyword;
use PDO;
class GatewayKeyword class GatewayKeyword
{ {
@ -14,20 +15,19 @@ class GatewayKeyword
$this->connection = connect(); $this->connection = connect();
} }
public function insertKeyword(Keyword $keyword) public function insertKeyword(string $word): void
{ {
$query = "INSERT INTO Keyword(id, word) VALUES(:id, :word)"; $query = "INSERT INTO Keyword(word) VALUES(:word)";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
':id' => array($keyword->getId(), PDO::PARAM_INT), ':word' => array($word, PDO::PARAM_STR)
':word' => array($keyword->getWord(), PDO::PARAM_INT)
)); ));
} }
public function deleteKeyword(Keyword $keyword) public function deleteKeyword(string $word): void
{ {
$query = "DELETE FROM Keyword WHERE id = :id"; $query = "DELETE FROM Keyword WHERE word = :word";
$this->connection->executeQuery($query, array( $this->connection->executeQuery($query, array(
':id' => array($keyword->getId(), PDO::PARAM_INT) ':word' => array($word, PDO::PARAM_STR)
)); ));
} }

@ -22,6 +22,7 @@ class CheckBoxQuestion extends BoxQuestion
public function printStrategy(): string public function printStrategy(): string
{ {
$id = $this->getId();
$content = $this->getContent(); $content = $this->getContent();
$possibleResponses = $this->getPossibleResponses(); $possibleResponses = $this->getPossibleResponses();
$categories = $this->getCategories(); $categories = $this->getCategories();
@ -31,7 +32,7 @@ class CheckBoxQuestion extends BoxQuestion
for($i = 0; $i < count($possibleResponses); $i++) for($i = 0; $i < count($possibleResponses); $i++)
{ {
$categoriesSplit = $possibleResponses[$i]."||"; $categoriesSplit = $id."#".$possibleResponses[$i]."||";
foreach ($categories[$i] as $category) foreach ($categories[$i] as $category)
{ {
$categoriesSplit.= $category."_"; $categoriesSplit.= $category."_";

@ -22,6 +22,7 @@ class ListBoxQuestion extends BoxQuestion
public function printStrategy(): string public function printStrategy(): string
{ {
$id = $this->getId();
$content = $this->getContent(); $content = $this->getContent();
$possibleResponses = $this->getPossibleResponses(); $possibleResponses = $this->getPossibleResponses();
$categories = $this->getCategories(); $categories = $this->getCategories();
@ -32,12 +33,12 @@ class ListBoxQuestion extends BoxQuestion
for($i = 0; $i < count($possibleResponses); $i++) for($i = 0; $i < count($possibleResponses); $i++)
{ {
$categoriesAndResponsesSplit = $possibleResponses[$i]."_"; $categoriesSplit = $id."#".$possibleResponses[$i]."||";
foreach ($categories[$i] as $category) foreach ($categories[$i] as $category)
{ {
$categoriesAndResponsesSplit.= $category."_"; $categoriesSplit.= $category."_";
} }
$html.= "\t\t\t\t\t<option value='$categoriesAndResponsesSplit'>$possibleResponses[$i]</option>\n"; $html.= "\t\t\t\t\t<option value='$categoriesSplit'>$possibleResponses[$i]</option>\n";
} }
$html.= "\t\t\t\t</select> $html.= "\t\t\t\t</select>
</div>\n"; </div>\n";

@ -21,4 +21,9 @@ class ControllerAdmin
global $rep, $views; global $rep, $views;
require($rep.$views['admin']); require($rep.$views['admin']);
} }
public function addKeyword(): void
{
(new ModelAdmin())->addKeyword();
}
} }

@ -3,6 +3,7 @@
namespace Model; namespace Model;
use API\script\Gateway\GatewayForm; use API\script\Gateway\GatewayForm;
use API\script\Gateway\GatewayKeyword;
use API\script\Gateway\GatewayQuestion; use API\script\Gateway\GatewayQuestion;
use BusinessClass\Form; use BusinessClass\Form;
use BusinessClass\ListBoxQuestion; use BusinessClass\ListBoxQuestion;
@ -53,4 +54,10 @@ class ModelAdmin
(new GatewayForm())->insertForm($form); (new GatewayForm())->insertForm($form);
} }
} }
public function addKeyword(): void
{
$keyword = $_POST['keyword'];
(new GatewayKeyword())->insertKeyword($keyword);
}
} }

@ -12,42 +12,47 @@ class ModelCandidate
{ {
$answersAndCategories = $_POST['answers']; $answersAndCategories = $_POST['answers'];
$answers = array(); $id = [];
$answer = [];
$category = [];
foreach ($answersAndCategories as $answerAndCategory) foreach ($answersAndCategories as $answerAndCategory)
{ {
$answer = explode("_", $answerAndCategory); $idAndAnswer = explode("||", $answerAndCategory)[0];
$answer = reset($answer); $id[] = explode("#", $idAndAnswer)[0];
$answers[] = $answer; $answer[] = explode("#", $idAndAnswer)[1];
$categs = explode("||", $answerAndCategory)[1];
$categs = explode("_", $categs);
array_pop($categs);
$category[] = $categs;
}
var_dump($id);
echo "<br>";
var_dump($answer);
echo "<br>";
var_dump($category);
echo "<br><br>";
for($i = 0; $i < count($answer); $i++)
{
// (new GatewayResponse())->insertResponse($id[$i], $answer[$i], $category[$i]);
} }
} }
public function getForm(): string public function getForm(): string
{ {
/*
$title = "Candidature à un témoignage";
$description = "Ce formulaire vous permet de candidater à un potentiel témoignage vidéo.";
$questions = array(
new TextQuestion("Décrivez-nous votre parcours en quelques lignes :"),
new ListBoxQuestion(array("Oui", "Non"), "Êtes-vous originaire de Clermont et ses alentours ? (- de 2 heures de trajet)", array(array("Clermont"), array("OrigineLointaine"))),
new ListBoxQuestion(array("BAC Général", "BAC Pro", "Étude supérieure"), "Quel étude avez-vous réalisé avant l'IUT?", array(array("Général"), array("Pro"), array("EtudSupp"))),
new CheckBoxQuestion(array("Mathématiques", "Web", "Mobile", "Gestion"), "Quels matières appréciez-vous ?", array(array("Maths", "Maths2", "Maths3"), array("Web"), array(""), array("Gestion", "Gestion2"))),
);
$form = new Form($title, $description, $questions);
*/
$form = (new GatewayForm())->getForm(); $form = (new GatewayForm())->getForm();
if(empty($form)) if(empty($form))
{ {
return "PAS DE FORMULAIRE\n"; return "PAS DE FORMULAIRE\n";
} }
$title = $form[0]['title']; $title = $form[0]['title'];
$description = $form[0]['description']; $description = $form[0]['description'];
$questionsTab = (new GatewayQuestion())->getAllQuestions($form[0]['id']); $questionsTab = (new GatewayQuestion())->getAllQuestions($form[0]['id']);
$questions = []; $questions = [];
for($i = 0; $i < count($questionsTab[0]); $i++) for($i = 0; $i < count($questionsTab[0]); $i++)
@ -75,16 +80,23 @@ class ModelCandidate
<div id='container_form'>\n <div id='container_form'>\n
<form method='post'>\n"; <form method='post'>\n";
foreach ($questions as $question) foreach ($questions as $question)
{ {
$html.= $question->printStrategy()."\n"; $html.= $question->printStrategy()."\n";
} }
if(count($questions) > 0)
{
$html.= "\t\t\t<input type='submit'>\n $html.= "\t\t\t<input type='submit'>\n
\t\t\t<input type='hidden' name='action' value='submitForm'> \t\t\t<input type='hidden' name='action' value='submitForm'>
\t\t</form>\n \t\t</form>\n
\t</div>\n"; \t</div>\n";
}
else
{
$html.= "\t\t</form>\n
\t</div>\n";
}
return $html; return $html;
} }

@ -15,6 +15,14 @@
<img id="logoUCA" src="https://cdn.uca.fr/images/logos/logo_uca_mini_light.png" height="35px" alt="logo UCA"> <img id="logoUCA" src="https://cdn.uca.fr/images/logos/logo_uca_mini_light.png" height="35px" alt="logo UCA">
<h1>Administration</h1> <h1>Administration</h1>
<h2>Ajouter une catégories :</h2>
<form method="post">
<label>Écrivez la catégorie : </label>
<input name="keyword" type="text" size="50">
<input type="submit" value="Ajouter">
<input type="hidden" name="action" value="addKeyword">
</form>
<h2>Ajouter une question :</h2> <h2>Ajouter une question :</h2>
<form method="post"> <form method="post">
@ -26,8 +34,8 @@
<label>Séléctionnez le type de question souhaitée : <label>Séléctionnez le type de question souhaitée :
<br>- Text permet à l'utilisateur d'écrire lui même la réponse. <br>- Text permet à l'utilisateur d'écrire lui même la réponse.
<br>- ListBox permet à l'utilisateur de choisir une réponse parmis plusieurs possibilités. <br>- ListBox permet à l'utilisateur de choisir une réponse parmi plusieurs possibilités.
<br>- CheckBox permet à l'utilisateur de choisir une ou plusieurs réponses parmis plusieurs possibilités. <br>- CheckBox permet à l'utilisateur de choisir une ou plusieurs réponses parmi plusieurs possibilités.
</label> </label>
<br> <br>
<select name="type"> <select name="type">

Loading…
Cancel
Save