From 1894de75c661b94e3857a0fcfb417dd9e164fbca Mon Sep 17 00:00:00 2001 From: Tom <147888129+Treize-tx@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:15:16 +0100 Subject: [PATCH 1/8] UPDATE:config.php inclu dans le .gitignore --- project/src/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/src/.gitignore b/project/src/.gitignore index da055ac..c588538 100755 --- a/project/src/.gitignore +++ b/project/src/.gitignore @@ -1,4 +1,5 @@ vendor/ composer.lock js/bootstrap*.js* -css/bootstrap*.css* \ No newline at end of file +css/bootstrap*.css* +config.php From cbd4862e6d428890006fb7ed9010911cb45d98dc Mon Sep 17 00:00:00 2001 From: Tom <147888129+Treize-tx@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:17:57 +0100 Subject: [PATCH 2/8] =?UTF-8?q?DELETE:=20ScientistGateway.php=20et=20UserG?= =?UTF-8?q?ateway.php=20supprim=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/model/gateways/ScientistGateway.php | 16 --- project/src/model/gateways/UserGateway.php | 113 ------------------ 2 files changed, 129 deletions(-) delete mode 100755 project/src/model/gateways/ScientistGateway.php delete mode 100755 project/src/model/gateways/UserGateway.php diff --git a/project/src/model/gateways/ScientistGateway.php b/project/src/model/gateways/ScientistGateway.php deleted file mode 100755 index d200eec..0000000 --- a/project/src/model/gateways/ScientistGateway.php +++ /dev/null @@ -1,16 +0,0 @@ -con = $co; - } - -// function findByName(string $name) :? Scientist { -// $usr = null; -// } -} \ No newline at end of file diff --git a/project/src/model/gateways/UserGateway.php b/project/src/model/gateways/UserGateway.php deleted file mode 100755 index 7563880..0000000 --- a/project/src/model/gateways/UserGateway.php +++ /dev/null @@ -1,113 +0,0 @@ -con=$con; - } - - public function login(string $email, string $password): bool - { - $sql = "SELECT * FROM Utilisateur WHERE email=:email"; - $this->con->executeQuery($sql, array( - ':email' => array($email, PDO::PARAM_STR) - )); - - $result = $this->con->getOneResult(); - - if (!empty($result)) { - return password_verify($password,$result['password']); - } - return false; - } - public function addUser(string $email, string $password): void - { - $sql = "INSERT INTO Utilisateur (email, password) VALUES (:email, :password)"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':email', $email); - $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); - $stmt->execute(); - } - public function deleteUser(int $id): void - { - $sql = "DELETE FROM Utilisateur WHERE idJoueur=:id"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':id', $id); - $stmt->execute(); - } - public function updateUser(int $id, string $email, string $password): void - { - $sql = "UPDATE Utilisateur SET email=:email, password=:password WHERE idJoueur=:id"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':id', $id); - $stmt->bindValue(':email', $email); - $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); - $stmt->execute(); - } - public function getUser(int $id): User - { - $sql = "SELECT * FROM Utilisateur WHERE idJoueur=:id"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':id', $id); - $stmt->execute(); - $result = $stmt->fetch(); - return new User($result['id'], $result['email'], $result['password']); - } - public function getUsers(): array - { - $sql = "SELECT * FROM utilisateur"; - $stmt = $this->con->prepare($sql); - $stmt->execute(); - $result = $stmt->fetchAll(); - $users = []; - foreach ($result as $user) { - $users[] = new User($user['id'], $user['email'], $user['password']); - } - return $users; - } - public function getHashedPasswordById(int $id): string - { - $sql = "SELECT password FROM Utilisateur WHERE idJoueur=:id"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':id', $id); - $stmt->execute(); - $result = $stmt->fetch(); - return $result['password']; - } - public function getHashedPassword(int $email): string - { - $sql = "SELECT password FROM Utilisateur WHERE email=:email"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':email', $email); - $stmt->execute(); - $result = $stmt->fetch(); - return $result['password']; - } - public function getUserId(string $email): int - { - $sql = "SELECT idJoueur FROM Utilisateur WHERE email=:email"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':email', $email); - $stmt->execute(); - $result = $stmt->fetch(); - return $result['id']; - } - public function getUserByEmailAndPassword(string $email, string $password): User - { - $sql = "SELECT * FROM utilisateur WHERE email=:email AND password=:password"; - $stmt = $this->con->prepare($sql); - $stmt->bindValue(':email', $email); - $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); - $stmt->execute(); - $result = $stmt->fetch(); - return new User($result['id'], $result['email'], $result['password']); - } -} From e971de12955c9ed275d1ef680ae979e2007ba1fd Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Tue, 21 Nov 2023 17:06:32 +0100 Subject: [PATCH 3/8] 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 4/8] 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 5/8] =?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