diff --git a/.idea/php.xml b/.idea/php.xml index b2ca53c..b673eaa 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -9,7 +9,7 @@ - + diff --git a/Source/API/script/APIController.php b/Source/API/script/APIController.php index 6f6e162..91bfcf2 100644 --- a/Source/API/script/APIController.php +++ b/Source/API/script/APIController.php @@ -13,10 +13,10 @@ class APIController } else { $action = $_REQUEST['action']; } - $listGateway = array(""); //TODO : nom des différentes Gateway à mettre + $listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion"); foreach ($listGateway as $gateway) // Pour chaque Gateway { - /* On regarde s'il implémente une fonction du même nom que l'action reçue */ + /* On regarde si elle implémente une fonction du même nom que l'action reçue */ if(method_exists($gateway, $action)) { (new $gateway)->$action(); // Si oui, on appelle cette fonction diff --git a/Source/API/script/Config/Connection.php b/Source/API/script/Config/Connection.php index 942a479..892f197 100644 --- a/Source/API/script/Config/Connection.php +++ b/Source/API/script/Config/Connection.php @@ -1,5 +1,10 @@ connection = connect(); + } + + public function insertForm(Form $form): void + { + if(empty($this->getForm())) + { + $query = "INSERT INTO Form(title, description) VALUES(:title, :description)"; + $this->connection->executeQuery($query, array( + ':title' => array($form->getTitle(), PDO::PARAM_STR), + ':description' => array($form->getDescription(), PDO::PARAM_STR) + )); + } + } + + public function getForm(): array { - $this->connection = $connection; + $query = "SELECT * FROM Form"; + $this->connection->executeQuery($query); + + return $this->connection->getResults(); } public function assignKeywordToQuestion(Keyword $keyword, string $response, int $idQuestion) @@ -23,17 +46,15 @@ class GatewayForm ':id' => array($idQuestion, PDO::PARAM_STR), ':response' => array($response, PDO::PARAM_STR) )); - $this->connection->executeQuery(); $idPossibleResponse = $this->connection->getResults()[0][0]; - $query = "INSERT INTO Reference(id, word) VALUES(:id, :word)"; + $query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)"; $this->connection->executeQuery($query, array( - ':idResponse' => array($idPossibleResponse, PDO::PARAM_INT), - ':idKeword' => array($keyword->getId(), PDO::PARAM_INT) + ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT), + ':keyword' => array($keyword->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); } public function deleteKeywordFromQuestion(Keyword $keyword, string $response, Question $question) @@ -43,7 +64,6 @@ class GatewayForm ':id' => array($question->getId(), PDO::PARAM_STR), ':response' => array($response, PDO::PARAM_STR) )); - $this->connection->executeQuery(); $idPossibleResponse = $this->connection->getResults()[0][0]; @@ -52,6 +72,5 @@ class GatewayForm ':idResponse' => array($idPossibleResponse, PDO::PARAM_INT), ':idKeword' => array($keyword->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); } } \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayKeyword.php b/Source/API/script/Gateway/GatewayKeyword.php index 4315ada..ea86e93 100644 --- a/Source/API/script/Gateway/GatewayKeyword.php +++ b/Source/API/script/Gateway/GatewayKeyword.php @@ -1,17 +1,19 @@ connection = $connection; + $this->connection = connect(); } public function insertKeyword(Keyword $keyword) @@ -21,7 +23,6 @@ class GatewayKeyword ':id' => array($keyword->getId(), PDO::PARAM_INT), ':word' => array($keyword->getWord(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); } public function deleteKeyword(Keyword $keyword) @@ -30,14 +31,12 @@ class GatewayKeyword $this->connection->executeQuery($query, array( ':id' => array($keyword->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); } public function getAllKeyword(): array { $query = "SELECT * FROM Keyword"; $this->connection->executeQuery($query); - $this->connection->executeQuery(); return $this->connection->getResults(); } diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index b710923..f5df47c 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -1,8 +1,10 @@ connection = $connection; + $this->connection = connect(); } - public function insertQuestion(Question $question, string $idForm) + public function insertQuestion(Question $question, int $idForm): void { $query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)"; $this->connection->executeQuery($query, array( ':content' => array($question->getContent(), PDO::PARAM_STR), ':type' => array(get_class($question), PDO::PARAM_STR), - ':form' => array($idForm, PDO::PARAM_STR) + ':form' => array($idForm, PDO::PARAM_INT) )); - $this->connection->executeQuery(); - $idQuestion = $this->connection->lastInsertId(); if(get_class($question) == BoxQuestion::class){ @@ -39,18 +39,14 @@ class GatewayQuestion ':content' => array($listPossibleResponse[$i], PDO::PARAM_STR) )); - $this->connection->executeQuery(); - - $idPossibleReponse = $this->connection->lastInsertId(); + $idPossibleResponse = $this->connection->lastInsertId(); $query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)"; $this->connection->executeQuery($query, array( ':question' => array($idQuestion, PDO::PARAM_INT), - ':possibleResponse' => array($idPossibleReponse, PDO::PARAM_INT) + ':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT) )); - $this->connection->executeQuery(); - foreach ($question->getCategories()[$i] as $keyword){ $gatewayForm = new GatewayForm($this->connection); @@ -60,14 +56,13 @@ class GatewayQuestion } } - public function deleteQuestion(Question $question) + public function deleteQuestion(Question $question): void { if(get_class($question) == BoxQuestion::class) { $query = "DELETE FROM Propose WHERE question = :id"; $this->connection->executeQuery($query, array( ':id' => array($question->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); $listPossibleResponse = $question->getPossibleResponses(); for ($i = 0; $i < count($listPossibleResponse); $i++){ @@ -75,13 +70,11 @@ class GatewayQuestion $this->connection->executeQuery($query, array( ':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); $query = "DELETE FROM PossibleResponse WHERE id = :id"; $this->connection->executeQuery($query, array( ':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); } } @@ -89,10 +82,9 @@ class GatewayQuestion $this->connection->executeQuery($query, array( ':id' => array($question->getId(), PDO::PARAM_INT) )); - $this->connection->executeQuery(); } - public function updateQuestion(Question $question) + public function updateQuestion(Question $question): void { $query = "UPDATE Question SET content = :content, type = :type, form = :form WHERE id = :id"; $this->connection->executeQuery($query, array( @@ -101,8 +93,6 @@ class GatewayQuestion ':form' => array($question->getForm(), PDO::PARAM_STR), ':id' => array($question->getId(), PDO::PARAM_STR) )); - - $this->connection->executeQuery(); } public function getAllQuestions(string $idForm): array //revoie un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox @@ -112,8 +102,6 @@ class GatewayQuestion ':form' => array($idForm, PDO::PARAM_STR) )); - $this->connection->executeQuery(); - $resultQuestion = $this->connection->getResults(); $possibleResponse = []; $keywordResponse = []; @@ -125,8 +113,6 @@ class GatewayQuestion ':id' => array($resultQuestion[$i]["id"], PDO::PARAM_STR) )); - $this->connection->executeQuery(); - $possibleResponse[] = $this->connection->getResults(); $tmpTab = []; foreach ($possibleResponse[$i] as $row){ @@ -136,8 +122,6 @@ class GatewayQuestion ':id' => array($row["id"], PDO::PARAM_STR) )); - $this->connection->executeQuery(); - $tmpTab[] = $this->connection->getResults(); } $keywordResponse[] = $tmpTab; diff --git a/Source/BusinessClass/BoxQuestion.php b/Source/BusinessClass/BoxQuestion.php index f8d6384..d929a35 100644 --- a/Source/BusinessClass/BoxQuestion.php +++ b/Source/BusinessClass/BoxQuestion.php @@ -12,10 +12,11 @@ abstract class BoxQuestion extends Question * @param array $possibleResponses * @param string $content * @param array $categories + * @param int $id */ - public function __construct(array $possibleResponses, string $content, array $categories) + public function __construct(array $possibleResponses, string $content, array $categories, int $id) { - parent::__construct($content); + parent::__construct($id, $content); $this->categories = $categories; $this->possibleResponses = $possibleResponses; } diff --git a/Source/BusinessClass/CheckBoxQuestion.php b/Source/BusinessClass/CheckBoxQuestion.php index 0ffca60..c81a9e1 100644 --- a/Source/BusinessClass/CheckBoxQuestion.php +++ b/Source/BusinessClass/CheckBoxQuestion.php @@ -8,10 +8,11 @@ class CheckBoxQuestion extends BoxQuestion * @param array $possibleResponses * @param string $content * @param array $categories + * @param int $id */ - public function __construct(array $possibleResponses, string $content, array $categories) + public function __construct(array $possibleResponses, string $content, array $categories, int $id) { - parent::__construct($possibleResponses, $content, $categories); + parent::__construct($possibleResponses, $content, $categories, $id); } public function responseStrategy() diff --git a/Source/BusinessClass/Form.php b/Source/BusinessClass/Form.php index 2a27158..6254c22 100644 --- a/Source/BusinessClass/Form.php +++ b/Source/BusinessClass/Form.php @@ -4,17 +4,20 @@ namespace BusinessClass; class Form { + private int $id; private string $title; private string $description; private array $questions; // La liste des questions dans un formulaire /** + * @param int $id * @param string $title * @param string $description * @param array $questions */ - public function __construct(string $title, string $description, array $questions) + public function __construct(int $id, string $title, string $description, array $questions) { + $this->id = $id; $this->title = $title; $this->description = $description; $this->questions = $questions; @@ -67,4 +70,12 @@ class Form { $this->questions = $questions; } -} \ No newline at end of file + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } +} diff --git a/Source/BusinessClass/Keyword.php b/Source/BusinessClass/Keyword.php index 320b5c9..cc9328b 100644 --- a/Source/BusinessClass/Keyword.php +++ b/Source/BusinessClass/Keyword.php @@ -4,13 +4,16 @@ namespace BusinessClass; class Keyword { + private int $id; private string $word; /** + * @param int $id * @param string $word */ - public function __construct(string $word) + public function __construct(int $id, string $word) { + $this->id = $id; $this->word = $word; } @@ -29,4 +32,12 @@ class Keyword { $this->word = $word; } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } } \ No newline at end of file diff --git a/Source/BusinessClass/ListBoxQuestion.php b/Source/BusinessClass/ListBoxQuestion.php index e93673f..bd03576 100644 --- a/Source/BusinessClass/ListBoxQuestion.php +++ b/Source/BusinessClass/ListBoxQuestion.php @@ -8,10 +8,11 @@ class ListBoxQuestion extends BoxQuestion * @param array $possibleResponses * @param string $content * @param array $categories + * @param int $id */ - public function __construct(array $possibleResponses, string $content, array $categories) + public function __construct(array $possibleResponses, string $content, array $categories, int $id) { - parent::__construct($possibleResponses, $content, $categories); + parent::__construct($possibleResponses, $content, $categories, $id); } public function responseStrategy() diff --git a/Source/BusinessClass/Question.php b/Source/BusinessClass/Question.php index c40733f..397be54 100644 --- a/Source/BusinessClass/Question.php +++ b/Source/BusinessClass/Question.php @@ -4,12 +4,16 @@ namespace BusinessClass; abstract class Question implements IResponseProcessingStrategy, IPrintQuestionStrategy { + private int $id; private string $content; + /** + * @param int $id * @param string $content */ - public function __construct(string $content) + public function __construct(int $id, string $content) { + $this->id = $id; $this->content = $content; } @@ -32,4 +36,12 @@ abstract class Question implements IResponseProcessingStrategy, IPrintQuestionSt { $this->content = $content; } -} \ No newline at end of file + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } +} diff --git a/Source/BusinessClass/TextQuestion.php b/Source/BusinessClass/TextQuestion.php index 3f81dfd..944ea72 100644 --- a/Source/BusinessClass/TextQuestion.php +++ b/Source/BusinessClass/TextQuestion.php @@ -6,10 +6,11 @@ class TextQuestion extends Question { /** * @param string $content + * @param int $id */ - public function __construct(string $content) + public function __construct(string $content, int $id) { - parent::__construct($content); + parent::__construct($id, $content); } public function responseStrategy() diff --git a/Source/Controller/ControllerAdmin.php b/Source/Controller/ControllerAdmin.php index a187da6..a1b6aab 100644 --- a/Source/Controller/ControllerAdmin.php +++ b/Source/Controller/ControllerAdmin.php @@ -2,7 +2,19 @@ namespace Controller; +use API\Gateway\GatewayQuestion; +use BusinessClass\ListBoxQuestion; +use Model\ModelAdmin; + class ControllerAdmin { + public function addQuestion(): void + { + (new ModelAdmin())->addQuestion(); + } + public function createForm(): void + { + (new ModelAdmin())->createForm(); + } } diff --git a/Source/Model/ModelAdmin.php b/Source/Model/ModelAdmin.php new file mode 100644 index 0000000..6ff29a9 --- /dev/null +++ b/Source/Model/ModelAdmin.php @@ -0,0 +1,36 @@ +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); + } + } + + +} diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 89981ed..0ff4df1 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -2,11 +2,9 @@ namespace Model; -use BusinessClass\CheckBoxQuestion; -use BusinessClass\Form; -use BusinessClass\ListBoxQuestion; +use API\script\Gateway\GatewayForm; +use API\script\Gateway\GatewayQuestion; use BusinessClass\TextQuestion; -use BusinessClass\YesNoQuestion; class ModelCandidate { @@ -17,7 +15,7 @@ class ModelCandidate public function getForm(): string { - /* TEMPORAIRE */ + /* $title = "Candidature à un témoignage"; $description = "Ce formulaire vous permet de candidater à un potentiel témoignage vidéo."; $questions = array( @@ -27,7 +25,37 @@ class ModelCandidate 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(); + if(empty($form)) + { + return "PAS DE FORMULAIRE\n"; + } + + $title = $form[0]['title']; + $description = $form[0]['description']; + $questionsTab = (new GatewayQuestion())->getAllQuestions($form[0]['id']); + + $questions = []; + + for($i = 0; $i < count($questionsTab[0]); $i++) + { + if(strcmp($questionsTab[0][$i]['type'], "TextQuestion") == 0) + { + $questions[] = new TextQuestion($questionsTab[0][$i]['content'], $questionsTab[0][$i]['id']); + } + else + { + $possiblesResponses = $questionsTab[1][$i]; + $content = $questionsTab[0][$i]['content']; + $categories = $questionsTab[2][$i]; + $id = $questionsTab[0][$i]['id']; + + $questions[] = new $questionsTab[0][$i]['type']($possiblesResponses, $content, $categories, $id); + } + } $html = "

$title

\n diff --git a/Source/Model/a b/Source/Model/a deleted file mode 100644 index e69de29..0000000