From bc0b4ee2d6c4a733d013487cdc7087b4f4889926 Mon Sep 17 00:00:00 2001 From: palevrault Date: Fri, 29 Dec 2023 11:47:33 +0100 Subject: [PATCH] Affichage ami --- Sources/config/config.php | 6 ++--- .../src/app/controller/AthleteController.php | 25 +++++++++++-------- .../src/data/core/database/AthleteGateway.php | 15 ++++++++--- .../src/data/core/database/AthleteMapper.php | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Sources/config/config.php b/Sources/config/config.php index 4d0a0f4d..6e4dfc13 100755 --- a/Sources/config/config.php +++ b/Sources/config/config.php @@ -12,10 +12,10 @@ $dotenv->safeLoad(); // const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger'; define("APP_ENV", 'development'); -const DB_SERVER = 'pgsql'; +const DB_SERVER = 'mysql'; const DB_HOST = 'localhost'; -const DB_DATABASE = 'sae_3'; -const DB_USER = 'Perederii'; +const DB_DATABASE = 'new'; +const DB_USER = 'root'; const DB_PASSWORD = ''; //const APP_ENV = 'console'; diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 0a61b7a6..0a6c7614 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -421,20 +421,25 @@ class AthleteController extends BaseController try { $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $map=new AthleteMapper(); - $friendEntity = $athleteGateway->getListIdFriends(1/*$currentUser->getId()*/); - - $friendList = []; - $listUserEntity = []; - foreach($friendEntity as $users) { - if ($users['idathlete1']==1/*$currentUser->getId()*/){ - $user=(int)$users['idathlete2']; + $friendEntity = $athleteGateway->getListIdFriends(3/*$currentUser->getId()*/); + foreach($friendEntity as $friendship){ + if($friendship['idAthlete1']==3/*$currentUser->getId()*/){ + $listFriend[]=$friendship['idAthlete2']; } else { - $user=(int)$users['idathlete1']; + $listFriend[]=$friendship['idAthlete1']; } - $listUserEntity[] = $map->athleteSqlToEntity($athleteGateway->getAthleteById(1)); } + foreach($listFriend as $friend){ + $friends[]=$athleteGateway->getById($friend); + } + foreach($friends as $friend){ + $friendlist[]=$friend[0]; + } + + $listUserEntity = $map->athleteSqlToEntity($friendlist); + foreach ($listUserEntity as $user) { - $friendList[] = ['nom' => $user[0]->getNom(), 'prenom' => $user[0]->getPrenom(), 'img' => 'test', 'username' => 'test']; + $friendList[] = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()]; } $response = $this->render('./page/friend.html.twig',[ diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php index a6677c89..e94155d0 100644 --- a/Sources/src/data/core/database/AthleteGateway.php +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -22,7 +22,6 @@ class AthleteGateway { { $query = "SELECT * FROM Athlete WHERE idAthlete = :id AND isCoach=FALSE"; $params = [':id' => $userId]; -// log::dd($params); $res = $this->connection->executeWithErrorHandling($query, $params); return $res; } @@ -90,10 +89,10 @@ class AthleteGateway { public function getListActivity(int $idAthlete): array { $query = "SELECT count(ac.idActivite) AS nbActivite, EXTRACT(MONTH FROM ac.date) AS mois - FROM Athlete at, Activite ac - WHERE at.idAthlete = :idAthlete + FROM Athlete ath, Activite ac + WHERE ath.idAthlete = :idAthlete AND ac.date > CURRENT_DATE - INTERVAL '1 YEAR' - AND ac.athleteId = at.idAthlete + AND ac.athleteId = ath.idAthlete GROUP BY mois"; $params = [ @@ -158,6 +157,14 @@ class AthleteGateway { return $this->connection->executeWithErrorHandling($query, $params); } + public function getById(int $userId): array + { + $query = "SELECT * FROM Athlete WHERE idAthlete = :id"; + $params = [':id' => $userId]; + $res = $this->connection->executeWithErrorHandling($query, $params); + return $res; + } + } diff --git a/Sources/src/data/core/database/AthleteMapper.php b/Sources/src/data/core/database/AthleteMapper.php index e9572ca4..4b978992 100644 --- a/Sources/src/data/core/database/AthleteMapper.php +++ b/Sources/src/data/core/database/AthleteMapper.php @@ -57,7 +57,7 @@ class AthleteMapper { if (isset($athleteData['isCoach'])) { $athlete->setIsCoach($athleteData['isCoach']); } - + $athleteEntities[] = $athlete; }