diff --git a/Sources/src/data/core/database/AthleteMapper.php b/Sources/src/data/core/database/AthleteMapper.php index 55e0a216..2938a71a 100644 --- a/Sources/src/data/core/database/AthleteMapper.php +++ b/Sources/src/data/core/database/AthleteMapper.php @@ -65,8 +65,8 @@ class AthleteMapper { public function athleteEntityToModel(AthleteEntity $athleteEntity): User { $role = new Athlete(); // Utilisez la classe Athlete - $dateSpecifique = $athleteEntity->getDateNaissance(); - $date = new DateTime($dateSpecifique); + $dateSpecific = $athleteEntity->getDateNaissance(); + $date = new DateTime($dateSpecific); $user = new User( $athleteEntity->getIdAthlete(), @@ -77,6 +77,7 @@ class AthleteMapper { $athleteEntity->getSexe(), $athleteEntity->getTaille(), $athleteEntity->getPoids(), + $athleteEntity->getDateNaissance(), $date, $role ); diff --git a/Sources/src/data/core/database/CoachGateway.php b/Sources/src/data/core/database/CoachGateway.php index 5d6afebd..63fc9875 100644 --- a/Sources/src/data/core/database/CoachGateway.php +++ b/Sources/src/data/core/database/CoachGateway.php @@ -10,54 +10,70 @@ class CoachGateway { $this->connection = $connection; } - public function getCoach() { + public function getCoach(): array + { $query = "SELECT * FROM Coach"; return $this->connection->executeWithErrorHandling($query); } - public function getCoachById(int $userId) { + public function getCoachById(int $userId): array + { $query = "SELECT * FROM Coach WHERE idCoach = :id"; $params = [':id' => [$userId, PDO::PARAM_INT]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function getCoachByName(string $name) { + public function getAthleteByCoachId(int $coachId): array + { + $query = "SELECT * FROM Athlete a, Coach c WHERE a.coachId = :id AND a.isCoach = TRUE"; + $params = [':id' => [$coachId, PDO::PARAM_INT]]; + return $this->connection->executeWithErrorHandling($query, $params); + } + + public function getCoachByName(string $name): array + { $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.nom = :name"; $params = [':name' => [$name, PDO::PARAM_STR]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function getCoachByFirstName(string $firstName) { + public function getCoachByFirstName(string $firstName): array + { $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.prenom = :firstName"; $params = [':firstName' => [$firstName, PDO::PARAM_STR]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function getCoachByEmail(string $email) { + public function getCoachByEmail(string $email): array + { $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.email = :email"; $params = [':email' => [$email, PDO::PARAM_STR]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function getCoachByGender(string $gender) { + public function getCoachByGender(string $gender): array + { $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.sexe = :gender"; $params = [':gender' => [$gender, PDO::PARAM_STR]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function getCoachByHeight(int $height) { + public function getCoachByHeight(int $height): array + { $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.taille = :height"; $params = [':height' => [$height, PDO::PARAM_INT]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function getCoachByBirthDate(string $birthdate) { + public function getCoachByBirthDate(string $birthdate): array + { $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.dateNaissance = :birthdate"; $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; return $this->connection->executeWithErrorHandling($query, $params); } - public function addCoach(CoachEntity $coach) { + public function addCoach(CoachEntity $coach): array + { $query = "INSERT INTO Coach (athleteId) VALUES (:athleteId)"; @@ -68,7 +84,8 @@ class CoachGateway { return $this->connection->executeWithErrorHandling($query, $params); } - public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach) { + public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach): array + { $query = "UPDATE Coach SET athleteId = :athleteId WHERE idCoach = :idCoach"; @@ -81,7 +98,8 @@ class CoachGateway { return $this->connection->executeWithErrorHandling($query, $params); } - public function deleteCoach(int $idCoach) { + public function deleteCoach(int $idCoach): array + { $query = "DELETE FROM Coach WHERE idCoach = :idCoach"; $params = [ diff --git a/Sources/src/data/core/database/CoachMapper.php b/Sources/src/data/core/database/CoachMapper.php index 3fd35c7f..f3fd48ec 100644 --- a/Sources/src/data/core/database/CoachMapper.php +++ b/Sources/src/data/core/database/CoachMapper.php @@ -1,6 +1,7 @@ setAthleteId($coachData['athleteId']); } - $coachEntities[] = $athlete; + $coachEntities[] = $coach; } return $coachEntities; } public function CoachEntityToModel(CoachEntity $coachEntity):User{ - $role = new Coach(); + $role = new CoachAthlete(); - $dateSpecifique = $athleteEntity->getDateNaissance(); - $date = new DateTime($dateSpecifique); + $idCoach = $coachEntity->getIdCoach(); + + $ath = getAthleteByCoachId($idCoach); + $athlete = athleteSqlToEntity($ath); + + $dateSpecific = $athlete->getDateNaissance(); + $date = new DateTime($dateSpecific); $user = new User( $coachEntity->getIdCoach(), - //$coachEntity->getNom(), - //$coachEntity->getPrenom(), - //$coachEntity->getEmail(), - //$coachEntity->getMotDePasse(), //A MODIFIER : Doit recup les valeurs dans Athlete qui correspond - //$coachEntity->getSexe(), - //$coachEntity->getTaille(), - //$coachEntity->getPoids(), - //$coachEntity->getDateNaissance(), + $athlete->getNom(), + $athlete->getPrenom(), + $athlete->getEmail(), + $athlete->getMotDePasse(), + $athlete->getSexe(), + $athlete->getTaille(), + $athlete->getPoids(), + $athlete->getDateNaissance(), $date, $role ); @@ -55,10 +61,10 @@ class CoachMapper { $coach = new CoachEntity(); $coach->setIdCoach($user->getId()); - $coach->setAthleteId($user->getId()); //A MODIFIER !!! doit recup Id Athlete qui correspond + $coach->setAthleteId($user->getId()); return $coach; } } - ?> +