From 730e478691507a30aae8172da4893eef5d029b38 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Tue, 21 Nov 2023 15:20:00 +0100 Subject: [PATCH 1/5] reajouter logout --- project/src/controller/UserController.php | 49 +++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/project/src/controller/UserController.php b/project/src/controller/UserController.php index d314d5e..6eea4d8 100755 --- a/project/src/controller/UserController.php +++ b/project/src/controller/UserController.php @@ -67,29 +67,34 @@ class UserController { public function login() { global $twig; - if($_SERVER['REQUEST_METHOD'] === 'POST'){ - Validation::valUserLogin($_REQUEST['login'], $dVueErreur); - $ug = new MdlUser(); - if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { - $_SESSION['pseudo'] = $_REQUEST['login']; - $_SESSION['isLogged'] = true; - header("Location: ."); - } else { - //voir si c'est un admin - $ug = new MdlAdmin(); - if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { - $_SESSION['pseudo'] = $_REQUEST['login']; - $_SESSION['isAdmin'] = true; - $_SESSION['isLogged'] = true; - header("Location: ."); - } else { - $dVueErreur[] = "Connexion échouée"; - throw new LoginException("Connexion err"); - } - } - } else { + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + Validation::valUserLogin($_REQUEST['login'], $dVueErreur); + $ug = new MdlUser(); + if ($ug->login($_REQUEST['login'], $_REQUEST['password'])) { + $_SESSION['pseudo'] = $_REQUEST['login']; + $_SESSION['isLogged'] = true; + header("Location: ."); + } else { + //voir si c'est un admin + $ug = new MdlAdmin(); + if ($ug->login($_REQUEST['login'], $_REQUEST['password'])) { + $_SESSION['pseudo'] = $_REQUEST['login']; + $_SESSION['isAdmin'] = true; + $_SESSION['isLogged'] = true; + header("Location: ."); + } else { + $dVueErreur[] = "Connexion échouée"; + throw new LoginException("Connexion err"); + } + } + } else { echo $twig->render('login.html'); - } + } + } + + public function logout(){ + $_SESSION=[]; + header("Location: ."); } public function createParty(array $params) : void From e971de12955c9ed275d1ef680ae979e2007ba1fd Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Tue, 21 Nov 2023 17:06:32 +0100 Subject: [PATCH 2/5] ajout get/edit MdlScientifque --- project/src/model/mdl/MdlScientifique.php | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/project/src/model/mdl/MdlScientifique.php b/project/src/model/mdl/MdlScientifique.php index bcac636..22a67ce 100755 --- a/project/src/model/mdl/MdlScientifique.php +++ b/project/src/model/mdl/MdlScientifique.php @@ -43,5 +43,39 @@ class MdlScientifique extends MdlBase{ } public function addScientifique(Scientifique $s){ return $this->gw->addScientifique($s); + } + public function editScientifique(Scientifique $s){ + return $this->gw->editScientifique($s); + } + + public function getScientifique(int $id){ + $t=$this->gw->getScientifique($id); + if(gettype($t)!="array"){ + throw new Exception("Scientifique non trouvé"); + } + + $sexe=new MdlSexe(); + $sexe=$sexe->getFromId($t["idsexe"]); + + $diff=new MdlDifficulte(); + $diff=$diff->getFromId($t["iddifficulte"]); + + $theme=new MdlThematique(); + $theme=$theme->getFromId($t["idthematique"]); + + return new Scientifique( + $id, + $t["nom"], + $t["prenom"], + $t["photo"], + DateTime::createFromFormat("Y-m-d", $t["datenaissance"]), + $t["descriptif"], + $t["ratiotrouvee"], + $theme, + $diff, + $sexe + ); + + } } \ No newline at end of file From c7255091ec1fde3f020c00594e839072952eea52 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Tue, 21 Nov 2023 17:06:56 +0100 Subject: [PATCH 3/5] ajout editScientifique --- .../model/gateways/ScientifiqueGateway.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php index b48c8d9..0893f84 100755 --- a/project/src/model/gateways/ScientifiqueGateway.php +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -41,4 +41,29 @@ class ScientifiqueGateway ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR] ]); } + public function editScientifique(Scientifique $sci): bool{ + return $this->con->executeQuery( + "UPDATE Scientifique SET nom = :nom, prenom = :prenom, photo = :photo, dateNaissance = :dateNaissance, descriptif = :descriptif, ratioTrouvee = :ratioTrouvee, idThematique = :idThematique, idDifficulte = :idDifficulte, idSexe = :idSexe WHERE id=:id;" + ,[ + ":nom"=>[$sci->getNom(),$this->con::PARAM_STR], + ":prenom"=>[$sci->getPrenom(),$this->con::PARAM_STR], + ":photo"=>[$sci->getPhoto(),$this->con::PARAM_STR], + ":dateNaissance"=>[date("Y-m-d H:i:s", $sci->getDateNaiss()->getTimestamp()),$this->con::PARAM_STR], + ":descriptif"=>[$sci->getDescriptif(),$this->con::PARAM_STR], + ":ratioTrouvee"=>[$sci->getRatioTrouvee(),$this->con::PARAM_STR], + ":idThematique"=>[$sci->getThematique()->getId(),$this->con::PARAM_STR], + ":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR], + ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR], + ":id"=>[$sci->getId(),$this->con::PARAM_INT] + ]); + } + + public function getScientifique(int $id): b { + $this->con->executeQuery( + "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, idSexe FROM Scientifique WHERE id=:id;" + ,[ + ":id"=>[$id,$this->con::PARAM_INT] + ]); + return $this->con->getOneResult(); + } } \ No newline at end of file From e327265d62e1af6f231ff746e22c037f861aac8f Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Tue, 21 Nov 2023 17:07:21 +0100 Subject: [PATCH 4/5] =?UTF-8?q?ajout=20possibilit=C3=A9=20de=20modifier=20?= =?UTF-8?q?scietififuqes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/src/controller/AdminController.php | 45 +++++++++++++------ .../templates/admin/ajouterScientifiques.html | 45 ++++++++++++++----- 2 files changed, 67 insertions(+), 23 deletions(-) diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index 9cc7486..2b9f4a8 100755 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -31,21 +31,37 @@ class AdminController { $sexe = new MdlSexe(); $theme = new MdlThematique(); $diff = new MdlDifficulte(); + $scient=null; if(!empty($_POST)){ - $sci=new MdlScientifique(); - $sci->addScientifique(new Scientifique(0, - $_POST["name"], - $_POST["prenom"], - $_POST["url"], - \DateTime::createFromFormat("Y-m-d",$_POST["date"]), - $_POST["description"], - 0, - $theme->getFromId(intval($_POST["theme"])), - $diff->getFromId(intval($_POST["difficulte"])), - $sexe->getFromId(intval($_POST["sexe"])) - )); + $id=0; + if(isset($_GET["id"])){ + $id=intval($_GET["id"]); + } + $sci = new Scientifique( + $id, + $_POST["name"], + $_POST["prenom"], + $_POST["url"], + \DateTime::createFromFormat("Y-m-d", $_POST["date"]), + $_POST["description"], + 0, + $theme->getFromId(intval($_POST["theme"])), + $diff->getFromId(intval($_POST["difficulte"])), + $sexe->getFromId(intval($_POST["sexe"])) + ); + $mdlsci=new MdlScientifique(); + if(isset($_GET["id"])){ + $mdlsci->editScientifique($sci); + } else { + $mdlsci->addScientifique($sci); + } } - echo $twig->render('admin/ajouterScientifiques.html',['sexe' => $sexe->getAll(), 'themes' => $theme->getAll(), 'difficultes' => $diff->getAll()]); + if(isset($_GET["id"])){ + $scient=new MdlScientifique(); + $scient=$scient->getScientifique($_GET["id"]); + } + + echo $twig->render('admin/ajouterScientifiques.html',['sexe' => $sexe->getAll(), 'themes' => $theme->getAll(), 'difficultes' => $diff->getAll(), 'scientifique' => $scient]); break; //mauvaise action default: @@ -59,6 +75,9 @@ class AdminController { } catch (\Exception $e2) { $dVueErreur[] = 'Erreur inattendue !'; echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + } catch (\Throwable $e2) { + $dVueErreur[] = 'Erreur !'; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); } } } diff --git a/project/src/templates/admin/ajouterScientifiques.html b/project/src/templates/admin/ajouterScientifiques.html index 82e80d9..a74d431 100644 --- a/project/src/templates/admin/ajouterScientifiques.html +++ b/project/src/templates/admin/ajouterScientifiques.html @@ -2,7 +2,7 @@ - Créer une partie + Créer un.e scientifique