Modif Gateway
continuous-integration/drone/push Build is failing Details

linkBDD
Kevin MONTEIRO 1 year ago
parent 15b97837f7
commit 7af4e472ec

@ -12,25 +12,29 @@ class ActivityGateway {
public function getActivity() { public function getActivity() {
$query = "SELECT * FROM Activite"; $query = "SELECT * FROM Activite";
return $this->connection->executeWithErrorHandling($query); $res = $this->connection->executeWithErrorHandling($query);
return $res;
} }
public function getActivityById(int $activityId) { public function getActivityById(int $activityId) {
$query = "SELECT * FROM Activite WHERE idActivite = :id"; $query = "SELECT * FROM Activite WHERE idActivite = :id";
$params = [':id' => [$activityId, PDO::PARAM_INT]]; $params = [':id' => [$activityId, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getActivityByType(string $type) { public function getActivityByType(string $type) {
$query = "SELECT * FROM Activite WHERE type = :type"; $query = "SELECT * FROM Activite WHERE type = :type";
$params = [':type' => [$type, PDO::PARAM_STR]]; $params = [':type' => [$type, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getActivityByDate(string $date) { public function getActivityByDate(string $date) {
$query = "SELECT * FROM Activite WHERE date = :date"; $query = "SELECT * FROM Activite WHERE date = :date";
$params = [':date' => [$date, PDO::PARAM_STR]]; $params = [':date' => [$date, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getActivityByTimeRange(string $startTime, string $endTime) { public function getActivityByTimeRange(string $startTime, string $endTime) {
@ -39,25 +43,29 @@ class ActivityGateway {
':startTime' => [$startTime, PDO::PARAM_STR], ':startTime' => [$startTime, PDO::PARAM_STR],
':endTime' => [$endTime, PDO::PARAM_STR] ':endTime' => [$endTime, PDO::PARAM_STR]
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getActivityByEffort(int $effortRessenti) { public function getActivityByEffort(int $effortRessenti) {
$query = "SELECT * FROM Activite WHERE effortRessenti = :effort"; $query = "SELECT * FROM Activite WHERE effortRessenti = :effort";
$params = [':effort' => [$effortRessenti, PDO::PARAM_INT]]; $params = [':effort' => [$effortRessenti, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getActivityByVariability(int $variabilite) { public function getActivityByVariability(int $variabilite) {
$query = "SELECT * FROM Activite WHERE variabilite = :variability"; $query = "SELECT * FROM Activite WHERE variabilite = :variability";
$params = [':variability' => [$variabilite, PDO::PARAM_INT]]; $params = [':variability' => [$variabilite, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getActivityByTemperature(int $temperatureMoyenne) { public function getActivityByTemperature(int $temperatureMoyenne) {
$query = "SELECT * FROM Activite WHERE temperatureMoyenne = :temperature"; $query = "SELECT * FROM Activite WHERE temperatureMoyenne = :temperature";
$params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]]; $params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function addActivity(ActivityEntity $activity) { public function addActivity(ActivityEntity $activity) {
@ -79,7 +87,8 @@ class ActivityGateway {
':temperatureMoyenne' => $activity->getTemperatureMoyenne(), ':temperatureMoyenne' => $activity->getTemperatureMoyenne(),
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function updateActivity(ActivityEntity $oldActivity, ActivityEntity $newActivity) { public function updateActivity(ActivityEntity $oldActivity, ActivityEntity $newActivity) {
@ -104,7 +113,8 @@ class ActivityGateway {
':temperatureMoyenne' => $newActivity->getTemperatureMoyenne(), ':temperatureMoyenne' => $newActivity->getTemperatureMoyenne(),
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function deleteActivity(int $idActivity) { public function deleteActivity(int $idActivity) {
@ -114,7 +124,8 @@ class ActivityGateway {
':idActivity' => $idActivity, ':idActivity' => $idActivity,
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
} }

@ -30,49 +30,56 @@ class AthleteGateway {
{ {
$query = "SELECT * FROM Athlete WHERE nom = :name AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE nom = :name AND isCoach=FALSE";
$params = [':name' => [$name, PDO::PARAM_STR]]; $params = [':name' => [$name, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getAthleteByFirstName(string $firstName): array public function getAthleteByFirstName(string $firstName): array
{ {
$query = "SELECT * FROM Athlete WHERE prenom = :firstName AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE prenom = :firstName AND isCoach=FALSE";
$params = [':firstName' => [$firstName, PDO::PARAM_STR]]; $params = [':firstName' => [$firstName, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getAthleteByEmail(string $email): array public function getAthleteByEmail(string $email): array
{ {
$query = "SELECT * FROM Athlete WHERE email = :email AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE email = :email AND isCoach=FALSE";
$params = [':email' => [$email, PDO::PARAM_STR]]; $params = [':email' => [$email, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getAthleteByGender(string $gender): array public function getAthleteByGender(string $gender): array
{ {
$query = "SELECT * FROM Athlete WHERE sexe = :gender AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE sexe = :gender AND isCoach=FALSE";
$params = [':gender' => [$gender, PDO::PARAM_STR]]; $params = [':gender' => [$gender, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getAthleteByHeight(int $height): array public function getAthleteByHeight(int $height): array
{ {
$query = "SELECT * FROM Athlete WHERE taille = :height AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE taille = :height AND isCoach=FALSE";
$params = [':height' => [$height, PDO::PARAM_INT]]; $params = [':height' => [$height, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getAthleteByWeight(int $weight): array public function getAthleteByWeight(int $weight): array
{ {
$query = "SELECT * FROM Athlete WHERE poids = :weight AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE poids = :weight AND isCoach=FALSE";
$params = [':weight' => [$weight, PDO::PARAM_INT]]; $params = [':weight' => [$weight, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function getAthleteByBirthDate(string $birthdate): array public function getAthleteByBirthDate(string $birthdate): array
{ {
$query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate AND isCoach=FALSE";
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]]; $params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function addAthlete(AthleteEntity $athlete): array public function addAthlete(AthleteEntity $athlete): array
@ -92,7 +99,8 @@ class AthleteGateway {
':isCoach' => $athlete->getIsCoach(), ':isCoach' => $athlete->getIsCoach(),
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function updateAthlete(AthleteEntity $oldAthlete, AthleteEntity $newAthlete): array public function updateAthlete(AthleteEntity $oldAthlete, AthleteEntity $newAthlete): array
@ -115,7 +123,8 @@ class AthleteGateway {
':isCoach' => $newAthlete->getIsCoach(), ':isCoach' => $newAthlete->getIsCoach(),
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }
public function deleteAthlete(int $idAthlete): array public function deleteAthlete(int $idAthlete): array
@ -126,7 +135,8 @@ class AthleteGateway {
':idAthlete' => $idAthlete, ':idAthlete' => $idAthlete,
]; ];
return $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
} }

@ -3,27 +3,98 @@
namespace Database; namespace Database;
class CoachEntity { class CoachEntity {
private $idCoach; private $idAthlete;
private $athleteId; private $nom;
private $prenom;
private $email;
private $sexe;
private $taille;
private $poids;
private $motDePasse;
private $dateNaissance;
private $isCoach;
// Getters // Getters
public function getIdCoach() { public function getIdAthlete() {
return $this->idCoach; return $this->idAthlete;
} }
public function getAthleteId() { public function getNom() {
return $this->athleteId; 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;
}
public function getIsCoach(){
return $this->isCoach;
} }
// Setters // Setters
public function setIdCoach($idCoach) { public function setIdAthlete($idAthlete) {
$this->idCoach = $idCoach; $this->idAthlete = $idAthlete;
} }
public function setAthleteId($athleteId) { public function setNom($nom) {
$this->athleteId = $athleteId; $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;
}
public function setIsCoach($isCoach){
$this->isCoach = $isCoach;
}
} }
?> ?>

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

@ -1,12 +1,12 @@
<?php <?php
namespace Database; namespace Database;
use Model\CoachAthlete;
use Model\User; use Model\User;
use \PDO; use \PDO;
use \DateTime; use \DateTime;
use Model\Role; use Model\Role;
use Model\Coach; use Model\Coach;
use Shared\Log;
class CoachMapper { class CoachMapper {
public function coachSqlToEntity(array $data): array { public function coachSqlToEntity(array $data): array {
@ -14,42 +14,65 @@ class CoachMapper {
foreach ($data as $coachData) { foreach ($data as $coachData) {
$coach = new CoachEntity(); $coach = new CoachEntity();
if (isset($coachData['idathlete'])) {
$coach->setIdAthlete($coachData['idathlete']);
}
if (isset($coachData['idCoach'])) { if (isset($coachData['nom'])) {
$coach->setIdCoach($coachData['idCoach']); $coach->setNom($coachData['nom']);
} }
if (isset($coachData['athleteId'])) { if (isset($coachData['prenom'])) {
$coach->setAthleteId($coachData['athleteId']); $coach->setPrenom($coachData['prenom']);
} }
$coachEntities[] = $coach; if (isset($coachData['email'])) {
$coach->setEmail($coachData['email']);
} }
return $coachEntities; if (isset($coachData['sexe'])) {
$coach->setSexe($coachData['sexe']);
} }
public function CoachEntityToModel(CoachEntity $coachEntity):User{ if (isset($coachData['taille'])) {
$role = new CoachAthlete(); $coach->setTaille($coachData['taille']);
}
$idCoach = $coachEntity->getIdCoach(); if (isset($coachData['poids'])) {
$coach->setPoids($coachData['poids']);
}
$ath = getAthleteByCoachId($idCoach); if (isset($coachData['motdepasse'])) {
$athlete = athleteSqlToEntity($ath); $coach->setMotDePasse($coachData['motdepasse']);
}
if (isset($coachData['datenaissance'])) {
$coach->setDateNaissance($coachData['datenaissance']);
}
$dateSpecific = $athlete->getDateNaissance(); if (isset($coachData['iscoach'])) {
$date = new DateTime($dateSpecific); $coach->setIsCoach($coachData['iscoach']);
}
$coachEntities[] = $coach;
}
return $coachEntities;
}
public function coachEntityToModel(CoachEntity $coachEntity): User {
$role = new Coach();
$date = new DateTime($coachEntity->getDateNaissance());
$user = new User( $user = new User(
$coachEntity->getIdCoach(), $coachEntity->getIdAthlete(),
$athlete->getNom(), $coachEntity->getNom(),
$athlete->getPrenom(), $coachEntity->getPrenom(),
$athlete->getEmail(), "myUsername",
$athlete->getMotDePasse(), $coachEntity->getEmail(),
$athlete->getSexe(), $coachEntity->getMotDePasse(),
$athlete->getTaille(), $coachEntity->getSexe(),
$athlete->getPoids(), $coachEntity->getTaille(),
$athlete->getDateNaissance(), $coachEntity->getPoids(),
$date, $date,
$role $role
); );
@ -57,14 +80,24 @@ class CoachMapper {
return $user; return $user;
} }
public function CoachToEntity(User $user):CoachEntity{ public function coachToEntity(User $user):CoachEntity{
$coach = new CoachEntity(); $coach = new CoachEntity();
$coach->setIdCoach($user->getId()); $coach->setIdAthlete($user->getId());
$coach->setAthleteId($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());
$coach->setIsCoach(TRUE);
return $coach; return $coach;
} }
} }
?> ?>

Loading…
Cancel
Save