diff --git a/Sources/config/config.php b/Sources/config/config.php index 8ddae748..4d0a0f4d 100755 --- a/Sources/config/config.php +++ b/Sources/config/config.php @@ -12,10 +12,11 @@ $dotenv->safeLoad(); // const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger'; define("APP_ENV", 'development'); +const DB_SERVER = 'pgsql'; const DB_HOST = 'localhost'; -const DB_DATABASE = 'heartTrack'; -const DB_USER = 'toto'; -const DB_PASSWORD = 'achanger'; +const DB_DATABASE = 'sae_3'; +const DB_USER = 'Perederii'; +const DB_PASSWORD = ''; //const APP_ENV = 'console'; -const DSN = "mysql:host=" . DB_HOST . ";dbname=" . DB_DATABASE; +const DSN = DB_SERVER . ":host=" . DB_HOST . ";dbname=" . DB_DATABASE; diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 72c3031e..fc22b38a 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use Database\AthleteEntity; use Database\AthleteMapper; use Database\EntrainementGateway; use Database\EntrainementMapper; @@ -80,7 +81,7 @@ class AthleteController extends BaseController print("Nom invalide."); } else { try { - $athleteGateway = new AthleteGateway(new Connexion("pgsql:host=localhost;dbname=sae_3", "Perederii", "")); + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $listSearch = $athleteGateway->getAthlete($username); $map = new AthleteMapper(); $athleteEntity = $map->athleteSqlToEntity($listSearch); @@ -154,7 +155,7 @@ class AthleteController extends BaseController public function exercice(): Response { try { - $entrainementGateway = new EntrainementGateway(new Connexion("pgsql:host=localhost;dbname=sae_3", "Perederii", "")); + $entrainementGateway = new EntrainementGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $listSearch = $entrainementGateway->getEntrainements(); $map = new EntrainementMapper(); $entrainementEntity = $map->entrainementSqlToEntity($listSearch); @@ -162,12 +163,10 @@ class AthleteController extends BaseController $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()]; + $training = $map->entrainementEntityToModel($entity); + $listUsers[$i] = ['idTraining' => number_format($training->getId(), 1), 'date' => $training->getDate()->format("D j F Y"), + 'location' => $training->getLocation(), 'description' => $training->getDescription(), + 'feedback' => $training->getFeedback()]; $i++; } @@ -181,7 +180,7 @@ class AthleteController extends BaseController 'mails' => [], 'users' => [], 'infoUser' => [], - 'exos' => [], + 'exos' => $listUsers, 'member' => [] ]); @@ -222,12 +221,16 @@ class AthleteController extends BaseController public function addFriend(string $username, IRequest $req): Response { try { - $athleteGateway = new AthleteGateway(new Connexion("pgsql:host=localhost;dbname=sae_3", "Perederii", "")); + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $map= new AthleteMapper(); $userSearched=$athleteGateway->getAthleteByFirstName($username); - $currentUser=$this->container->get(UserManager::class)->getUserById(1); - if ($userSearched!=null) { - $currentUser->addFriend($userSearched); + $currentUser=$map->athleteEntityToModel(new AthleteEntity($athleteGateway->getAthleteById(1))); + foreach($userSearched as $user) { + $listUser[] = $map->athleteEntityToModel(new AthleteEntity($user)); + } + if ($listUser!=null) { foreach ($userSearched as $user) { + $currentUser->addFriend($user); $users = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()]; } } @@ -305,24 +308,42 @@ class AthleteController extends BaseController #[Route(path: '/friendlist', name: 'friendlist2', methods: ['GET'])] public function friendlist2(): Response { - $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()]; + try { + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $map=new AthleteMapper(); + $friendEntity = $athleteGateway->getListIdFriends(1/*currentUser->getId()*/); + + foreach($friendEntity as $users) { + if ($users['idathlete1']==1/*currentUser->getId()*/){ + $user=(int)$users['idathlete2']; + } else { + $user=(int)$users['idathlete1']; + } + $listUserEntity[] = $map->athleteSqlToEntity($athleteGateway->getAthleteById(1)); + } + foreach ($listUserEntity as $user) { + $friendList[] = ['nom' => $user[0]->getNom(), 'prenom' => $user[0]->getPrenom(), 'img' => 'test', 'username' => 'test']; + } + + $response = $this->render('./page/friend.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => "Doe", + 'role' => "Athlète", + 'friendship' => $friendList, + 'analyzes' => [], + 'mails' => [], + 'users' => $users, + 'infoUser' => [], + 'exos' => [], + 'member' => [], + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); } - return $this->render('./page/friend.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => $list, - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [], - ]); + return $response; } // #[Route(path: '/delete-friend', name: 'delete-friend', methods: ['POST'])] diff --git a/Sources/src/app/controller/SocialController.php b/Sources/src/app/controller/SocialController.php index 506eda77..c4ef8805 100644 --- a/Sources/src/app/controller/SocialController.php +++ b/Sources/src/app/controller/SocialController.php @@ -5,6 +5,11 @@ namespace App\Controller; use App\Container; use App\Router\Request\IRequest; use App\Router\Response\Response; +use Database\AthleteGateway; +use Database\AthleteMapper; +use Database\Connexion; +use Database\NotificationGateway; +use Database\NotificationMapper; use Shared\Attributes\Route; use Twig\Environment; use Data\Core\Preferences; @@ -23,22 +28,43 @@ class SocialController extends BaseController } - #[Route(path: '/mail', name: 'mail', methods: ['GET'])] + #[Route(path: '/notification', name: 'notification', methods: ['GET'])] public function mail(): Response { - return $this->render('./page/mail.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); + try { + $notificationGateway = new NotificationGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $listSearch = $notificationGateway->getNotifications(); + $map = new NotificationMapper(); + $notificationEntity = $map->notificationSqlToEntity($listSearch); + + $listUsers = []; + + foreach ($notificationEntity as $entity) { + $notification = $map->notificationEntityToModel($entity); + $listUsers[] = ['idnotif' => $notification->getId(), 'message' => $notification->getMessage(), + 'date' => $notification->getDate(),'statut' => $notification->getStatut(), 'urgence' => $notification->getUrgence(), + 'idathlete' => $notification->getToUserId()]; + } + + $response = $this->render('./page/notification.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => "Doe", + 'role' => "Athlète", + 'friendship' => [], + 'analyzes' => [], + 'mails' => $listUsers, + 'users' => [], + 'infoUser' => [], + 'exos' => [], + 'member' => [] + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); + } + return $response; } diff --git a/Sources/src/app/views/Templates/base.html.twig b/Sources/src/app/views/Templates/base.html.twig index 5c6177bb..f1911f1d 100755 --- a/Sources/src/app/views/Templates/base.html.twig +++ b/Sources/src/app/views/Templates/base.html.twig @@ -68,7 +68,7 @@ Coaching - + Messagerie diff --git a/Sources/src/app/views/Templates/page/exercice.html.twig b/Sources/src/app/views/Templates/page/exercice.html.twig index 80bb86b9..25e69e4e 100755 --- a/Sources/src/app/views/Templates/page/exercice.html.twig +++ b/Sources/src/app/views/Templates/page/exercice.html.twig @@ -25,18 +25,18 @@ Date - Type - Intensité prévue - Status + Description + Localisation + FeedBack {% for exo in exos %} {{exo.date}} - {{exo.type}} - {{exo.intensite}} - {{exo.status}} + {{exo.description}} + {{exo.location}} + {{exo.feedback}} {% endfor %} diff --git a/Sources/src/app/views/Templates/page/friend.html.twig b/Sources/src/app/views/Templates/page/friend.html.twig index c0c4691b..0b95b7a4 100755 --- a/Sources/src/app/views/Templates/page/friend.html.twig +++ b/Sources/src/app/views/Templates/page/friend.html.twig @@ -26,7 +26,7 @@ {% if friendship is empty %}

Vous n'avez aucun ami.

- {% else %} + {% else %} diff --git a/Sources/src/app/views/Templates/page/mail.html.twig b/Sources/src/app/views/Templates/page/notification.html.twig similarity index 90% rename from Sources/src/app/views/Templates/page/mail.html.twig rename to Sources/src/app/views/Templates/page/notification.html.twig index ac667739..ee8c51c1 100755 --- a/Sources/src/app/views/Templates/page/mail.html.twig +++ b/Sources/src/app/views/Templates/page/notification.html.twig @@ -28,8 +28,8 @@ {% for mail in mails %} - - + + {% endfor %} diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php index da0c4262..9a15d67b 100644 --- a/Sources/src/data/core/database/AthleteGateway.php +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -21,7 +21,8 @@ class AthleteGateway { public function getAthleteById(int $userId): array { $query = "SELECT * FROM Athlete WHERE idAthlete = :id AND isCoach=FALSE"; - $params = [':id' => [$userId, PDO::PARAM_INT]]; + $params = [':id' => $userId]; +// log::dd($params); $res = $this->connection->executeWithErrorHandling($query, $params); return $res; } diff --git a/Sources/src/data/core/database/Connexion.php b/Sources/src/data/core/database/Connexion.php index 0d9e4254..27e88aa9 100644 --- a/Sources/src/data/core/database/Connexion.php +++ b/Sources/src/data/core/database/Connexion.php @@ -20,9 +20,6 @@ class Connexion extends \PDO { public function executeQuery(string $query, array $parameters = []) { $this->stmt = $this->prepare($query); -// foreach ($parameters as $name => $value) { -// $this->stmt->bindValue($name, $value[0], $value[1]); -// } foreach ($parameters as $name => $value) { $dataType = is_numeric($value) ? \PDO::PARAM_INT : \PDO::PARAM_STR; $bindValueResult = $this->stmt->bindValue($name, $value, $dataType); @@ -48,13 +45,24 @@ class Connexion extends \PDO { public function getResults(): array { $results = $this->stmt->fetchAll(\PDO::FETCH_ASSOC); - // Convertissez les colonnes "taille" et "poids" en nombres foreach ($results as &$row) { - $row['taille'] = floatval($row['taille']); - $row['poids'] = floatval($row['poids']); + if($row['identrainement']) { + $row['identrainement'] = floatval(($row['identrainement'])); + } + if($row['latitude']) { + $row['latitude'] = floatval(($row['latitude'])); + } + if($row['longitude']) { + $row['longitude'] = floatval(($row['longitude'])); + } + if($row['taille']) { + $row['taille'] = floatval($row['taille']); + } + if($row['poids']) { + $row['poids'] = floatval($row['poids']); + } } - return $results; } } diff --git a/Sources/src/data/core/database/EntrainementGateway.php b/Sources/src/data/core/database/EntrainementGateway.php index 04032659..b0b5bf3a 100644 --- a/Sources/src/data/core/database/EntrainementGateway.php +++ b/Sources/src/data/core/database/EntrainementGateway.php @@ -2,6 +2,8 @@ namespace Database; +use Shared\Log; + class EntrainementGateway { private Connexion $connection; diff --git a/Sources/src/data/core/database/EntrainementMapper.php b/Sources/src/data/core/database/EntrainementMapper.php index 5da55f0f..8f9f8afc 100644 --- a/Sources/src/data/core/database/EntrainementMapper.php +++ b/Sources/src/data/core/database/EntrainementMapper.php @@ -2,9 +2,11 @@ namespace Database; +use DateTime; use Model\Athlete; use Model\Training; use Model\User; +use Shared\Log; class EntrainementMapper { @@ -13,8 +15,9 @@ class EntrainementMapper foreach ($data as $entrainementData) { $entrainement = new EntrainementEntity(); - if (isset($entrainementData['idEntrainement'])) { - $entrainement->setIdEntrainement($entrainementData['idEntrainement']); + + if (isset($entrainementData['identrainement'])) { + $entrainement->setIdEntrainement($entrainementData['identrainement']); } if (isset($entrainementData['date'])) { @@ -37,8 +40,8 @@ class EntrainementMapper $entrainement->setFeedback($entrainementData['feedback']); } - if (isset($entrainementData['coachId'])) { - $entrainement->setCoachId($entrainementData['coachId']); + if (isset($entrainementData['athleteid'])) { + $entrainement->setCoachId($entrainementData['athleteid']); } $entrainementEntities[] = $entrainement; @@ -48,12 +51,13 @@ class EntrainementMapper } public function entrainementEntityToModel(EntrainementEntity $entrainementEntity): Training { + $date = new DateTime($entrainementEntity->getDate()); return new Training( $entrainementEntity->getIdEntrainement(), - $entrainementEntity->getDate(), - $entrainementEntity->getDescription(), + $date, $entrainementEntity->getLatitude(), $entrainementEntity->getLongitude(), + $entrainementEntity->getDescription(), $entrainementEntity->getFeedback() ); } diff --git a/Sources/src/data/core/database/NotificationEntity.php b/Sources/src/data/core/database/NotificationEntity.php new file mode 100644 index 00000000..02b9ebf0 --- /dev/null +++ b/Sources/src/data/core/database/NotificationEntity.php @@ -0,0 +1,63 @@ +idNotif; + } + public function getMessage() + { + return $this->message; + } + public function getDate() + { + return $this->date; + } + public function getStatut() + { + return $this->statut; + } + public function getUrgence() + { + return $this->urgence; + } + public function getIdAthlete() + { + return $this->idAthlete; + } + public function setIdNotif($idNotif) + { + $this->idNotif = $idNotif; + } + public function setMessage($message) + { + $this->message = $message; + } + public function setDate($date) + { + $this->date = $date; + } + public function setStatut($statut) + { + $this->statut = $statut; + } + public function setUrgence($urgence) + { + $this->urgence = $urgence; + } + public function setIdAthlete($idAthlete) + { + $this->idAthlete = $idAthlete; + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/NotificationGateway.php b/Sources/src/data/core/database/NotificationGateway.php new file mode 100644 index 00000000..19715e38 --- /dev/null +++ b/Sources/src/data/core/database/NotificationGateway.php @@ -0,0 +1,19 @@ +connection = $connection; + } + + public function getNotifications(): array + { + $query = "SELECT * FROM Notification"; + $res = $this->connection->executeWithErrorHandling($query); + return $res; + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/NotificationMapper.php b/Sources/src/data/core/database/NotificationMapper.php new file mode 100644 index 00000000..49b56160 --- /dev/null +++ b/Sources/src/data/core/database/NotificationMapper.php @@ -0,0 +1,74 @@ +setIdNotif($notificationData['idnotif']); + } + + if (isset($notificationData['message'])) { + $notification->setMessage($notificationData['message']); + } + + if (isset($notificationData['date'])) { + $notification->setDate($notificationData['date']); + } + + if (isset($notificationData['statut'])) { + $notification->setStatut($notificationData['statut']); + } + + if (isset($notificationData['urgence'])) { + $notification->setUrgence($notificationData['urgence']); + } + + if (isset($notificationData['athleteid'])) { + $notification->setIdAthlete($notificationData['athleteid']); + } + + $notificationEntities[] = $notification; + } + + return $notificationEntities; + } + + public function notificationEntityToModel(NotificationEntity $notificationEntity): Notification + { + $date = new DateTime($notificationEntity->getDate()); + return new Notification( + $notificationEntity->getIdNotif(), + $notificationEntity->getMessage(), + $date, + $notificationEntity->getStatut(), + $notificationEntity->getUrgence(), + $notificationEntity->getIdAthlete() + ); + } + + public function notificationToEntity(Notification $notification): NotificationEntity + { + $notif = new NotificationEntity(); + $notif->setIdNotif($notification->getId()); + $notif->setMessage($notification->getMessage()); + $notif->setDate($notification->getDate()); + $notif->setStatut($notification->getStatut()); + $notif->setUrgence($notification->getUrgence()); + $notif->setIdAthlete($notification->getToUserId()); + + return $notif; + } +} \ No newline at end of file diff --git a/Sources/src/data/model/Notification.php b/Sources/src/data/model/Notification.php index 7472632a..a3c66268 100644 --- a/Sources/src/data/model/Notification.php +++ b/Sources/src/data/model/Notification.php @@ -2,8 +2,41 @@ namespace Model; +use DateTime; + class Notification { + private int $idNotif; + private string $message; + private \DateTime $date; + private string $statut; + private string $urgence; + private int $toUserId; + /** + * @param string $type + * @param string $message + */ + public function __construct( + int $idNotif, + string $message, + DateTime $date, + string $statut, + string $urgence, + int $toUserId + ) + { + $this->idNotif = $idNotif; + $this->message = $message; + $this->date = $date; + $this->statut = $statut; + $this->urgence = $urgence; + $this->toUserId =$toUserId; + } + + public function getId(){ return $this->idNotif;} + public function getDate(){ return $this->date;} + public function getStatut(){ return $this->statut;} + public function getUrgence(){ return $this->urgence;} /** * @return string */ @@ -36,10 +69,6 @@ class Notification $this->message = $message; } - private string $type; - private string $message; - private int $toUserId; - /** * @return int */ @@ -55,16 +84,6 @@ class Notification { $this->toUserId = $toUserId; } - /** - * @param string $type - * @param string $message - */ - public function __construct(int $toUserId,string $type, string $message) - { - $this->type = $type; - $this->toUserId =$toUserId; - $this->message = $message; - } public function __toString(): string { return var_export($this, true); diff --git a/Sources/src/data/model/Training.php b/Sources/src/data/model/Training.php index 220b1b97..dc2fbd3e 100644 --- a/Sources/src/data/model/Training.php +++ b/Sources/src/data/model/Training.php @@ -33,7 +33,7 @@ class Training return $this->date; } public function getLocation(): String { - return $this->longitude . $this->latitude; + return $this->longitude . ", " . $this->latitude; } public function getLatitude(): float { return $this->latitude;
{{mail.nom}} {{mail.prenom}}{{mail.urgence}} {{mail.statut}} {{mail.message}}