Gateways, Mappers et Entity pour Athlete et Coach a tester mais fonctionnel normalement
continuous-integration/drone/push Build is failing Details

WORK-KMO-Gateway
Kevin MONTEIRO 1 year ago
parent af9821709c
commit aba0924f64

@ -65,8 +65,8 @@ class AthleteMapper {
public function athleteEntityToModel(AthleteEntity $athleteEntity): User { public function athleteEntityToModel(AthleteEntity $athleteEntity): User {
$role = new Athlete(); // Utilisez la classe Athlete $role = new Athlete(); // Utilisez la classe Athlete
$dateSpecifique = $athleteEntity->getDateNaissance(); $dateSpecific = $athleteEntity->getDateNaissance();
$date = new DateTime($dateSpecifique); $date = new DateTime($dateSpecific);
$user = new User( $user = new User(
$athleteEntity->getIdAthlete(), $athleteEntity->getIdAthlete(),
@ -77,6 +77,7 @@ class AthleteMapper {
$athleteEntity->getSexe(), $athleteEntity->getSexe(),
$athleteEntity->getTaille(), $athleteEntity->getTaille(),
$athleteEntity->getPoids(), $athleteEntity->getPoids(),
$athleteEntity->getDateNaissance(),
$date, $date,
$role $role
); );

@ -10,54 +10,70 @@ class CoachGateway {
$this->connection = $connection; $this->connection = $connection;
} }
public function getCoach() { public function getCoach(): array
{
$query = "SELECT * FROM Coach"; $query = "SELECT * FROM Coach";
return $this->connection->executeWithErrorHandling($query); return $this->connection->executeWithErrorHandling($query);
} }
public function getCoachById(int $userId) { public function getCoachById(int $userId): array
{
$query = "SELECT * FROM Coach WHERE idCoach = :id"; $query = "SELECT * FROM Coach WHERE idCoach = :id";
$params = [':id' => [$userId, PDO::PARAM_INT]]; $params = [':id' => [$userId, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); 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"; $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.nom = :name";
$params = [':name' => [$name, PDO::PARAM_STR]]; $params = [':name' => [$name, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); 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"; $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.prenom = :firstName";
$params = [':firstName' => [$firstName, PDO::PARAM_STR]]; $params = [':firstName' => [$firstName, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); 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"; $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.email = :email";
$params = [':email' => [$email, PDO::PARAM_STR]]; $params = [':email' => [$email, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); 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"; $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.sexe = :gender";
$params = [':gender' => [$gender, PDO::PARAM_STR]]; $params = [':gender' => [$gender, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); 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"; $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.taille = :height";
$params = [':height' => [$height, PDO::PARAM_INT]]; $params = [':height' => [$height, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); 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"; $query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.dateNaissance = :birthdate";
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function addCoach(CoachEntity $coach) { public function addCoach(CoachEntity $coach): array
{
$query = "INSERT INTO Coach (athleteId) $query = "INSERT INTO Coach (athleteId)
VALUES (:athleteId)"; VALUES (:athleteId)";
@ -68,7 +84,8 @@ class CoachGateway {
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach) { public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach): array
{
$query = "UPDATE Coach $query = "UPDATE Coach
SET athleteId = :athleteId SET athleteId = :athleteId
WHERE idCoach = :idCoach"; WHERE idCoach = :idCoach";
@ -81,7 +98,8 @@ class CoachGateway {
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function deleteCoach(int $idCoach) { public function deleteCoach(int $idCoach): array
{
$query = "DELETE FROM Coach WHERE idCoach = :idCoach"; $query = "DELETE FROM Coach WHERE idCoach = :idCoach";
$params = [ $params = [

@ -1,6 +1,7 @@
<?php <?php
namespace Database; namespace Database;
use Model\CoachAthlete;
use Model\User; use Model\User;
use \PDO; use \PDO;
use \DateTime; use \DateTime;
@ -22,28 +23,33 @@ class CoachMapper {
$coach->setAthleteId($coachData['athleteId']); $coach->setAthleteId($coachData['athleteId']);
} }
$coachEntities[] = $athlete; $coachEntities[] = $coach;
} }
return $coachEntities; return $coachEntities;
} }
public function CoachEntityToModel(CoachEntity $coachEntity):User{ public function CoachEntityToModel(CoachEntity $coachEntity):User{
$role = new Coach(); $role = new CoachAthlete();
$dateSpecifique = $athleteEntity->getDateNaissance(); $idCoach = $coachEntity->getIdCoach();
$date = new DateTime($dateSpecifique);
$ath = getAthleteByCoachId($idCoach);
$athlete = athleteSqlToEntity($ath);
$dateSpecific = $athlete->getDateNaissance();
$date = new DateTime($dateSpecific);
$user = new User( $user = new User(
$coachEntity->getIdCoach(), $coachEntity->getIdCoach(),
//$coachEntity->getNom(), $athlete->getNom(),
//$coachEntity->getPrenom(), $athlete->getPrenom(),
//$coachEntity->getEmail(), $athlete->getEmail(),
//$coachEntity->getMotDePasse(), //A MODIFIER : Doit recup les valeurs dans Athlete qui correspond $athlete->getMotDePasse(),
//$coachEntity->getSexe(), $athlete->getSexe(),
//$coachEntity->getTaille(), $athlete->getTaille(),
//$coachEntity->getPoids(), $athlete->getPoids(),
//$coachEntity->getDateNaissance(), $athlete->getDateNaissance(),
$date, $date,
$role $role
); );
@ -55,10 +61,10 @@ class CoachMapper {
$coach = new CoachEntity(); $coach = new CoachEntity();
$coach->setIdCoach($user->getId()); $coach->setIdCoach($user->getId());
$coach->setAthleteId($user->getId()); //A MODIFIER !!! doit recup Id Athlete qui correspond $coach->setAthleteId($user->getId());
return $coach; return $coach;
} }
} }
?> ?>

Loading…
Cancel
Save