diff --git a/Documents/Diagramme/BDD/README_BDD.md b/Documents/Diagramme/BDD/README_BDD.md new file mode 100644 index 00000000..f30c5f44 --- /dev/null +++ b/Documents/Diagramme/BDD/README_BDD.md @@ -0,0 +1,121 @@ +[retour au README.md](../../../README.md) +[Retour aux Documents](../../README_DOCUMENTS.md) +[Retour au diagramme de classes](../README_DIAGRAMMES.md) + +# BDD + +```plantuml +@startuml +skinparam classAttributeIconSize 0 +package MLD{ +entity "Athlète" as athlete { + {static} idAthlete + nom + prénom + email + sexe + taille + poids + motDePasse + dateNaissance +} + +entity "Amitié" as friendship{ +{static}# idAthlete1 +{static}# idAthlete2 +début +} + +entity "Notification" as notif { + {static} idNotif + message + date + statut + urgence + #athleteId +} + +entity "Coach" as coach { + {static} idCoach + // attributs spécifiques au coach + #athleteId +} + +entity "Statistique" as stats { + {static} idStatistique + poids + fcMoyenne + fcMax + caloriesBrûléesMoy + date + #athleteId +} + +entity "Entraînement" as training { + {static} idEntrainement + date + description + // Exercices + latitude + longitude + feedback + #coachId +} + +entity "Participe" as takepart { + {static} #athleteId + {static} #entrainementId +} + + +entity "SourceDonnée" as source { + {static} idSource + type + modèle + précision + #athleteId +} + +entity "Activité" as activity { + {static} idActivité + type + date + heureDeDébut + heureDeFin + effortRessent + variabilité + variance + ecartType + moyenne + maximum + minimum + temperatureMoyenne + #athleteId + #sourceId +} +entity "FréquenceCardiaque" as fc { + {static} idFc + altitude + temps : time + température + bpm + longitude + latitude + #activitéId +} + +} +activity --> athlete +activity --> source +activity <-- fc +coach --> athlete +athlete <-- source +stats --> athlete +takepart --> athlete +takepart --> training +friendship --> athlete +notif --> athlete +coach <-- training +athlete <-- friendship +@enduml +``` \ No newline at end of file diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 176304d9..72c3031e 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -3,6 +3,8 @@ namespace App\Controller; use Database\AthleteMapper; +use Database\EntrainementGateway; +use Database\EntrainementMapper; use Shared\Validation; use App\Container; use App\Router\Request\IRequest; @@ -151,19 +153,43 @@ class AthleteController extends BaseController #[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8 public function exercice(): Response { - return $this->render('./page/exercice.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => 'johndoe',//$currentUser->getUsername(), - 'role' => 'Athlete',//$currentUser->getRole(), - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); + try { + $entrainementGateway = new EntrainementGateway(new Connexion("pgsql:host=localhost;dbname=sae_3", "Perederii", "")); + $listSearch = $entrainementGateway->getEntrainements(); + $map = new EntrainementMapper(); + $entrainementEntity = $map->entrainementSqlToEntity($listSearch); + + $listUsers = []; + $i = 0; + foreach ($entrainementEntity as $entity) { + $user = $map->entrainementEntityToModel($entity); + $listUsers[$i] = ['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()]; + $i++; + } + + $response = $this->render('./page/exercice.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => 'johndoe',//$currentUser->getUsername(), + 'role' => 'Athlete',//$currentUser->getRole(), + 'friendship' => [], + 'analyzes' => [], + 'mails' => [], + 'users' => [], + 'infoUser' => [], + 'exos' => [], + 'member' => [] + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); + } + return $response; } #[Route(path: '/exercices', name: 'exercices', methods: ['POST'])] // 8 @@ -196,13 +222,17 @@ class AthleteController extends BaseController public function addFriend(string $username, IRequest $req): Response { try { - $userSearched=$this->container->get(UserManager::class)->searchUserByName($username); + $athleteGateway = new AthleteGateway(new Connexion("pgsql:host=localhost;dbname=sae_3", "Perederii", "")); + $userSearched=$athleteGateway->getAthleteByFirstName($username); $currentUser=$this->container->get(UserManager::class)->getUserById(1); - if ($userSearched!=null){ + if ($userSearched!=null) { $currentUser->addFriend($userSearched); + foreach ($userSearched as $user) { + $users = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()]; + } } - foreach ($userSearched as $user){ - $users=['nom' => $user->getNom(), 'prenom'=>$user->getPrenom(), 'img'=>'test', 'username'=>$user->getUsername()]; + else{ + $users=[]; } return $this->render('./page/addfriend.html.twig',[ 'css' => $this->preference->getCookie(), @@ -275,13 +305,17 @@ class AthleteController extends BaseController #[Route(path: '/friendlist', name: 'friendlist2', methods: ['GET'])] public function friendlist2(): Response { - $friendList = $this->container->get(UserManager::class)->getFriends(); + $athleteGateway = new AthleteGateway(new Connexion("pgsql:host=localhost;dbname=sae_3", "Perederii", "")); + $friendList = $athleteGateway->getListIdFriends(1); + foreach ($userSearched as $friendList) { + $users = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()]; + } return $this->render('./page/friend.html.twig',[ 'css' => $this->preference->getCookie(), 'pp' => "test2", 'user' => "Doe", 'role' => "Athlète", - 'friendship' => $friendList, + 'friendship' => $list, 'analyzes' => [], 'mails' => [], 'users' => [], diff --git a/Sources/src/data/core/database/ActiviteGateway.php b/Sources/src/data/core/database/ActivityGateway.php similarity index 100% rename from Sources/src/data/core/database/ActiviteGateway.php rename to Sources/src/data/core/database/ActivityGateway.php diff --git a/Sources/src/data/core/database/ActiviteMapper.php b/Sources/src/data/core/database/ActivityMapper.php similarity index 100% rename from Sources/src/data/core/database/ActiviteMapper.php rename to Sources/src/data/core/database/ActivityMapper.php diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php index 8bada5e3..da0c4262 100644 --- a/Sources/src/data/core/database/AthleteGateway.php +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -75,6 +75,17 @@ class AthleteGateway { return $this->connection->executeWithErrorHandling($query, $params); } + public function getListIdFriends(int $idAthlete): array + { + $query = "SELECT idAthlete1, idAthlete2 FROM Friendship WHERE idAthlete1 = :idAthlete OR idAthlete2= :idAthlete"; + + $params = [ + ':idAthlete' => $idAthlete, + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } + public function addAthlete(AthleteEntity $athlete): array { $query = "INSERT INTO Athlete (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) diff --git a/Sources/src/data/core/database/EntrainementEntity.php b/Sources/src/data/core/database/EntrainementEntity.php new file mode 100644 index 00000000..82340c2c --- /dev/null +++ b/Sources/src/data/core/database/EntrainementEntity.php @@ -0,0 +1,71 @@ +idEntrainement; + } + public function getDate() + { + return $this->date; + } + public function getDescription() + { + return $this->description; + } + public function getLatitude() + { + return $this->latitude; + } + public function getLongitude() + { + return $this->longitude; + } + public function getFeedback() + { + return $this->feedback; + } + public function getCoachId() + { + return $this->coachId; + } + public function setIdEntrainement($idEntrainement) + { + $this->idEntrainement = $idEntrainement; + } + public function setDate($date) + { + $this->date = $date; + } + public function setDescription($description) + { + $this->description = $description; + } + public function setLatitude($latitude) + { + $this->latitude = $latitude; + } + public function setLongitude($longitude) + { + $this->longitude = $longitude; + } + public function setFeedback($feedback) + { + $this->feedback = $feedback; + } + public function setCoachId($coachId) + { + $this->coachId = $coachId; + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/EntrainementGateway.php b/Sources/src/data/core/database/EntrainementGateway.php new file mode 100644 index 00000000..04032659 --- /dev/null +++ b/Sources/src/data/core/database/EntrainementGateway.php @@ -0,0 +1,19 @@ +connection = $connection; + } + + public function getEntrainements(): array + { + $query = "SELECT * FROM Entrainement"; + $res = $this->connection->executeWithErrorHandling($query); + return $res; + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/EntrainementMapper.php b/Sources/src/data/core/database/EntrainementMapper.php new file mode 100644 index 00000000..5da55f0f --- /dev/null +++ b/Sources/src/data/core/database/EntrainementMapper.php @@ -0,0 +1,74 @@ +setIdEntrainement($entrainementData['idEntrainement']); + } + + if (isset($entrainementData['date'])) { + $entrainement->setDate($entrainementData['date']); + } + + if (isset($entrainementData['description'])) { + $entrainement->setDescription($entrainementData['description']); + } + + if (isset($entrainementData['latitude'])) { + $entrainement->setLatitude($entrainementData['latitude']); + } + + if (isset($entrainementData['longitude'])) { + $entrainement->setLongitude($entrainementData['longitude']); + } + + if (isset($entrainementData['feedback'])) { + $entrainement->setFeedback($entrainementData['feedback']); + } + + if (isset($entrainementData['coachId'])) { + $entrainement->setCoachId($entrainementData['coachId']); + } + + $entrainementEntities[] = $entrainement; + } + + return $entrainementEntities; + } + + public function entrainementEntityToModel(EntrainementEntity $entrainementEntity): Training { + return new Training( + $entrainementEntity->getIdEntrainement(), + $entrainementEntity->getDate(), + $entrainementEntity->getDescription(), + $entrainementEntity->getLatitude(), + $entrainementEntity->getLongitude(), + $entrainementEntity->getFeedback() + ); + } + + public function entrainementToEntity(Training $training):EntrainementEntity{ + + $train = new EntrainementEntity(); + $train->setIdEntrainement($training->getId()); + $train->setDate($training->getDate()); + $train->setDescription($training->getDescription()); + $train->setLatitude($training->getLatitude()); + $train->setLongitude($training->getLongitude()); + $train->setFeedback($training->getFeedback()); + $train->setCoachId(1); + + return $train; + } +} \ No newline at end of file diff --git a/Sources/src/data/model/Training.php b/Sources/src/data/model/Training.php index 98291d77..220b1b97 100644 --- a/Sources/src/data/model/Training.php +++ b/Sources/src/data/model/Training.php @@ -35,6 +35,12 @@ class Training public function getLocation(): String { return $this->longitude . $this->latitude; } + public function getLatitude(): float { + return $this->latitude; + } + public function getLongitude(): float { + return $this->longitude; + } public function getDescription(): String { return $this->description;