From d092f7c318b2609cee4fd67442d94ae80e4877af Mon Sep 17 00:00:00 2001 From: palevrault Date: Thu, 21 Dec 2023 11:12:28 +0100 Subject: [PATCH 1/3] Ajout de notif dans la BD --- Sources/src/app/controller/AthleteController.php | 1 - Sources/src/data/core/database/NotificationGateway.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 1f8b0bf6..0abf76a2 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -93,7 +93,6 @@ class AthleteController extends BaseController $listSearch = $athleteGateway->getAthlete($username); $map = new AthleteMapper(); $athleteEntity = $map->athleteSqlToEntity($listSearch); - $listUsers = []; foreach ($athleteEntity as $entity) { $user = $map->athleteEntityToModel($entity); diff --git a/Sources/src/data/core/database/NotificationGateway.php b/Sources/src/data/core/database/NotificationGateway.php index 8ee36c5b..c1050ab9 100644 --- a/Sources/src/data/core/database/NotificationGateway.php +++ b/Sources/src/data/core/database/NotificationGateway.php @@ -20,8 +20,8 @@ class NotificationGateway } public function addNotification(NotificationEntity $notif){ - $query = "INSERT INTO Notification (idnotif, message, date, statut, urgence, athleteid) VALUES (:idNotif, :message, :date, :statut, :urgence, :idAthlete)"; - $params = [':idNotif'=>$notif->getIdNotif(), ':message'=>$notif->getMessage(), ':date'=>$notif->getDate(), ':statut'=>$notif->getStatut(), ':urgence'=>$notif->getUrgence(), ':idAthlete'=>$notif->getIdAthlete()]; + $query = "INSERT INTO Notification (message, date, statut, urgence, athleteid) VALUES (:message, :date, :statut, :urgence, :idAthlete)"; + $params = [':message'=>$notif->getMessage(), ':date'=>$notif->getDate(), ':statut'=>$notif->getStatut(), ':urgence'=>$notif->getUrgence(), ':idAthlete'=>$notif->getIdAthlete()]; return $this->connection->executeWithErrorHandling($query, $params); } } \ No newline at end of file From 07b223c6330fe025d5f2a38a81b5c0da9f85c9d5 Mon Sep 17 00:00:00 2001 From: palevrault Date: Thu, 21 Dec 2023 12:16:45 +0100 Subject: [PATCH 2/3] correction de trucs --- Sources/src/app/controller/AthleteController.php | 6 +++++- Sources/src/data/core/database/AthleteGateway.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 0abf76a2..6f37a675 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -90,7 +90,11 @@ class AthleteController extends BaseController } else { try { $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); - $listSearch = $athleteGateway->getAthlete($username); + if($username==null){ + $listSearch=$athleteGateway->getAthlete(); + } else { + $listSearch = $athleteGateway->getAthleteByName($username); + } $map = new AthleteMapper(); $athleteEntity = $map->athleteSqlToEntity($listSearch); $listUsers = []; diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php index 22a78fbd..323be996 100644 --- a/Sources/src/data/core/database/AthleteGateway.php +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -30,7 +30,7 @@ class AthleteGateway { public function getAthleteByName(string $name): array { $query = "SELECT * FROM Athlete WHERE nom = :name AND isCoach=FALSE"; - $params = [':name' => [$name, PDO::PARAM_STR]]; + $params = [':name' => $name]; return $this->connection->executeWithErrorHandling($query, $params); } From 23ccabbb71fa8004b241ccf6b105372baaf46170 Mon Sep 17 00:00:00 2001 From: palevrault Date: Thu, 21 Dec 2023 21:31:53 +0100 Subject: [PATCH 3/3] Test ajout graphique --- Sources/config/config.php | 8 +++---- Sources/src/app/controller/UserController.php | 9 ++++++++ .../app/views/Templates/page/home.html.twig | 21 ++++++++++++++++++- .../src/data/core/database/AthleteGateway.php | 11 ++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Sources/config/config.php b/Sources/config/config.php index 4d0a0f4d..f28606cb 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_HOST = 'localhost'; -const DB_DATABASE = 'sae_3'; -const DB_USER = 'Perederii'; +const DB_SERVER = 'mysql'; +const DB_HOST = 'localhost:3306'; +const DB_DATABASE = 'new'; +const DB_USER = 'root'; const DB_PASSWORD = ''; //const APP_ENV = 'console'; diff --git a/Sources/src/app/controller/UserController.php b/Sources/src/app/controller/UserController.php index 6b3091af..6ce05f94 100644 --- a/Sources/src/app/controller/UserController.php +++ b/Sources/src/app/controller/UserController.php @@ -9,6 +9,8 @@ use Shared\Attributes\Route; use Twig\Environment; use Data\Core\Preferences; use Shared\Log; +use Database\Athletegateway; +use Database\Connexion; class UserController extends BaseController { @@ -43,6 +45,12 @@ class UserController extends BaseController #[Route(path: '/home', name: 'home', methods: ['GET'])] public function home(): Response { + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $activity = $athleteGateway->getListActivity('1');//$currentUser->getId() + foreach($activity as $act){ + $chart["act"] = $act["nbActivite"]; + $chart["mois"] = date('M', mktime(0, 0, 0, $act["mois"], 10)); + } return $this->render('./page/home.html.twig',[ 'css' => $this->preference->getCookie(), 'pp' => "test2", @@ -50,6 +58,7 @@ class UserController extends BaseController 'role' => "Athlète", 'friendship' => [], 'analyzes' => [], + 'chart' => $chart, 'mails' => [], 'users' => [], 'infoUser' => [], diff --git a/Sources/src/app/views/Templates/page/home.html.twig b/Sources/src/app/views/Templates/page/home.html.twig index 6ade985b..f75c376c 100755 --- a/Sources/src/app/views/Templates/page/home.html.twig +++ b/Sources/src/app/views/Templates/page/home.html.twig @@ -22,7 +22,26 @@ Stastiques globales
- {# #} + + + +
diff --git a/Sources/src/data/core/database/AthleteGateway.php b/Sources/src/data/core/database/AthleteGateway.php index 323be996..b73e9380 100644 --- a/Sources/src/data/core/database/AthleteGateway.php +++ b/Sources/src/data/core/database/AthleteGateway.php @@ -86,6 +86,17 @@ class AthleteGateway { return $this->connection->executeWithErrorHandling($query, $params); } + + public function getListActivity(int $idAthlete): array + { + $query = "SELECT count(ac.idActivite) AS nbActivite, MONTH(ac.date) AS mois FROM Athlete at, Activite ac WHERE at.idAthlete = :idAthlete AND ac.date > DATE_SUB(date, INTERVAL 1 YEAR) AND ac.athleteId=at.idAthlete GROUP BY mois"; + + $params = [ + ':idAthlete' => $idAthlete, + ]; + + return $this->connection->executeWithErrorHandling($query, $params); + } public function addAthlete(AthleteEntity $athlete): array {