From d39694036aff7f647f734decf59c28bbad03cb18 Mon Sep 17 00:00:00 2001 From: palevrault Date: Thu, 11 Jan 2024 09:21:52 +0100 Subject: [PATCH] modif ajout d'amis --- .../src/app/controller/AthleteController.php | 15 +++++++-------- Sources/src/app/controller/UserController.php | 2 ++ .../views/Templates/page/addfriend.html.twig | 7 +++---- .../src/data/core/database/ActivityEntity.php | 2 +- .../src/data/core/database/ActivityMapper.php | 2 +- .../src/data/core/database/AthleteGateway.php | 17 ++++++++++++----- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 0a6c7614..24337566 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -201,8 +201,8 @@ class AthleteController extends BaseController $listActivity = []; foreach ($activityGateway as $entity) { $activity = $map->activityEntityToModel($entity); - $listActivity[] = ['idactivity' => number_format($activity->getIdActivity()), '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"), + $listActivity[] = ['idactivite' => number_format($activity->getIdActivity()), 'type' => $activity->getType(), + 'date' => $activity->getDate()->format("D j F Y"), 'heurededebut' => $activity->getHeureDebut()->format("H\h i"), 'heuredefin' => $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()]; @@ -293,7 +293,7 @@ class AthleteController extends BaseController } #[Route(path: '/add-friend', name: 'add-friend', methods: ['POST'])] - public function addFriend(string $username, IRequest $req): Response + public function addFriend(string $id, IRequest $req): Response { try {/* $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); @@ -326,7 +326,7 @@ class AthleteController extends BaseController $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $map = new AthleteMapper(); - $userSearched = $athleteGateway->getAthleteByFirstName("Bryan"); + $userSearched = $athleteGateway->getAthleteById((int)$id); $athleteEntity = $map->athleteSqlToEntity($userSearched); // $user = $athleteGateway->getAthleteById(1); // $currentUser = $map->athleteToEntity($user); @@ -334,18 +334,17 @@ class AthleteController extends BaseController // foreach($userSearched as $user) { // $listUser[] = $map->athleteToEntity($user); // } - $users=[]; foreach ($athleteEntity as $user) { // $this->userMgr->getCurrentUser()->addFriend($user); // $currentUser->addFriend($user); - $users = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()]; + $users[] = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername(), 'idathlete' => $user->getIdAthlete()]; } $notif = new NotificationGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $mapper = new NotificationMapper(); $date = new DateTime(); // DateTime::createFromFormat('d/m/Y', date('d/m/Y')); // Log::dd($date); - $myNotif = new Notification(20, "Demande d'ami de la part de " . $users['nom'], $date, true, 7, 1); + $myNotif = new Notification(20,"Demande d'ami de la part de ".$users['username'], $date, true, 7, 1); $notif->addNotification($mapper->notificationToEntity($myNotif)); return $this->render('./page/addfriend.html.twig',[ 'css' => $this->preference->getCookie(), @@ -359,7 +358,7 @@ class AthleteController extends BaseController 'infoUser' => [], 'exos' => [], 'member' => [], - 'responce' => "Notification d'ajout envoyée à $username" + 'responce' => "Notification d'ajout envoyée à ".$users[0]['username'] ]); } catch (\Throwable $th) { throw $th; diff --git a/Sources/src/app/controller/UserController.php b/Sources/src/app/controller/UserController.php index ca403f69..c6301d5e 100644 --- a/Sources/src/app/controller/UserController.php +++ b/Sources/src/app/controller/UserController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Container; use App\Router\Request\IRequest; use App\Router\Response\Response; +use Database\ActivityMapper; use Shared\Attributes\Route; use Twig\Environment; use Data\Core\Preferences; @@ -49,6 +50,7 @@ class UserController extends BaseController $activity = $athleteGateway->getListActivity('1');//$currentUser->getId() // Log::dd($activity); $chart = []; + // PROBLEME AVEC LE GRAPHIQUE Soucis avec le graphique : Undefined array key "nbactivite" ligne 57 foreach($activity as $act){ $chart[] = ['act' => $act['nbactivite'], 'mois' => date('m', $act['mois'])]; } diff --git a/Sources/src/app/views/Templates/page/addfriend.html.twig b/Sources/src/app/views/Templates/page/addfriend.html.twig index 507101a9..edd2fb1d 100644 --- a/Sources/src/app/views/Templates/page/addfriend.html.twig +++ b/Sources/src/app/views/Templates/page/addfriend.html.twig @@ -43,10 +43,9 @@ {{utili.nom}} {{utili.prenom}} - -
- + + +
diff --git a/Sources/src/data/core/database/ActivityEntity.php b/Sources/src/data/core/database/ActivityEntity.php index 7f14956e..be31539a 100644 --- a/Sources/src/data/core/database/ActivityEntity.php +++ b/Sources/src/data/core/database/ActivityEntity.php @@ -18,7 +18,7 @@ class ActivityEntity { private $temperatureMoyenne; // Getters - public function getIdActivity() { + public function getIdActivity() :int { return $this->idActivity; } diff --git a/Sources/src/data/core/database/ActivityMapper.php b/Sources/src/data/core/database/ActivityMapper.php index 296c03c8..adad8141 100644 --- a/Sources/src/data/core/database/ActivityMapper.php +++ b/Sources/src/data/core/database/ActivityMapper.php @@ -73,7 +73,7 @@ class ActivityMapper { /** * @throws \Exception */ - public function ActivityEntityToModel(ActivityEntity $activiteEntity):Activity { + public function activityEntityToModel(ActivityEntity $activiteEntity):Activity { $date = new DateTime($activiteEntity->getDate()); $heureDebut = new \DateTime($activiteEntity->getHeureDebut()); $heureFin = new \DateTime($activiteEntity->getHeureFin()); diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php index e94155d0..2fd651ba 100644 --- a/Sources/src/data/core/database/AthleteGateway.php +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -88,12 +88,19 @@ class AthleteGateway { public function getListActivity(int $idAthlete): array { - $query = "SELECT count(ac.idActivite) AS nbActivite, EXTRACT(MONTH FROM ac.date) AS mois - FROM Athlete ath, Activite ac - WHERE ath.idAthlete = :idAthlete + /*$query = "SELECT count(ac.idActivite) AS nbActivite, EXTRACT(MONTH FROM ac.date) AS mois + FROM Athlete at, Activite ac + WHERE at.idAthlete = :idAthlete AND ac.date > CURRENT_DATE - INTERVAL '1 YEAR' - AND ac.athleteId = ath.idAthlete - GROUP BY mois"; + AND ac.athleteId = at.idAthlete + GROUP BY mois";*/ + + $query = "SELECT COUNT(ac.idActivite) AS nbActivite, EXTRACT(MONTH FROM ac.date) AS mois + FROM Athlete at + JOIN Activite ac ON ac.athleteId = at.idAthlete + WHERE at.idAthlete = :idAthlete + AND ac.date > CURRENT_DATE - INTERVAL 1 YEAR + GROUP BY mois"; $params = [ ':idAthlete' => $idAthlete,