diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 2384e5c1..4a317ec6 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -4,6 +4,7 @@ namespace App\Controller; use Database\ActivityGateway; use Database\ActivityMapper; +use Database\AnalyzeGateway; use Database\AthleteEntity; use Database\AthleteMapper; use Database\EntrainementGateway; @@ -120,36 +121,38 @@ class AthleteController extends BaseController return $response; } - #[Route(path: '/analyses/{id}', name: 'analyses', methods: ['GET'])] - public function analyses(): Response + #[Route(path: '/analyze/{id}', name: 'analyze_details', methods: ['GET'])] + public function activityDetails(): Response { try { - $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); - $listSearch = $activityGateway->getActivity(); - $map = new ActivityMapper(); - $activityGateway = $map->activitySqlToEntity($listSearch); - $listActivity = []; - foreach ($activityGateway as $entity) { - $activity = $map->activityEntityToModel($entity); - $listActivity[] = ['idactivity' => number_format($activity->getIdActivity(), 1), 'type' => $activity->getType(), - 'date' => $activity->getDate()->format("D j F Y"), 'heureDebut' => $activity->getHeureDebut()->format("H\h i"), 'heureFin' => $activity->getHeureFin()->format("H\h i"), - 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(), - 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(), - 'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' =>$activity->getAvrTemperature()]; - } + // Utilisez $id pour récupérer les détails de l'activité depuis la base de données +// $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); +// $activityEntity = $activityGateway->getActivityById($id); // Assurez-vous d'avoir une méthode similaire dans votre gateway + + $analyzeGateway = new AnalyzeGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $analyzeEntity = $analyzeGateway->getFrequenceCardiaque(); + +// $map = new ActivityMapper(); +// $activityModel = $map->activityEntityToModel($activityEntity); + Log::dd($analyzeEntity); + +// $listAnalyze = []; +// foreach ($analyzeEntity as $entity) { +// $user = $map->athleteEntityToModel($entity); +// $listUsers[] = ['idathlete' => number_format($user->getId(), 1), 'nom' => $user->getNom(), +// 'prenom' => $user->getPrenom(),'email' => $user->getEmail(), 'sexe' => $user->getSexe(), +// 'taille' => $user->getTaille(), 'poids' => $user->getPoids(), 'motdepasse' => $user->getMotDePasse(), +// 'datenaissance' => $user->getDateNaissance(), 'iscoach' => $user->getRole(), 'img' => 'test', +// 'username' => $user->getUsername()]; +// } - $response = $this->render('./page/analyze.html.twig',[ + $response = $this->render('./page/activity_details.html.twig', [ 'css' => $this->preference->getCookie(), 'pp' => "test2", 'user' => 'johndoe',//$currentUser->getUsername(), 'role' => 'Athlete',//$currentUser->getRole(), 'friendship' => [], - 'analyzes' => $listActivity, - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] + 'activity' => [], ]); } catch (\Throwable $th) { throw $th; @@ -158,6 +161,45 @@ class AthleteController extends BaseController return $response; } +// +// #[Route(path: '/analyses/{id}', name: 'analyses', methods: ['GET'])] +// public function analyses(): Response +// { +// try { +// $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); +// $listSearch = $activityGateway->getActivity(); +// $map = new ActivityMapper(); +// $activityGateway = $map->activitySqlToEntity($listSearch); +// $listActivity = []; +// foreach ($activityGateway as $entity) { +// $activity = $map->activityEntityToModel($entity); +// $listActivity[] = ['idactivity' => number_format($activity->getIdActivity(), 1), 'type' => $activity->getType(), +// 'date' => $activity->getDate()->format("D j F Y"), 'heureDebut' => $activity->getHeureDebut()->format("H\h i"), 'heureFin' => $activity->getHeureFin()->format("H\h i"), +// 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(), +// 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(), +// 'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' =>$activity->getAvrTemperature()]; +// } +// +// $response = $this->render('./page/analyze.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => 'johndoe',//$currentUser->getUsername(), +// 'role' => 'Athlete',//$currentUser->getRole(), +// 'friendship' => [], +// 'analyzes' => $listActivity, +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } catch (\Throwable $th) { +// throw $th; +// return $this->render("./page/analyze.html.twig", ['tabError' => $taberror]); +// } +// return $response; +// } + #[Route(path: '/activity', name: 'activity', methods: ['GET'])] public function activity(): Response { diff --git a/Sources/src/app/views/Templates/page/activity.html.twig b/Sources/src/app/views/Templates/page/activity.html.twig index be5fb8bd..cf855441 100644 --- a/Sources/src/app/views/Templates/page/activity.html.twig +++ b/Sources/src/app/views/Templates/page/activity.html.twig @@ -67,8 +67,10 @@ {{analyze.max}} Bpm {{analyze.min}} Bpm {{analyze.temperature}} °C -{# En savoir plus#} - En savoir plus + {{ analyze.effortRessenti }} +{# En savoir plus#} + En savoir plus +{# En savoir plus#} {% endfor %} diff --git a/Sources/src/app/views/Templates/page/analyze.html.twig b/Sources/src/app/views/Templates/page/analyze.html.twig index f22c8801..a2167c03 100755 --- a/Sources/src/app/views/Templates/page/analyze.html.twig +++ b/Sources/src/app/views/Templates/page/analyze.html.twig @@ -39,7 +39,7 @@ {{analyze.max}} Bpm {{analyze.min}} Bpm {{analyze.temperature}} °C - En savoir plus + Home {% endfor %} diff --git a/Sources/src/data/core/database/ActivityGateway.php b/Sources/src/data/core/database/ActivityGateway.php index ed6db38c..3d9e9564 100644 --- a/Sources/src/data/core/database/ActivityGateway.php +++ b/Sources/src/data/core/database/ActivityGateway.php @@ -17,7 +17,7 @@ class ActivityGateway { public function getActivityById(int $activityId) { $query = "SELECT * FROM Activite WHERE idActivite = :id"; - $params = [':id' => [$activityId, PDO::PARAM_INT]]; + $params = [':id' => $activityId]; return $this->connection->executeWithErrorHandling($query, $params); } diff --git a/Sources/src/data/core/database/AnalyzeEntity.php b/Sources/src/data/core/database/AnalyzeEntity.php new file mode 100644 index 00000000..4560f7b7 --- /dev/null +++ b/Sources/src/data/core/database/AnalyzeEntity.php @@ -0,0 +1,79 @@ +idFc; + } + public function getAltitude() + { + return $this->altitude; + } + public function getTime() + { + return $this->temps; + } + public function getTemperature() + { + return $this->temperature; + } + public function getBpm() + { + return $this->bpm; + } + public function getLongitude() + { + return $this->longitude; + } + public function getLatitude() + { + return $this->latitude; + } + public function getIdActivity() + { + return $this->idactivity; + } + public function setIdFC($idFc) + { + $this->idFc = $idFc; + } + public function setAltitude($altitude) + { + $this->altitude = $altitude; + } + public function setTime($time) + { + $this->time = $time; + } + public function setTemperature($temperature) + { + $this->temperature = $temperature; + } + public function setBpm($bpm) + { + $this->bpm = $bpm; + } + public function setLongitude($longitude) + { + $this->longitude = $longitude; + } + public function setLatitude($latitude) + { + $this->latitude = $latitude; + } + public function setIdActivity($idactivity) + { + $this->idactivity = $idactivity; + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/AnalyzeGateway.php b/Sources/src/data/core/database/AnalyzeGateway.php new file mode 100644 index 00000000..7dd7666a --- /dev/null +++ b/Sources/src/data/core/database/AnalyzeGateway.php @@ -0,0 +1,24 @@ +connection = $connection; + } + + public function getFrequenceCardiaque() { + $query = "SELECT * FROM FrequenceCardiaque"; + return $this->connection->executeWithErrorHandling($query); + } + public function getFrequenceCardiaqueByIdActivity(int $activityId) + { + $query = "SELECT * FROM FrequenceCardiaque WHERE activiteid = :id"; + $params = [':id' => $activityId]; + return $this->connection->executeWithErrorHandling($query, $params); + } + +} \ No newline at end of file diff --git a/Sources/src/data/core/database/AnalyzeMapper.php b/Sources/src/data/core/database/AnalyzeMapper.php new file mode 100644 index 00000000..6adc7733 --- /dev/null +++ b/Sources/src/data/core/database/AnalyzeMapper.php @@ -0,0 +1,123 @@ +setIdActivity($analyzeData['idactivite']); + } + + if (isset($analyzeData['type'])) { + $analyze->setType($analyzeData['type']); + } + + if (isset($analyzeData['date'])) { + $analyze->setDate($analyzeData['date']); + } + + if (isset($analyzeData['heurededebut'])) { + $analyze->setHeureDebut($analyzeData['heurededebut']); + } + + if (isset($analyzeData['heuredefin'])) { + $analyze->setHeureFin($analyzeData['heuredefin']); + } + + if (isset($analyzeData['effortressent'])) { + $analyze->setEffortRessenti($analyzeData['effortressent']); + } + + if (isset($analyzeData['variabilite'])) { + $analyze->setVariabilite($analyzeData['variabilite']); + } + + if (isset($analyzeData['variance'])) { + $analyze->setVariance($analyzeData['variance']); + } + + if (isset($analyzeData['ecarttype'])) { + $analyze->setEcartType($analyzeData['ecarttype']); + } + + if (isset($analyzeData['moyenne'])) { + $analyze->setMoyenne($analyzeData['moyenne']); + } + + if (isset($analyzeData['maximum'])) { + $analyze->setMaximum($analyzeData['maximum']); + } + + if (isset($analyzeData['minimum'])) { + $analyze->setMinimum($analyzeData['minimum']); + } + + if (isset($analyzeData['temperaturemoyenne'])) { + $analyze->setTemperatureMoyenne($analyzeData['temperaturemoyenne']); + } + + $analyzeEntities[] = $analyze; + } + return $analyzeEntities; + } + + /** + * @throws \Exception + */ +// public function ActivityEntityToModel(ActivityEntity $activiteEntity):Activity { +// $date = new DateTime($activiteEntity->getDate()); +// $heureDebut = new \DateTime($activiteEntity->getHeureDebut()); +// $heureFin = new \DateTime($activiteEntity->getHeureFin()); +// $effortRessenti = intval($activiteEntity->getEffortRessenti()); +// $variability = floatval($activiteEntity->getVariability()); +// $variance = floatval($activiteEntity->getVariance()); +// $ecartType = floatval($activiteEntity->getEcartType()); +// +// $act = new Activity( +// $activiteEntity->getIdActivity(), +// $activiteEntity->getType(), +// $date, +// $heureDebut, +// $heureFin, +// $effortRessenti, +// $variability, +// $variance, +// $ecartType, +// $activiteEntity->getMoyenne(), +// $activiteEntity->getMaximum(), +// $activiteEntity->getMinimum(), +// $activiteEntity->getTemperatureMoyenne(), +// 'false' +// ); +// +// return $act; +// } + //public function ActivityToEntity(Activity model): ActivityEntity; + +// public function activityToEntity( $act):ActivityEntity{ +// +// $act = new ActivityEntity(); +// $act->setIdActivity($act->getIdActivity()()); +// $act->setType($act->getType()); +// $act->setDate($act->getDate()); +// $act->setHeureDebut($act->getHeureDebut()); +// $act->setHeureFin($act->getHeureFin()); +// $act->setEffortRessenti($act->getEffortRessenti()); +// $act->setVariabilite($act->getVariability()); +// $act->setVariance($act->getVariance()); +// $act->setEcartType($act->getEcartType()); +// $act->setMoyenne($act->getMoyenne()); +// $act->setMaximum($act->getMaximum()); +// $act->setMinimum($act->getMinimum()); +// $act->setTemperatureMoyenne($act->getTemperatureMoyenne()); +// +// return $act; +// } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/data/athlete.sql b/Sources/src/data/core/database/data/athlete.sql new file mode 100644 index 00000000..51c2b19a --- /dev/null +++ b/Sources/src/data/core/database/data/athlete.sql @@ -0,0 +1,6 @@ +INSERT INTO Athlete (idAthlete, username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES + (1, 'johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 70, 'password123', '1990-01-01', FALSE), + (2, 'janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE), + (3, 'bryanO', 'OConner', 'Bryan', 'bryan.oconner@example.com', 'M', 1.88, 86, 'password789', '1973-09-12', FALSE), + (4, 'dominicT', 'Toretto', 'Dominic', 'dominic.toretto@example.com', 'M', 1.83, 94, 'password987', '1967-07-18', TRUE), + (5, 'miaT', 'Toretto', 'Mia', 'mia.toretto@example.com', 'F', 1.70, 56, 'password654', '1980-04-26', FALSE); \ No newline at end of file diff --git a/Sources/src/data/core/database/data/friendship.sql b/Sources/src/data/core/database/data/friendship.sql new file mode 100644 index 00000000..da8b2a52 --- /dev/null +++ b/Sources/src/data/core/database/data/friendship.sql @@ -0,0 +1,29 @@ +INSERT INTO Friendship (idAthlete1, idAthlete2, debut) VALUES + (3, 4, '2023-01-01'), + (3, 5, '2023-01-12'); + +INSERT INTO Notification (idNotif, message, date, statut, urgence, athleteId) VALUES + (1, 'Training session at 10 AM', '2023-03-10', TRUE, 1, 1), + (2, 'Training session at 3 PM', '2023-05-10', TRUE, 1, 2); + +INSERT INTO Statistique (idStatistique, poids, fcMoyenne, fcMax, caloriesBruleesMoy, date, athleteId) VALUES + (1, 70, 80, 150, 500, '2023-03-10', 1), + (2, 86, 95, 170, 896, '2023-04-13', 3); + +INSERT INTO Entrainement (idEntrainement, date, description, latitude, longitude, feedback, athleteId) VALUES + (1, '2023-03-10', 'Long run in the park', 40.7128, -74.0060, 'Good effort', 1), + (2, '2023-04-13', 'Long run in the forest', 44.7128, -70.0060, 'Pretty good effort', 3); + +INSERT INTO Participe (athleteId, entrainementId) VALUES + (1, 1), + (3, 2); + +INSERT INTO SourceDonnee (idSource, type, modele, precision2, athleteId) VALUES + (1, 'Heart Rate Monitor', 'HRM-Pro', 98.5, 1); + +INSERT INTO Activite (idActivite, type, date, heureDeDebut, heureDeFin, effortRessent, variabilite, variance, ecartType, moyenne, maximum, minimum, temperatureMoyenne, athleteId, sourceId) VALUES + (1, 'Running', '2023-03-10', '08:00:00', '09:00:00', 3, 0.5, 1, 0.1, 140, 160, 120, 20, 1, 1), + (2, 'Running Forest', '2023-04-13', '10:00:00', '12:00:00', 5, 0.5, 1, 0.1, 140, 160, 120, 20, 1, 1); + +INSERT INTO FrequenceCardiaque (idFc, altitude, temps, temperature, bpm, longitude, latitude, activiteId) VALUES + (1, 100, '08:15:00', 15, 130, -74.0060, 40.7128, 1); \ No newline at end of file diff --git a/Sources/src/data/core/database/db.sql b/Sources/src/data/core/database/data/tables.sql similarity index 71% rename from Sources/src/data/core/database/db.sql rename to Sources/src/data/core/database/data/tables.sql index 0eae219b..2a8f0ab3 100644 --- a/Sources/src/data/core/database/db.sql +++ b/Sources/src/data/core/database/data/tables.sql @@ -103,30 +103,5 @@ CREATE TABLE FrequenceCardiaque ( FOREIGN KEY (activiteId) REFERENCES Activite(idActivite) ); -INSERT INTO Athlete (idAthlete, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES - (1, 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 70, 'password123', '1990-01-01', FALSE), - (2, 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE); - -INSERT INTO Friendship (idAthlete1, idAthlete2, debut) VALUES - (1, 2, '2023-01-01'); - -INSERT INTO Notification (idNotif, message, date, statut, urgence, athleteId) VALUES - (1, 'Training session at 10 AM', '2023-03-10', TRUE, 1, 1); - -INSERT INTO Statistique (idStatistique, poids, fcMoyenne, fcMax, caloriesBruleesMoy, date, athleteId) VALUES - (1, 70, 80, 150, 500, '2023-03-10', 1); - -INSERT INTO Entrainement (idEntrainement, date, description, latitude, longitude, feedback, athleteId) VALUES - (1, '2023-03-12', 'Long run in the park', 40.7128, -74.0060, 'Good effort', 1); - -INSERT INTO Participe (athleteId, entrainementId) VALUES - (1, 1); - -INSERT INTO SourceDonnee (idSource, type, modele, precision2, athleteId) VALUES - (1, 'Heart Rate Monitor', 'HRM-Pro', 98.5, 1); - -INSERT INTO Activite (idActivite, type, date, heureDeDebut, heureDeFin, effortRessent, variabilite, variance, ecartType, moyenne, maximum, minimum, temperatureMoyenne, athleteId, sourceId) VALUES - (1, 'Running', '2023-03-10', '08:00:00', '09:00:00', 7, 0.5, 1, 0.1, 140, 160, 120, 20, 1, 1); - -INSERT INTO FrequenceCardiaque (idFc, altitude, temps, temperature, bpm, longitude, latitude, activiteId) VALUES - (1, 100, '08:15:00', 15, 130, -74.0060, 40.7128, 1); +\i athlete.sql +\i friendship.sql \ No newline at end of file