Compare commits

...

8 Commits

Author SHA1 Message Date
Kevin MONTEIRO 18f7205540 nada
continuous-integration/drone/push Build is failing Details
1 year ago
Kevin MONTEIRO ca732f2c97 Athlete Gateway, Mappeur et Entity fonctionnel avec test unitaires
continuous-integration/drone/push Build is failing Details
1 year ago
Kevin MONTEIRO 64c04a97f6 Ajout test unitaire non fonctionnel ( Class Connection not found )
continuous-integration/drone/push Build is failing Details
1 year ago
Kevin MONTEIRO c09ce09b26 Gateway, Entity, Mappeur : Coach, Athlete et Activite
continuous-integration/drone/push Build is passing Details
1 year ago
Kevin MONTEIRO 8a2736e6ff Add User Gateway
continuous-integration/drone/push Build is passing Details
1 year ago
Kevin MONTEIRO 5be89731ad Adaptation PHP 7
continuous-integration/drone/push Build is passing Details
1 year ago
Kevin MONTEIRO 5b970ccd74 Merge branch 'issue_16_statistics_coach' of https://codefirst.iut.uca.fr/git/FitDev/Projet_fit_web into issue_16_statistics_coach
continuous-integration/drone/push Build is passing Details
1 year ago
Kevin MONTEIRO 13a1c02d83 modif Diagramme Classe
1 year ago

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
{"version":1,"defects":{"MaClasseTest::testMethode":5,"ExampleTest::testMethode":5,"toto::testMethode":5,"AthleteGateway::testGateway":5,"Database\\Tests\\AthleteGatewayTest::testGetAthlete":4,"Database\\Tests\\AthleteGatewayTest::testGetAthleteById":4,"Database\\Tests\\AthleteGatewayTest::testAddAthlete":4,"Database\\Tests\\AthleteGatewayTest::testUpdateAthlete":4,"Database\\Tests\\AthleteGatewayTest::testDeleteAthlete":4,"Database\\AthleteGatewayTest::testGetAthlete":4,"Database\\AthleteGatewayTest::testGetAthleteById":4,"Database\\AthleteGatewayTest::testAddAthlete":4,"Database\\AthleteGatewayTest::testUpdateAthlete":4,"Database\\AthleteGatewayTest::testDeleteAthlete":4,"AthleteGatewayTest::testAddAndGetAthlete":4,"AthleteGatewayTest::testGetAthlete":5,"AthleteGatewayTest::testAddAthlete":5,"AthleteGatewayTest::testDeleteAthlete":4,"AthleteGatewayTest::testUpdateAthlete":5,"AthleteMapperTest::testMapperAthlete":5,"GatewayTest::testGetAthlete":5,"GatewayTest::testUpdateAthlete":5,"MapperTest::testMapperAthlete":5,"GatewayTest::testGetCoach":5,"GatewayTest::testAddCoach":4},"times":{"MaClasseTest::testMethode":0.001,"ExampleTest::testMethode":0.001,"toto::testMethode":0.001,"AthleteGateway::testGateway":0.048,"Database\\Tests\\AthleteGatewayTest::testGetAthlete":0.001,"Database\\Tests\\AthleteGatewayTest::testGetAthleteById":0.001,"Database\\Tests\\AthleteGatewayTest::testAddAthlete":0.072,"Database\\Tests\\AthleteGatewayTest::testUpdateAthlete":0.001,"Database\\Tests\\AthleteGatewayTest::testDeleteAthlete":0.001,"Database\\AthleteGatewayTest::testGetAthlete":0.002,"Database\\AthleteGatewayTest::testGetAthleteById":0,"Database\\AthleteGatewayTest::testAddAthlete":0,"Database\\AthleteGatewayTest::testUpdateAthlete":0,"Database\\AthleteGatewayTest::testDeleteAthlete":0,"AthleteGatewayTest::testAddAndGetAthlete":0.028,"AthleteGatewayTest::testGetAthlete":0.004,"AthleteGatewayTest::testAddAthlete":0.005,"AthleteGatewayTest::testDeleteAthlete":0.003,"AthleteGatewayTest::testUpdateAthlete":0.006,"AthleteMapperTest::testMapperAthlete":0.004,"GatewayTest::testGetAthlete":0.005,"GatewayTest::testUpdateAthlete":0.009,"MapperTest::testMapperAthlete":0.018,"GatewayTest::testGetCoach":0.055,"GatewayTest::testAddCoach":0.015}}

@ -9,6 +9,7 @@
"Repository\\": "src/data/model/repository", "Repository\\": "src/data/model/repository",
"Manager\\": "src/data/model/manager", "Manager\\": "src/data/model/manager",
"Network\\": "src/data/core/network", "Network\\": "src/data/core/network",
"Database\\": "src/data/core/database",
"Console\\": "src/console", "Console\\": "src/console",
"Stub\\": [ "Stub\\": [
"src/data/stub", "src/data/stub",
@ -24,10 +25,11 @@
"vlucas/phpdotenv": "^5.5" "vlucas/phpdotenv": "^5.5"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "*" "phpunit/phpunit": "^9.6"
}, },
"scripts": { "scripts": {
"dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL", "dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL",
"dev:console": "export APP_ENV=console && php public/index.php" "dev:console": "export APP_ENV=console && php public/index.php",
"test" : "./vendor/bin/phpunit tests"
} }
} }

@ -0,0 +1,127 @@
<?php
namespace Database;
class ActiviteEntity {
private $idActivite;
private $type;
private $date;
private $heureDebut;
private $heureFin;
private $effortRessenti;
private $variabilite;
private $variance;
private $ecartType;
private $moyenne;
private $maximum;
private $minimum;
private $temperatureMoyenne;
// Getters
public function getIdActivite() {
return $this->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;
}
}
?>

@ -0,0 +1,120 @@
<?php
namespace Database;
class ActiviteGateway {
private $connection;
public function __construct(Connection $connection) {
$this->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);
}
}
?>

@ -0,0 +1,51 @@
<?php
namespace Database;
use Model\Activite;
class ActiviteMapper {
public function map(array $data):ActiviteEntity {
$activite = new ActiviteEntity();
$activite->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;
}
?>

@ -0,0 +1,91 @@
<?php
namespace Database;
class AthleteEntity {
private $idAthlete;
private $nom;
private $prenom;
private $email;
private $sexe;
private $taille;
private $poids;
private $motDePasse;
private $dateNaissance;
// Getters
public function getIdAthlete() {
return $this->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;
}
}
?>

@ -0,0 +1,131 @@
<?php
namespace Database;
use \PDO;
class AthleteGateway {
private $connection;
public function __construct(Connexion $connection) {
$this->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);
?>

@ -0,0 +1,99 @@
<?php
namespace Database;
use Model\User;
use \PDO;
use \DateTime;
use Model\Role;
use Model\Athlete;
class AthleteMapper {
public function fromSqlToEntity(array $data): array {
$athleteEntities = [];
foreach ($data as $athleteData) {
$athlete = new AthleteEntity();
if (isset($athleteData['idAthlete'])) {
$athlete->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;
}
}
?>

@ -0,0 +1,91 @@
<?php
namespace Database;
class CoachEntity {
private $idCoach;
private $nom;
private $prenom;
private $email;
private $sexe;
private $taille;
private $poids;
private $motDePasse;
private $dateNaissance;
// Getters
public function getIdCoach() {
return $this->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;
}
}
?>

@ -0,0 +1,109 @@
<?php
namespace Database;
use \PDO;
class CoachGateway {
private $connection;
public function __construct(Connexion $connection) {
$this->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);
}
}

@ -0,0 +1,62 @@
<?php
namespace Database;
use Model\User;
use \PDO;
use \DateTime;
use Model\Role;
use Model\Coach;
class CoachMapper {
public function map(array $data) {
$coach = new CoachEntity();
$coach->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;
}
}
?>

@ -0,0 +1,49 @@
<?php
namespace Database;
class Connexion extends \PDO {
private $stmt;
public function __construct(string $dsn,string $username, string $password) {
try {
parent::__construct($dsn,$username,$password);
$this->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);
}
}
?>

@ -5,18 +5,41 @@ use Model\Role;
// Data Class // Data Class
class User{ class User{
private int $id;
private string $nom;
private string $prenom;
private string $email;
private string $motDePasse;
private string $sexe;
private float $taille;
private float $poids;
private \DateTime $dateNaissance;
private Role $role;
public function __construct( public function __construct(
private int $id, int $id,
private string $nom, string $nom,
private string $prenom, string $prenom,
private string $email, string $email,
private string $motDePasse, string $motDePasse,
private string $sexe, string $sexe,
private float $taille, float $taille,
private float $poids, float $poids,
private \DateTime $dateNaissance, \DateTime $dateNaissance,
private Role $role, Role $role
) {} ) {
$this->id = $id;
$this->nom = $nom;
$this->prenom = $prenom;
$this->email = $email;
$this->motDePasse = $motDePasse;
$this->sexe = $sexe;
$this->taille = $taille;
$this->poids = $poids;
$this->dateNaissance = $dateNaissance;
$this->role = $role;
}
public function getId(): int { public function getId(): int {
return $this->id; return $this->id;
} }

@ -1,13 +0,0 @@
<?php
namespace DataManager;
class CoachManager
{
/**
*/
public function __construct()
{
}
}

@ -0,0 +1,220 @@
<?php
use PHPUnit\Framework\TestCase;
//use Database\{Connexion, AthleteGateway,AthleteEntity};
use Database\AthleteEntity;
use Database\AthleteGateway;
use Database\Connexion;
use Database\AthleteMapper;
use Database\CoachGateway;
use Database\CoachEntity;
use Database\CoachMapper;
class GatewayTest extends TestCase {
//Partie concernant les Athlètes
public function testGetAthlete() {
//$dsn = "pgsql:host=londres;port=8888;dbname=dbkemonteiro2;user=kemonteiro2;password=Mdp";
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$result = $athleteGateway->getAthlete();
//var_dump($result);
}
/* Fonctionne mais en commentaire pour pas add et del a chaque fois
public function testAddAthlete(){
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$dateSpecifique = "2023-11-26";
$timestamp = strtotime($dateSpecifique);
$dateSQL = date("Y-m-d", $timestamp);
$athleteEntity = new AthleteEntity();
$athleteEntity->setNom('John');
$athleteEntity->setPrenom('Doe');
$athleteEntity->setIdAthlete(1234);
$athleteEntity->setEmail('kevin.monteiro@gmail.fr');
$athleteEntity->setSexe('H');
$athleteEntity->setTaille(169);
$athleteEntity->setPoids(69);
$athleteEntity->setMotDePasse('motdepasse');
$athleteEntity->setDateNaissance($dateSQL);
$result2 = $athleteGateway->addAthlete($athleteEntity);
}
public function testDeleteAthlete(){
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$result = $athleteGateway->deleteAthlete( //idAthlete );
var_dump($result);
}*/
public function testUpdateAthlete(){
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$dateSpecifique = "2004-08-26";
$timestamp = strtotime($dateSpecifique);
$dateSQL = date("Y-m-d", $timestamp);
$athleteEntity = new AthleteEntity();
$athleteEntity->setNom('John');
$athleteEntity->setPrenom('Doe');
$athleteEntity->setIdAthlete(13);
$athleteEntity->setEmail('kevin.monteiro@gmail.fr');
$athleteEntity->setSexe('H');
$athleteEntity->setTaille(169);
$athleteEntity->setPoids(69);
$athleteEntity->setMotDePasse('motdepasse');
$athleteEntity->setDateNaissance($dateSQL);
$athleteEntity2 = new AthleteEntity();
$athleteEntity2->setNom('Monteiro');
$athleteEntity2->setPrenom('Kevin');
$athleteEntity2->setIdAthlete(13);
$athleteEntity2->setEmail('kevin.monteiro@gmail.fr');
$athleteEntity2->setSexe('H');
$athleteEntity2->setTaille(169);
$athleteEntity2->setPoids(69);
$athleteEntity2->setMotDePasse('motdepasse');
$athleteEntity2->setDateNaissance($dateSQL);
$result = $athleteGateway->updateAthlete($athleteEntity, $athleteEntity2);
}
//Partie concernant les Coachs
public function testGetCoach() {
//$dsn = "pgsql:host=londres;port=8888;dbname=dbkemonteiro2;user=kemonteiro2;password=Mdp";
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$coachGateway = new CoachGateway($connexion);
$result = $coachGateway->getCoach();
var_dump($result);
}
/*
//Fonctionne PAS A PARTIR DE LA
public function testAddCoach(){
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$coachGateway = new CoachGateway($connexion);
$dateSpecifique = "2023-11-26";
$timestamp = strtotime($dateSpecifique);
$dateSQL = date("Y-m-d", $timestamp);
$coachEntity = new CoachEntity();
$coachEntity->setNom('John');
$coachEntity->setPrenom('Doe');
$coachEntity->setIdCoach(1234);
$coachEntity->setEmail('kevin.monteiro@gmail.fr');
$coachEntity->setSexe('H');
$coachEntity->setTaille(169);
$coachEntity->setPoids(69);
$coachEntity->setMotDePasse('motdepasse');
$coachEntity->setDateNaissance($dateSQL);
$result2 = $coachGateway->addCoach($coachEntity);
}
public function testDeleteAthlete(){
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$result = $athleteGateway->deleteAthlete( //idAthlete );
var_dump($result);
}*/
/*
public function testUpdateAthlete(){
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$dateSpecifique = "2004-08-26";
$timestamp = strtotime($dateSpecifique);
$dateSQL = date("Y-m-d", $timestamp);
$athleteEntity = new AthleteEntity();
$athleteEntity->setNom('John');
$athleteEntity->setPrenom('Doe');
$athleteEntity->setIdAthlete(13);
$athleteEntity->setEmail('kevin.monteiro@gmail.fr');
$athleteEntity->setSexe('H');
$athleteEntity->setTaille(169);
$athleteEntity->setPoids(69);
$athleteEntity->setMotDePasse('motdepasse');
$athleteEntity->setDateNaissance($dateSQL);
$athleteEntity2 = new AthleteEntity();
$athleteEntity2->setNom('Monteiro');
$athleteEntity2->setPrenom('Kevin');
$athleteEntity2->setIdAthlete(13);
$athleteEntity2->setEmail('kevin.monteiro@gmail.fr');
$athleteEntity2->setSexe('H');
$athleteEntity2->setTaille(169);
$athleteEntity2->setPoids(69);
$athleteEntity2->setMotDePasse('motdepasse');
$athleteEntity2->setDateNaissance($dateSQL);
$result = $athleteGateway->updateAthlete($athleteEntity, $athleteEntity2);
}*/
}

@ -0,0 +1,43 @@
<?php
use PHPUnit\Framework\TestCase;
use Model\User;
use Database\AthleteEntity;
use Database\AthleteGateway;
use Database\Connexion;
use Database\AthleteMapper;
class MapperTest extends TestCase {
public function testMapperAthlete() {
//$dsn = "pgsql:host=londres;port=8888;dbname=dbkemonteiro2;user=kemonteiro2;password=Mdp";
$dsn = "mysql:host=londres;dbname=dbkemonteiro2;";
$username = "kemonteiro2";
$password = "#Phpmyadmin63";
$connexion = new Connexion($dsn,$username,$password);
$athleteGateway = new AthleteGateway($connexion);
$result = $athleteGateway->getAthlete();
$map = new AthleteMapper ();
//SQL To AthleteEntity
$athleteEntity = $map->fromSqlToEntity($result);
foreach($athleteEntity as $ath){
$result = $ath->getNom();
var_dump($result);
//Pour chaque AthleteEntity : Athlete Entity To User avec Role Athlete(Model)
$user = $map->athleteEntityToModel($ath);
var_dump($user->getId());
//Pour chaque Athlete du Model -> Athlete Entity
$res = $map->athleteToEntity($user);
var_dump($res->getIdAthlete());
}
}
}

@ -1,12 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
class MaClasseTest extends TestCase
{
public function testMethode()
{
echo "TEST MEC";
}
}

@ -0,0 +1 @@
{"version":1,"defects":[],"times":{"ExampleTest::testAddition":0.037}}

@ -24,6 +24,7 @@ return array(
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'), 'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'), 'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'), 'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
'Database\\' => array($baseDir . '/src/data/core/database'),
'Data\\' => array($baseDir . '/src/data'), 'Data\\' => array($baseDir . '/src/data'),
'Console\\' => array($baseDir . '/src/console'), 'Console\\' => array($baseDir . '/src/console'),
'App\\' => array($baseDir . '/src/app'), 'App\\' => array($baseDir . '/src/app'),

@ -59,6 +59,7 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
'Dotenv\\' => 7, 'Dotenv\\' => 7,
'Doctrine\\Instantiator\\' => 22, 'Doctrine\\Instantiator\\' => 22,
'DeepCopy\\' => 9, 'DeepCopy\\' => 9,
'Database\\' => 9,
'Data\\' => 5, 'Data\\' => 5,
), ),
'C' => 'C' =>
@ -146,6 +147,10 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy', 0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy',
), ),
'Database\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/core/database',
),
'Data\\' => 'Data\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src/data', 0 => __DIR__ . '/../..' . '/src/data',

@ -3,7 +3,7 @@
'name' => 'hearttrack/package', 'name' => 'hearttrack/package',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'd4345678992503b9eb56ef4afd00ff13f5d7531a', 'reference' => 'c09ce09b267f34dee8978397953b90d55d7d3873',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -31,7 +31,7 @@
'hearttrack/package' => array( 'hearttrack/package' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'd4345678992503b9eb56ef4afd00ff13f5d7531a', 'reference' => 'c09ce09b267f34dee8978397953b90d55d7d3873',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),

Loading…
Cancel
Save