From c09ce09b267f34dee8978397953b90d55d7d3873 Mon Sep 17 00:00:00 2001 From: "kevin.monteiro" Date: Mon, 20 Nov 2023 08:08:00 +0100 Subject: [PATCH] Gateway, Entity, Mappeur : Coach, Athlete et Activite --- .../src/data/core/database/ActiviteEntity.php | 125 ++++++++++++++++++ .../data/core/database/ActiviteGateway.php | 61 +++++++++ .../src/data/core/database/ActiviteMapper.php | 24 ++++ .../src/data/core/database/AthleteEntity.php | 89 +++++++++++++ .../src/data/core/database/AthleteGateway.php | 75 +++++++++++ .../src/data/core/database/AthleteMapper.php | 20 +++ .../src/data/core/database/CoachEntity.php | 89 +++++++++++++ .../src/data/core/database/CoachGateway.php | 55 ++++++++ .../src/data/core/database/CoachMapper.php | 20 +++ .../src/data/core/database/UserGateway.php | 50 ------- 10 files changed, 558 insertions(+), 50 deletions(-) create mode 100644 Sources/src/data/core/database/ActiviteEntity.php create mode 100644 Sources/src/data/core/database/ActiviteGateway.php create mode 100644 Sources/src/data/core/database/ActiviteMapper.php create mode 100644 Sources/src/data/core/database/AthleteEntity.php create mode 100644 Sources/src/data/core/database/AthleteGateway.php create mode 100644 Sources/src/data/core/database/AthleteMapper.php create mode 100644 Sources/src/data/core/database/CoachEntity.php create mode 100644 Sources/src/data/core/database/CoachGateway.php create mode 100644 Sources/src/data/core/database/CoachMapper.php delete mode 100644 Sources/src/data/core/database/UserGateway.php diff --git a/Sources/src/data/core/database/ActiviteEntity.php b/Sources/src/data/core/database/ActiviteEntity.php new file mode 100644 index 00000000..df8340d4 --- /dev/null +++ b/Sources/src/data/core/database/ActiviteEntity.php @@ -0,0 +1,125 @@ +idActivity; + } + + public function getType() { + return $this->type; + } + + public function getDate() { + return $this->date; + } + + public function getHeureDebut() { + return $this->heureDebut; + } + + public function getHeureFin() { + return $this->heureFin; + } + + public function getEffortRessenti() { + return $this->effortRessenti; + } + + public function getVariabilite() { + return $this->variabilite; + } + + public function getVariance() { + return $this->variance; + } + + public function getEcartType() { + return $this->ecartType; + } + + public function getMoyenne() { + return $this->moyenne; + } + + public function getMaximum() { + return $this->maximum; + } + + public function getMinimum() { + return $this->minimum; + } + + public function getTemperatureMoyenne() { + return $this->temperatureMoyenne; + } + + // Setters + public function setIdActivity($idActivity) { + $this->idActivity = $idActivity; + } + + public function setType($type) { + $this->type = $type; + } + + public function setDate($date) { + $this->date = $date; + } + + public function setHeureDebut($heureDebut) { + $this->heureDebut = $heureDebut; + } + + public function setHeureFin($heureFin) { + $this->heureFin = $heureFin; + } + + public function setEffortRessenti($effortRessenti) { + $this->effortRessenti = $effortRessenti; + } + + public function setVariabilite($variabilite) { + $this->variabilite = $variabilite; + } + + public function setVariance($variance) { + $this->variance = $variance; + } + + public function setEcartType($ecartType) { + $this->ecartType = $ecartType; + } + + public function setMoyenne($moyenne) { + $this->moyenne = $moyenne; + } + + public function setMaximum($maximum) { + $this->maximum = $maximum; + } + + public function setMinimum($minimum) { + $this->minimum = $minimum; + } + + public function setTemperatureMoyenne($temperatureMoyenne) { + $this->temperatureMoyenne = $temperatureMoyenne; + } +} + +?> diff --git a/Sources/src/data/core/database/ActiviteGateway.php b/Sources/src/data/core/database/ActiviteGateway.php new file mode 100644 index 00000000..8b34a3ee --- /dev/null +++ b/Sources/src/data/core/database/ActiviteGateway.php @@ -0,0 +1,61 @@ +connection = $connection; + } + + public function getActivity() { + $query = "SELECT * FROM Activity"; + return $this->connection->executeWithErrorHandling($query); + } + + public function getActivityById($activityId) { + $query = "SELECT * FROM Activity WHERE idActivity = :id"; + $params = [':id' => [$activityId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActivityByType($type) { + $query = "SELECT * FROM Activity WHERE type = :type"; + $params = [':type' => [$type, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActivityByDate($date) { + $query = "SELECT * FROM Activity WHERE date = :date"; + $params = [':date' => [$date, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActivityByTimeRange($startTime, $endTime) { + $query = "SELECT * FROM Activity WHERE heureDebut >= :startTime AND heureFin <= :endTime"; + $params = [ + ':startTime' => [$startTime, PDO::PARAM_STR], + ':endTime' => [$endTime, PDO::PARAM_STR] + ]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActivityByEffort($effortRessenti) { + $query = "SELECT * FROM Activity WHERE effortRessenti = :effort"; + $params = [':effort' => [$effortRessenti, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActivityByVariability($variabilite) { + $query = "SELECT * FROM Activity WHERE variabilite = :variability"; + $params = [':variability' => [$variabilite, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActivityByTemperature($temperatureMoyenne) { + $query = "SELECT * FROM Activity WHERE temperatureMoyenne = :temperature"; + $params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } +} + +?> diff --git a/Sources/src/data/core/database/ActiviteMapper.php b/Sources/src/data/core/database/ActiviteMapper.php new file mode 100644 index 00000000..03ad3c5f --- /dev/null +++ b/Sources/src/data/core/database/ActiviteMapper.php @@ -0,0 +1,24 @@ +setIdActivite($data['idActivite']); + $activite->setType($data['type']); + $activite->setDate($data['date']); + $activite->setHeureDebut($data['heureDebut']); + $activite->setHeureFin($data['heureFin']); + $activite->setEffortRessenti($data['effortRessenti']); + $activite->setVariabilite($data['variabilite']); + $activite->setVariance($data['variance']); + $activite->setEcartType($data['ecartType']); + $activite->setMoyenne($data['moyenne']); + $activite->setMaximum($data['maximum']); + $activite->setMinimum($data['minimum']); + $activite->setTemperatureMoyenne($data['temperatureMoyenne']); + + return $activite; + } +} + +?> diff --git a/Sources/src/data/core/database/AthleteEntity.php b/Sources/src/data/core/database/AthleteEntity.php new file mode 100644 index 00000000..de5f5a65 --- /dev/null +++ b/Sources/src/data/core/database/AthleteEntity.php @@ -0,0 +1,89 @@ +idAthlete; + } + + public function getNom() { + return $this->nom; + } + + public function getPrenom() { + return $this->prenom; + } + + public function getEmail() { + return $this->email; + } + + public function getSexe() { + return $this->sexe; + } + + public function getTaille() { + return $this->taille; + } + + public function getPoids() { + return $this->poids; + } + + public function getMotDePasse() { + return $this->motDePasse; + } + + public function getDateNaissance() { + return $this->dateNaissance; + } + + // Setters + public function setIdAthlete($idAthlete) { + $this->idAthlete = $idAthlete; + } + + public function setNom($nom) { + $this->nom = $nom; + } + + public function setPrenom($prenom) { + $this->prenom = $prenom; + } + + public function setEmail($email) { + $this->email = $email; + } + + public function setSexe($sexe) { + $this->sexe = $sexe; + } + + public function setTaille($taille) { + $this->taille = $taille; + } + + public function setPoids($poids) { + $this->poids = $poids; + } + + public function setMotDePasse($motDePasse) { + $this->motDePasse = $motDePasse; + } + + public function setDateNaissance($dateNaissance) { + $this->dateNaissance = $dateNaissance; + } +} + +?> diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php new file mode 100644 index 00000000..ac884842 --- /dev/null +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -0,0 +1,75 @@ +connection = $connection; + } + + public function getAthlete() { + $query = "SELECT * FROM Athlete"; + return $this->connection->executeWithErrorHandling($query); + } + + public function getAthleteById($userId) { + $query = "SELECT * FROM Athlete WHERE idAthlete = :id"; + $params = [':id' => [$userId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByName($name) { + $query = "SELECT * FROM Athlete WHERE nom = :name"; + $params = [':name' => [$name, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByFirstName($firstName) { + $query = "SELECT * FROM Athlete WHERE prenom = :firstName"; + $params = [':firstName' => [$firstName, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByEmail($email) { + $query = "SELECT * FROM Athlete WHERE email = :email"; + $params = [':email' => [$email, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByGender($gender) { + $query = "SELECT * FROM Athlete WHERE sexe = :gender"; + $params = [':gender' => [$gender, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByHeight($height) { + $query = "SELECT * FROM Athlete WHERE taille = :height"; + $params = [':height' => [$height, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByWeight($weight) { + $query = "SELECT * FROM Athlete WHERE poids = :weight"; + $params = [':weight' => [$weight, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByBirthDate($birthdate) { + $query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate"; + $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } +} + + +// Exemple d'utilisation +//$dsn = "pgsql:host=localhost;port=5432;dbname=mydatabase;user=myuser;password=mypassword"; +//$connection = new Connection($dsn); +//$gateway = new UserGateway($connection); + +//$allAth = $gateway->getAthlete(); +//print_r($allAth); + +//$singleAth = $gateway->getAthleteById(1); +//print_r($singleAth); + +?> diff --git a/Sources/src/data/core/database/AthleteMapper.php b/Sources/src/data/core/database/AthleteMapper.php new file mode 100644 index 00000000..a25a3979 --- /dev/null +++ b/Sources/src/data/core/database/AthleteMapper.php @@ -0,0 +1,20 @@ +setIdAthlete($data['idAthlete']); + $athlete->setNom($data['nom']); + $athlete->setPrenom($data['prenom']); + $athlete->setEmail($data['email']); + $athlete->setSexe($data['sexe']); + $athlete->setTaille($data['taille']); + $athlete->setPoids($data['poids']); + $athlete->setMotDePasse($data['motDePasse']); + $athlete->setDateNaissance($data['dateNaissance']); + + return $athlete; + } +} + +?> diff --git a/Sources/src/data/core/database/CoachEntity.php b/Sources/src/data/core/database/CoachEntity.php new file mode 100644 index 00000000..0910d118 --- /dev/null +++ b/Sources/src/data/core/database/CoachEntity.php @@ -0,0 +1,89 @@ +idCoach; + } + + public function getNom() { + return $this->nom; + } + + public function getPrenom() { + return $this->prenom; + } + + public function getEmail() { + return $this->email; + } + + public function getSexe() { + return $this->sexe; + } + + public function getTaille() { + return $this->taille; + } + + public function getPoids() { + return $this->poids; + } + + public function getMotDePasse() { + return $this->motDePasse; + } + + public function getDateNaissance() { + return $this->dateNaissance; + } + + // Setters + public function setIdCoach($idCoach) { + $this->idCoach = $idCoach; + } + + public function setNom($nom) { + $this->nom = $nom; + } + + public function setPrenom($prenom) { + $this->prenom = $prenom; + } + + public function setEmail($email) { + $this->email = $email; + } + + public function setSexe($sexe) { + $this->sexe = $sexe; + } + + public function setTaille($taille) { + $this->taille = $taille; + } + + public function setPoids($poids) { + $this->poids = $poids; + } + + public function setMotDePasse($motDePasse) { + $this->motDePasse = $motDePasse; + } + + public function setDateNaissance($dateNaissance) { + $this->dateNaissance = $dateNaissance; + } +} + +?> diff --git a/Sources/src/data/core/database/CoachGateway.php b/Sources/src/data/core/database/CoachGateway.php new file mode 100644 index 00000000..634c849a --- /dev/null +++ b/Sources/src/data/core/database/CoachGateway.php @@ -0,0 +1,55 @@ +connection = $connection; + } + + public function getCoach() { + $query = "SELECT * FROM Coach"; + return $this->connection->executeWithErrorHandling($query); + } + + public function getCoachById($userId) { + $query = "SELECT * FROM Coach WHERE idCoach = :id"; + $params = [':id' => [$userId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByName($name) { + $query = "SELECT * FROM Coach WHERE nom = :name"; + $params = [':name' => [$name, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByFirstName($firstName) { + $query = "SELECT * FROM Coach WHERE prenom = :firstName"; + $params = [':firstName' => [$firstName, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByEmail($email) { + $query = "SELECT * FROM Coach WHERE email = :email"; + $params = [':email' => [$email, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByGender($gender) { + $query = "SELECT * FROM Coach WHERE sexe = :gender"; + $params = [':gender' => [$gender, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByHeight($height) { + $query = "SELECT * FROM Coach WHERE taille = :height"; + $params = [':height' => [$height, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByBirthDate($birthdate) { + $query = "SELECT * FROM Coach WHERE dateNaissance = :birthdate"; + $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/CoachMapper.php b/Sources/src/data/core/database/CoachMapper.php new file mode 100644 index 00000000..b0a1e995 --- /dev/null +++ b/Sources/src/data/core/database/CoachMapper.php @@ -0,0 +1,20 @@ +setIdCoach($data['idCoach']); + $coach->setNom($data['nom']); + $coach->setPrenom($data['prenom']); + $coach->setEmail($data['email']); + $coach->setSexe($data['sexe']); + $coach->setTaille($data['taille']); + $coach->setPoids($data['poids']); + $coach->setMotDePasse($data['motDePasse']); + $coach->setDateNaissance($data['dateNaissance']); + + return $coach; + } +} + +?> diff --git a/Sources/src/data/core/database/UserGateway.php b/Sources/src/data/core/database/UserGateway.php deleted file mode 100644 index dc58f98c..00000000 --- a/Sources/src/data/core/database/UserGateway.php +++ /dev/null @@ -1,50 +0,0 @@ -connection = $connection; - } - - public function getAthlete() { - $query = "SELECT * FROM Athlete"; - return $this->connection->executeWithErrorHandling($query); - } - - public function getCoach() { - $query = "SELECT * FROM Coach"; - return $this->connection->executeWithErrorHandling($query); - } - - public function getAthleteById($userId) { - $query = "SELECT * FROM Athlete WHERE idAthlete = :id"; - $params = [':id' => [$userId, PDO::PARAM_INT]]; - return $this->connection->executeWithErrorHandling($query, $params); - } - - public function getCoachById($userId) { - $query = "SELECT * FROM Coach WHERE idCoach = :id"; - $params = [':id' => [$userId, PDO::PARAM_INT]]; - return $this->connection->executeWithErrorHandling($query, $params); - } - -} - -// Exemple d'utilisation -//$dsn = "pgsql:host=localhost;port=5432;dbname=mydatabase;user=myuser;password=mypassword"; -//$connection = new Connection($dsn); -//$gateway = new UserGateway($connection); - -//$allAth = $gateway->getAthlete(); -//print_r($allAth); - -//$allCoach = $gateway->getCoach(); -//print_r($allCoach); - -//$singleAth = $gateway->getAthleteById(1); -//print_r($singleAth); - -//$singleCoach = $gateway->getCoachById(1); -//print_r($singleCoach); - -?>