From 9a2ca2e3ba464ad895530e592949b4756ec7954a Mon Sep 17 00:00:00 2001 From: "victor.soulier" Date: Sun, 19 Nov 2023 12:50:55 +0100 Subject: [PATCH] ADD : mdl, metier, gw scientifique --- .../model/gateways/ScientifiqueGateway.php | 18 +++ .../src/model/gateways/ScientistGateway.php | 16 --- project/src/model/mdl/MdlScientifique.php | 40 ++++++ project/src/model/metier/Scientifique.php | 124 ++++++++++++++++++ 4 files changed, 182 insertions(+), 16 deletions(-) create mode 100644 project/src/model/gateways/ScientifiqueGateway.php delete mode 100644 project/src/model/gateways/ScientistGateway.php create mode 100644 project/src/model/mdl/MdlScientifique.php create mode 100644 project/src/model/metier/Scientifique.php diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php new file mode 100644 index 0000000..a863ea2 --- /dev/null +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -0,0 +1,18 @@ +con = $con; + } + + public function getRandom(): array|bool{ + $this->con->executeQuery( + "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, idsexe FROM Scientifique ORDER BY RANDOM() LIMIT 1;"); + return $this->con->getOneResult(); + } +} \ No newline at end of file diff --git a/project/src/model/gateways/ScientistGateway.php b/project/src/model/gateways/ScientistGateway.php deleted file mode 100644 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/mdl/MdlScientifique.php b/project/src/model/mdl/MdlScientifique.php new file mode 100644 index 0000000..6ea01da --- /dev/null +++ b/project/src/model/mdl/MdlScientifique.php @@ -0,0 +1,40 @@ +gw = new ScientifiqueGateway($this->con); + $this->mdlSexe = new MdlSexe(); + $this->mdlDifficulte = new MdlDifficulte(); + $this->mdlThematique = new MdlThematique(); + } + + public function getRandom(): Scientifique{ + $row = $this->gw->getRandom(); + if($row == false) throw new RuntimeException("Erreur aucun scientifique trouvé"); + $sexe = $this->mdlSexe->getFromId($row['idsexe']); + $difficulte = $this->mdlDifficulte->getFromId($row['iddifficulte']); + $thematique = $this->mdlThematique->getFromId($row['idthematique']); + + return new Scientifique($row['id'], + $row['nom'], + $row['prenom'], + $row['photo'], + new DateTime($row['datenaissance']), + $row['descriptif'], + $row['ratiotrouvee'], + $thematique, + $difficulte, + $sexe); + } +} \ No newline at end of file diff --git a/project/src/model/metier/Scientifique.php b/project/src/model/metier/Scientifique.php new file mode 100644 index 0000000..85d65a5 --- /dev/null +++ b/project/src/model/metier/Scientifique.php @@ -0,0 +1,124 @@ +id = $id; + $this->nom = $nom; + $this->prenom = $prenom; + $this->photo = $photo; + $this->ratioTrouvee = $ratioTrouvee; + $this->descriptif = $descriptif; + $this->dateNaiss = $dateNaiss; + $this->thematique = $thematique; + $this->difficulte = $difficulte; + $this->sexe = $sexe; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getNom(): string + { + return $this->nom; + } + + /** + * @return string + */ + public function getPrenom(): string + { + return $this->prenom; + } + + /** + * @return string + */ + public function getPhoto(): string + { + return $this->photo; + } + + /** + * @return string + */ + public function getDescriptif(): string + { + return $this->descriptif; + } + + /** + * @return DateTime + */ + public function getDateNaiss(): DateTime + { + return $this->dateNaiss; + } + + /** + * @return float + */ + public function getRatioTrouvee(): float + { + return $this->ratioTrouvee; + } + + /** + * @return Thematique + */ + public function getThematique(): Thematique + { + return $this->thematique; + } + + /** + * @return Difficulte + */ + public function getDifficulte(): Difficulte + { + return $this->difficulte; + } +} \ No newline at end of file