From 7cd47655472040f79a1ce10492a72a2a8b71f9b5 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Wed, 22 Nov 2023 16:46:34 +0100 Subject: [PATCH 1/3] =?UTF-8?q?verifier=20les=20donn=C3=A9es=20avant=20d'a?= =?UTF-8?q?jouter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/src/controller/AdminController.php | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index 0f1e7c1..4bc5f7f 100755 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -40,6 +40,13 @@ class AdminController { if(isset($_GET["id"])){ $id=intval($_GET["id"]); } + try{ + $this->verifierDonnees(); + } catch (Exception $ex){ + $dVueErreur[] = 'Erreur : '.$ex; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + return; + } $sci = new Scientifique( $id, $_POST["name"], @@ -92,6 +99,39 @@ class AdminController { } + private function verifierDonnees(){ + $sexe = new MdlSexe(); + $theme = new MdlThematique(); + $diff = new MdlDifficulte(); + $selectTheme=$theme->getFromId(intval($_POST["theme"])); + $selectDiff=$diff->getFromId(intval($_POST["difficulte"])); + $selectSexe=$sexe->getFromId(intval($_POST["sexe"])); + //todo : verifier les données, mettre dans une fonction et try catch + if(strlen($_POST["name"]) < 2){ + throw new Exception("nom trop court"); + } + if(strlen($_POST["prenom"]) < 2){ + throw new Exception("prénom trop court"); + } + if(empty($_POST["url"])){ + throw new Exception("pas de photo"); + } + if(strlen($_POST["name"]) < 2){ + throw new Exception("nom trop court"); + } + if(strlen($_POST["description"]) < 20){ + throw new Exception("description trop courte "); + } + if($selectTheme==null){ + throw new Exception("thematique inconnue"); + } + if($selectSexe==null){ + throw new Exception("sexe inconnu"); + } + if($selectDiff==null){ + throw new Exception("difficulté inconnue"); + } + } } ?> \ No newline at end of file From 54198a8f420a9a09b30ecce338434d7cdb563b72 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Wed, 22 Nov 2023 16:46:50 +0100 Subject: [PATCH 2/3] fix erreur lors ajout sci --- project/src/model/gateways/ScientifiqueGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php index d47dbb3..d8f193f 100755 --- a/project/src/model/gateways/ScientifiqueGateway.php +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -45,7 +45,7 @@ class ScientifiqueGateway ":idThematique"=>[$sci->getThematique()->getId(),$this->con::PARAM_STR], ":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR], ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR] - ]); + ]) ? true : false ; } public function getScientifiquesParPages(int $currentPage, int $nbElemByPage) : array { From c4c29b85a5d6e44790e551b864df96c62db4d087 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Wed, 22 Nov 2023 17:00:58 +0100 Subject: [PATCH 3/3] idem edit --- project/src/model/gateways/ScientifiqueGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php index d8f193f..322fb30 100755 --- a/project/src/model/gateways/ScientifiqueGateway.php +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -82,7 +82,7 @@ class ScientifiqueGateway ":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR], ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR], ":id"=>[$sci->getId(),$this->con::PARAM_INT] - ]); + ]) ? true : false ; } /**