diff --git a/Sources/src/data/core/database/ActiviteEntity.php b/Sources/src/data/core/database/ActiviteEntity.php new file mode 100644 index 00000000..a29a0a47 --- /dev/null +++ b/Sources/src/data/core/database/ActiviteEntity.php @@ -0,0 +1,127 @@ +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 setIdActivite($idActivite) { + $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..853cffa0 --- /dev/null +++ b/Sources/src/data/core/database/ActiviteGateway.php @@ -0,0 +1,120 @@ +connection = $connection; + } + + public function getActivite() { + $query = "SELECT * FROM Activite"; + return $this->connection->executeWithErrorHandling($query); + } + + public function getActiviteById(int $activiteId) { + $query = "SELECT * FROM Activite WHERE idActivite = :id"; + $params = [':id' => [$activiteId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActiviteByType(string $type) { + $query = "SELECT * FROM Activite WHERE type = :type"; + $params = [':type' => [$type, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActiviteByDate(string $date) { + $query = "SELECT * FROM Activite WHERE date = :date"; + $params = [':date' => [$date, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActiviteByTimeRange(string $startTime, string $endTime) { + $query = "SELECT * FROM Activite 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 getActiviteByEffort(int $effortRessenti) { + $query = "SELECT * FROM Activite WHERE effortRessenti = :effort"; + $params = [':effort' => [$effortRessenti, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActiviteByVariability(int $variabilite) { + $query = "SELECT * FROM Activite WHERE variabilite = :variability"; + $params = [':variability' => [$variabilite, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getActiviteByTemperature(int $temperatureMoyenne) { + $query = "SELECT * FROM Activite WHERE temperatureMoyenne = :temperature"; + $params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function addActivite(ActiviteEntity $activite) { + $query = "INSERT INTO Activite (type, date, heureDebut, heureDeFin, effortRessenti, variabilite, variance, ecartType, moyenne, maximum, minimum, temperatureMoyenne) + VALUES (:type, :date, :heureDebut, :heureDeFin, :effortRessenti, :variabilite, :variance, :ecartType, :moyenne, :maximum, :minimum, :temperatureMoyenne)"; + + $params = [ + ':type' => $activite->getType(), + ':date' => $activite->getDate()->format('Y-m-d'), // Format date pour SQL + ':heureDebut' => $activite->getHeureDebut()->format('H:i:s'), // Format heure pour SQL + ':heureDeFin' => $activite->getHeureFin()->format('H:i:s'), // Format heure pour SQL + ':effortRessenti' => $activite->getEffortRessenti(), + ':variabilite' => $activite->getVariabilite(), + ':variance' => $activite->getVariance(), + ':ecartType' => $activite->getEcartType(), + ':moyenne' => $activite->getMoyenne(), + ':maximum' => $activite->getMaximum(), + ':minimum' => $activite->getMinimum(), + ':temperatureMoyenne' => $activite->getTemperatureMoyenne(), + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function updateActivite(ActiviteEntity $oldActivite, ActiviteEntity $newActivite) { + $query = "UPDATE Activite + SET type = :type, date = :date, heureDebut = :heureDebut, heureDeFin = :heureDeFin, + effortRessenti = :effortRessenti, variabilite = :variabilite, variance = :variance, ecartType = :ecartType, moyenne = :moyenne, maximum = :maximum, minimum = :minimum, temperatureMoyenne = :temperatureMoyenne + WHERE idActivite = :idActivite"; + + $params = [ + ':idActivite' => $oldActivite->getIdActivite(), + ':type' => $newActivite->getType(), + ':date' => $newActivite->getDate()->format('Y-m-d'), // Format date pour SQL + ':heureDebut' => $newActivite->getHeureDebut()->format('H:i:s'), // Format heure pour SQL + ':heureDeFin' => $newActivite->getHeureFin()->format('H:i:s'), // Format heure pour SQL + ':effortRessenti' => $newActivite->getEffortRessenti(), + ':variabilite' => $newActivite->getVariabilite(), + ':variance' => $newActivite->getVariance(), + ':ecartType' => $newActivite->getEcartType(), + ':moyenne' => $newActivite->getMoyenne(), + ':maximum' => $newActivite->getMaximum(), + ':minimum' => $newActivite->getMinimum(), + ':temperatureMoyenne' => $newActivite->getTemperatureMoyenne(), + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function deleteActivite(int $idActivite) { + $query = "DELETE FROM Activite WHERE idActivite = :idActivite"; + + $params = [ + ':idActivite' => $idActivite, + ]; + + 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..d2097e10 --- /dev/null +++ b/Sources/src/data/core/database/ActiviteMapper.php @@ -0,0 +1,51 @@ +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; + } + + //public function ActiviteEntityToModel(ActiviteEntity entity): Activite; + + public function ActiviteEntityToModel(ActiviteEntity $activiteEntity):Activite{ + + $act = new Activite( + $activiteEntity->getIdActivite(), + $activiteEntity->getType(), + $activiteEntity->getDate(), + $activiteEntity->getHeureDebut(), + $activiteEntity->getHeureFin(), + $activiteEntity->getEffortRessenti(), + $activiteEntity->getVariabilite(), + $activiteEntity->getVariance(), + $activiteEntity->getEcartType(), + $activiteEntity->getMoyenne(), + $activiteEntity->getMaximum(), + $activiteEntity->getMinimum(), + $activiteEntity->getTemperatureMoyenne() + ); + + return $act; + } + //public function ActiviteToEntity(Activite model): ActiviteEntity; +} + +?> diff --git a/Sources/src/data/core/database/AthleteEntity.php b/Sources/src/data/core/database/AthleteEntity.php new file mode 100644 index 00000000..812543c8 --- /dev/null +++ b/Sources/src/data/core/database/AthleteEntity.php @@ -0,0 +1,91 @@ +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..7b2dc45e --- /dev/null +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -0,0 +1,131 @@ +connection = $connection; + } + + public function getAthlete() { + $query = "SELECT * FROM Athlete"; + return $this->connection->executeWithErrorHandling($query); + } + + public function getAthleteById(int $userId) { + $query = "SELECT * FROM Athlete WHERE idAthlete = :id"; + $params = [':id' => [$userId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByName(string $name) { + $query = "SELECT * FROM Athlete WHERE nom = :name"; + $params = [':name' => [$name, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByFirstName(string $firstName) { + $query = "SELECT * FROM Athlete WHERE prenom = :firstName"; + $params = [':firstName' => [$firstName, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByEmail(string $email) { + $query = "SELECT * FROM Athlete WHERE email = :email"; + $params = [':email' => [$email, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByGender(string $gender) { + $query = "SELECT * FROM Athlete WHERE sexe = :gender"; + $params = [':gender' => [$gender, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByHeight(int $height) { + $query = "SELECT * FROM Athlete WHERE taille = :height"; + $params = [':height' => [$height, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByWeight(int $weight) { + $query = "SELECT * FROM Athlete WHERE poids = :weight"; + $params = [':weight' => [$weight, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getAthleteByBirthDate(string $birthdate) { + $query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate"; + $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function addAthlete(AthleteEntity $athlete) { + $query = "INSERT INTO Athlete (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance) + VALUES (:nom, :prenom, :email, :sexe, :taille, :poids, :motDePasse, :dateNaissance)"; + + $params = [ + ':nom' => $athlete->getNom(), + ':prenom' => $athlete->getPrenom(), + ':email' => $athlete->getEmail(), + ':sexe' => $athlete->getSexe(), + ':taille' => $athlete->getTaille(), + ':poids' => $athlete->getPoids(), + ':motDePasse' => $athlete->getMotDePasse(), + ':dateNaissance' => $athlete->getDateNaissance(), + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function updateAthlete(AthleteEntity $oldAthlete, AthleteEntity $newAthlete) { + $query = "UPDATE Athlete + SET nom = :nom, prenom = :prenom, email = :email, sexe = :sexe, + taille = :taille, poids = :poids, motDePasse = :motDePasse, dateNaissance = :dateNaissance + WHERE idAthlete = :idAthlete"; + + $params = [ + ':idAthlete' => $oldAthlete->getIdAthlete(), + ':nom' => $newAthlete->getNom(), + ':prenom' => $newAthlete->getPrenom(), + ':email' => $newAthlete->getEmail(), + ':sexe' => $newAthlete->getSexe(), + ':taille' => $newAthlete->getTaille(), + ':poids' => $newAthlete->getPoids(), + ':motDePasse' => $newAthlete->getMotDePasse(), + ':dateNaissance' => $newAthlete->getDateNaissance(), + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function deleteAthlete(int $idAthlete) { + $query = "DELETE FROM Athlete WHERE idAthlete = :idAthlete"; + + $params = [ + ':idAthlete' => $idAthlete, + ]; + + 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 AthleteGateway($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..16f5f0be --- /dev/null +++ b/Sources/src/data/core/database/AthleteMapper.php @@ -0,0 +1,99 @@ +setIdAthlete($athleteData['idAthlete']); + } + + if (isset($athleteData['nom'])) { + $athlete->setNom($athleteData['nom']); + } + + if (isset($athleteData['prenom'])) { + $athlete->setPrenom($athleteData['prenom']); + } + + if (isset($athleteData['email'])) { + $athlete->setEmail($athleteData['email']); + } + + if (isset($athleteData['sexe'])) { + $athlete->setSexe($athleteData['sexe']); + } + + if (isset($athleteData['taille'])) { + $athlete->setTaille($athleteData['taille']); + } + + if (isset($athleteData['poids'])) { + $athlete->setPoids($athleteData['poids']); + } + + if (isset($athleteData['motDePasse'])) { + $athlete->setMotDePasse($athleteData['motDePasse']); + } + + if (isset($athleteData['dateNaissance'])) { + $athlete->setDateNaissance($athleteData['dateNaissance']); + } + + $athleteEntities[] = $athlete; + } + + return $athleteEntities; + } + + public function athleteEntityToModel(AthleteEntity $athleteEntity): User { + $role = new Athlete(); // Utilisez la classe Athlete + + $dateSpecifique = $athleteEntity->getDateNaissance(); + $date = new DateTime($dateSpecifique); + + $user = new User( + $athleteEntity->getIdAthlete(), + $athleteEntity->getNom(), + $athleteEntity->getPrenom(), + $athleteEntity->getEmail(), + $athleteEntity->getMotDePasse(), + $athleteEntity->getSexe(), + $athleteEntity->getTaille(), + $athleteEntity->getPoids(), + $date, + $role + ); + + return $user; + } + + public function athleteToEntity(User $user):AthleteEntity{ + + $ath = new AthleteEntity(); + $ath->setIdAthlete($user->getId()); + $ath->setNom($user->getNom()); + $ath->setPrenom($user->getPrenom()); + $ath->setEmail($user->getEmail()); + $ath->setSexe($user->getSexe()); + $ath->setTaille($user->getTaille()); + $ath->setPoids($user->getPoids()); + $ath->setMotDePasse($user->getMotDePasse()); + $ath->setDateNaissance($user->getDateNaissance()); + + return $ath; + } + +} + +?> diff --git a/Sources/src/data/core/database/CoachEntity.php b/Sources/src/data/core/database/CoachEntity.php new file mode 100644 index 00000000..03af8b1c --- /dev/null +++ b/Sources/src/data/core/database/CoachEntity.php @@ -0,0 +1,91 @@ +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..5f795799 --- /dev/null +++ b/Sources/src/data/core/database/CoachGateway.php @@ -0,0 +1,109 @@ +connection = $connection; + } + + public function getCoach() { + $query = "SELECT * FROM Coach"; + return $this->connection->executeWithErrorHandling($query); + } + + public function getCoachById(int $userId) { + $query = "SELECT * FROM Coach WHERE idCoach = :id"; + $params = [':id' => [$userId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByName(string $name) { + $query = "SELECT * FROM Coach WHERE nom = :name"; + $params = [':name' => [$name, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByFirstName(string $firstName) { + $query = "SELECT * FROM Coach WHERE prenom = :firstName"; + $params = [':firstName' => [$firstName, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByEmail(string $email) { + $query = "SELECT * FROM Coach WHERE email = :email"; + $params = [':email' => [$email, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByGender(string $gender) { + $query = "SELECT * FROM Coach WHERE sexe = :gender"; + $params = [':gender' => [$gender, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByHeight(int $height) { + $query = "SELECT * FROM Coach WHERE taille = :height"; + $params = [':height' => [$height, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByBirthDate(string $birthdate) { + $query = "SELECT * FROM Coach WHERE dateNaissance = :birthdate"; + $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function addCoach(CoachEntity $coach) { + $query = "INSERT INTO Coach (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance) + VALUES (:nom, :prenom, :email, :sexe, :taille, :poids, :motDePasse, :dateNaissance)"; + + $params = [ + ':nom' => $coach->getNom(), + ':prenom' => $coach->getPrenom(), + ':email' => $coach->getEmail(), + ':sexe' => $coach->getSexe(), + ':taille' => $coach->getTaille(), + ':poids' => $coach->getPoids(), + ':motDePasse' => $coach->getMotDePasse(), + ':dateNaissance' => $coach->getDateNaissance(), + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach) { + $query = "UPDATE Coach + SET nom = :nom, prenom = :prenom, email = :email, sexe = :sexe, + taille = :taille, poids = :poids, motDePasse = :motDePasse, dateNaissance = :dateNaissance + WHERE idCoach = :idCoach"; + + $params = [ + ':idCoach' => $oldCoach->getIdCoach(), + ':nom' => $newCoach->getNom(), + ':prenom' => $newCoach->getPrenom(), + ':email' => $newCoach->getEmail(), + ':sexe' => $newCoach->getSexe(), + ':taille' => $newCoach->getTaille(), + ':poids' => $newCoach->getPoids(), + ':motDePasse' => $newCoach->getMotDePasse(), + ':dateNaissance' => $newCoach->getDateNaissance(), + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function deleteCoach(int $idCoach) { + $query = "DELETE FROM Coach WHERE idCoach = :idCoach"; + + $params = [ + ':idCoach' => $idCoach, + ]; + + 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..76284918 --- /dev/null +++ b/Sources/src/data/core/database/CoachMapper.php @@ -0,0 +1,62 @@ +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; + } + + public function CoachEntityToModel(CoachEntity $coachEntity):User{ + $role = "Coach"; + + $user = new User( + $coachEntity->getIdCoach(), + $coachEntity->getNom(), + $coachEntity->getPrenom(), + $coachEntity->getEmail(), + $coachEntity->getMotDePasse(), + $coachEntity->getSexe(), + $coachEntity->getTaille(), + $coachEntity->getPoids(), + $coachEntity->getDateNaissance(), + $role + ); + + return $user; + } + + public function CoachToEntity(User $user):CoachEntity{ + + $coach = new CoachEntity(); + $coach->setIdCoach($user->getId()); + $coach->setNom($user->getNom()); + $coach->setPrenom($user->getPrenom()); + $coach->setEmail($user->getEmail()); + $coach->setSexe($user->getSexe()); + $coach->setTaille($user->getTaille()); + $coach->setPoids($user->getPoids()); + $coach->setMotDePasse($user->getMotDePasse()); + $coach->setDateNaissance($user->getDateNaissance()); + + return $coach; + } +} + +?> diff --git a/Sources/src/data/core/database/Connexion.php b/Sources/src/data/core/database/Connexion.php new file mode 100644 index 00000000..9a03267b --- /dev/null +++ b/Sources/src/data/core/database/Connexion.php @@ -0,0 +1,49 @@ +setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + } catch (\PDOException $e) { + // Log error or handle it as needed + throw new \PDOException("Error connecting to the database: " . $e->getMessage()); + } + } + + public function executeQuery(string $query, array $parameters = []): bool { + $this->stmt = $this->prepare($query); + //foreach ($parameters as $name => $value) { + // $this->stmt->bindValue($name, $value[0], $value[1]); + //} + foreach ($parameters as $name => $value) { + $bindValueResult = $this->stmt->bindValue($name, $value, \PDO::PARAM_STR); + if (!$bindValueResult) { + // Gérez l'erreur, par exemple, en lançant une exception. + throw new \PDOException('Failed to bind value for parameter ' . $name); + } + } + return $this->stmt->execute(); + } + + public function executeWithErrorHandling(string $query, array $params = []): array { + try { + $this->beginTransaction(); + $this->executeQuery($query, $params); + $this->commit(); + return $this->getResults(); + } catch (\PDOException $e) { + $this->rollBack(); + throw new \PDOException('Unexpected error on database client: ' . $e->getMessage()); + } + } + + public function getResults(): array { + return $this->stmt->fetchAll(\PDO::FETCH_ASSOC); + } +} +?> \ No newline at end of file