|
|
|
@ -10,103 +10,111 @@ class CoachGateway {
|
|
|
|
|
$this->connection = $connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoach(): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach";
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query);
|
|
|
|
|
public function getCoach() {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE isCoach = TRUE;";
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoachById(int $userId): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach WHERE idCoach = :id";
|
|
|
|
|
public function getCoachById(int $userId) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE idAthlete = :id AND isCoach = TRUE";
|
|
|
|
|
$params = [':id' => [$userId, PDO::PARAM_INT]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
public function getCoachByName(string $name) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE nom = :name AND isCoach = TRUE";
|
|
|
|
|
$params = [':name' => [$name, PDO::PARAM_STR]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoachByFirstName(string $firstName): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.prenom = :firstName";
|
|
|
|
|
public function getCoachByFirstName(string $firstName) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE prenom = :firstName AND isCoach = TRUE";
|
|
|
|
|
$params = [':firstName' => [$firstName, PDO::PARAM_STR]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoachByEmail(string $email): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.email = :email";
|
|
|
|
|
public function getCoachByEmail(string $email) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE email = :email AND isCoach = TRUE";
|
|
|
|
|
$params = [':email' => [$email, PDO::PARAM_STR]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoachByGender(string $gender): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.sexe = :gender";
|
|
|
|
|
public function getCoachByGender(string $gender) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE sexe = :gender AND isCoach = TRUE";
|
|
|
|
|
$params = [':gender' => [$gender, PDO::PARAM_STR]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoachByHeight(int $height): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.taille = :height";
|
|
|
|
|
public function getCoachByHeight(int $height) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE taille = :height AND isCoach = TRUE";
|
|
|
|
|
$params = [':height' => [$height, PDO::PARAM_INT]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCoachByBirthDate(string $birthdate): array
|
|
|
|
|
{
|
|
|
|
|
$query = "SELECT * FROM Coach c, Athlete a WHERE c.athleteId = a.idAthlete AND a.dateNaissance = :birthdate";
|
|
|
|
|
public function getCoachByBirthDate(string $birthdate) {
|
|
|
|
|
$query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate AND isCoach = TRUE";
|
|
|
|
|
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addCoach(CoachEntity $coach): array
|
|
|
|
|
{
|
|
|
|
|
$query = "INSERT INTO Coach (athleteId)
|
|
|
|
|
VALUES (:athleteId)";
|
|
|
|
|
public function addCoach(CoachEntity $coach) {
|
|
|
|
|
$query = "INSERT INTO Athlete (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach)
|
|
|
|
|
VALUES (:nom, :prenom, :email, :sexe, :taille, :poids, :motDePasse, :dateNaissance, TRUE)";
|
|
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
':athleteId' => $coach->getAthleteId(),
|
|
|
|
|
':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);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach): array
|
|
|
|
|
{
|
|
|
|
|
$query = "UPDATE Coach
|
|
|
|
|
SET athleteId = :athleteId
|
|
|
|
|
public function updateCoach(CoachEntity $oldCoach, CoachEntity $newCoach) {
|
|
|
|
|
$query = "UPDATE Athlete
|
|
|
|
|
SET nom = :nom, prenom = :prenom, email = :email, sexe = :sexe,
|
|
|
|
|
taille = :taille, poids = :poids, motDePasse = :motDePasse, dateNaissance = :dateNaissance, isCoach = TRUE
|
|
|
|
|
WHERE idCoach = :idCoach";
|
|
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
':idCoach' => $oldCoach->getIdCoach(),
|
|
|
|
|
':athleteId' => $newCoach->getAthleteId(),
|
|
|
|
|
':idAthlete' => $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);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteCoach(int $idCoach): array
|
|
|
|
|
{
|
|
|
|
|
$query = "DELETE FROM Coach WHERE idCoach = :idCoach";
|
|
|
|
|
public function deleteCoach(int $idCoach) {
|
|
|
|
|
$query = "DELETE FROM Athlete WHERE idAthlete = :idCoach";
|
|
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
':idCoach' => $idCoach,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|