From 2efb321f6af180a1d9fd5d8c0ab5e40b768c6e55 Mon Sep 17 00:00:00 2001
From: anperederi
Date: Tue, 9 Jan 2024 11:12:04 +0100
Subject: [PATCH] update some parts with database
---
Sources/config/config.php | 2 +-
.../src/app/controller/AthleteController.php | 4 +-
Sources/src/app/controller/AuthController.php | 23 +++-
Sources/src/app/controller/UserController.php | 101 +++++++++++++++---
.../app/router/middleware/AuthMiddleware.php | 2 +-
.../src/app/views/Templates/base.html.twig | 2 +-
.../app/views/Templates/page/home.html.twig | 9 +-
.../app/views/Templates/page/import.html.twig | 2 +-
.../src/app/views/Templates/page/index.html | 2 +-
.../src/data/core/database/ActivityEntity.php | 8 +-
.../src/data/core/database/ActivityMapper.php | 33 +++---
.../src/data/core/database/AthleteGateway.php | 34 ++++--
.../src/data/core/database/AthleteMapper.php | 1 -
.../core/database/NotificationGateway.php | 4 +-
.../src/data/core/database/data/athlete.sql | 12 +--
.../core/database/data/frequenceCardiaque.sql | 43 ++++----
.../data/core/database/data/friendship.sql | 3 -
.../src/data/core/database/data/tables.sql | 20 ++--
Sources/src/data/core/network/AuthService.php | 22 +++-
Sources/src/data/model/Activity.php | 3 +-
Sources/src/data/model/Notification.php | 9 +-
Sources/src/data/model/Role.php | 1 -
Sources/src/data/model/Training.php | 9 +-
Sources/src/data/model/User.php | 25 +++--
.../data/model/manager/ActivityManager.php | 2 +-
.../repository/NotificationRepository.php | 10 +-
.../data/stub/repository/UserRepository.php | 10 +-
27 files changed, 264 insertions(+), 132 deletions(-)
diff --git a/Sources/config/config.php b/Sources/config/config.php
index 8d5b276e..dab98bf1 100755
--- a/Sources/config/config.php
+++ b/Sources/config/config.php
@@ -12,7 +12,7 @@ $dotenv->safeLoad();
// const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger';
define("APP_ENV", getenv('APP_ENV'));
-const DB_SERVER = 'pgsql';
+const DB_SERVER = 'mysql';
const DB_HOST = 'localhost';
const DB_DATABASE = 'sae_3';
const DB_USER = 'Perederii';
diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php
index 6513b409..c5b1d9ee 100644
--- a/Sources/src/app/controller/AthleteController.php
+++ b/Sources/src/app/controller/AthleteController.php
@@ -302,8 +302,8 @@ class AthleteController extends BaseController
$athleteEntity = $map->athleteSqlToEntity($userSearched);
$users=[];
foreach ($athleteEntity as $user) {
- $this->userMgr->getCurrentUser()->addFriend($user);
- $currentUser->addFriend($user);
+// $this->userMgr->getCurrentUser()->addFriend($user);
+// $currentUser->addFriend($user);
$users = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()];
}
$notif = new NotificationGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
diff --git a/Sources/src/app/controller/AuthController.php b/Sources/src/app/controller/AuthController.php
index 5c0006ba..a62fb2a3 100644
--- a/Sources/src/app/controller/AuthController.php
+++ b/Sources/src/app/controller/AuthController.php
@@ -9,6 +9,9 @@ use App\Router\Response\Response;
use App\Router\Response\IResponse;
use App\Router\Session;
+use Database\AthleteGateway;
+use Database\AthleteMapper;
+use Database\Connexion;
use Manager\UserManager;
use Shared\Attributes\Route;
use Shared\Validation;
@@ -33,7 +36,21 @@ class AuthController extends BaseController
$log=$email; // should check email with verrify email
$mdp=Validation::clean_string($password);
if($this->userMgr->login($log,$mdp)){
- return new RedirectResponse('/home');
+ $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
+ $user = $athleteGateway->getUserByEmail($email);
+ $map = new AthleteMapper();
+ $userEntity = $map->athleteSqlToEntity($user);
+
+ $users = ['username' => $userEntity[0]->getUsername(), 'nom' => $userEntity[0]->getNom(),
+ 'prenom' => $userEntity[0]->getPrenom(),'email' => $userEntity[0]->getEmail(), 'sexe' => $userEntity[0]->getSexe(),
+ 'taille' => $userEntity[0]->getTaille(), 'poids' => $userEntity[0]->getPoids(), 'motdepasse' => $userEntity[0]->getMotDePasse(),
+ 'datenaissance' => $userEntity[0]->getDateNaissance(), 'iscoach' => $userEntity[0]->getIsCoach(), 'img' => 'test'];
+ return $this->render('./page/home.html.twig', [
+ 'css' => $this->preference->getCookie(),
+ 'pp' => $users['img'],
+ 'user' => $users['username'],
+ 'role' => $users['iscoach']
+ ]);
}
else{
$error [] = "Erreur de connexion. Essayez encore";
@@ -59,14 +76,14 @@ class AuthController extends BaseController
public function login2(IRequest $request): IResponse {
return $this->render('./page/login.html.twig',[
- 'css' => $this->preference->getCookie(),
+ 'css' => $this->preference->getCookie()
]);
}
#[Route('/register', name: 'register2' , methods:['GET'])]
public function register2(IRequest $request): IResponse{
return $this->render('./page/register.html.twig',[
- 'css' => $this->preference->getCookie(),
+ 'css' => $this->preference->getCookie()
]);
}
diff --git a/Sources/src/app/controller/UserController.php b/Sources/src/app/controller/UserController.php
index e97dd508..dc0c5536 100644
--- a/Sources/src/app/controller/UserController.php
+++ b/Sources/src/app/controller/UserController.php
@@ -9,6 +9,7 @@ use App\Router\Response\Response;
use App\Router\Response\IResponse;
use App\Router\Session;
+use DateInterval;
use DateTime;
use Manager\UserManager;
use Shared\Attributes\Route;
@@ -53,23 +54,97 @@ class UserController extends BaseController
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$activity = $athleteGateway->getListActivity('1');//$currentUser->getId()
+// $charts = [];
+// $i = 0;
+// while ($i <= 12) {
+// if ($activity[$i]['mois'] == null) {
+// $activity[$i]['mois'] = $i;
+// $activity[$i]['nbactivite'] = 0;
+// } elseif (($indice = intval($activity[$i]['mois'])) != $i) {
+// $temp = $activity[$i]; // Stocker temporairement les données actuelles
+// $activity[$i]['mois'] = $i;
+// $activity[$i]['nbactivite'] = 0;
+// $activity[$indice]['mois'] = $indice;
+// $activity[$indice]['nbactivite'] = $temp['nbactivite']; // Restaurer les données
+// }
+// $charts[] = ['act' => $activity[$i]['nbactivite'], 'mois' => $activity[$i]['mois']];
+// $i++;
+// }
+
$charts = [];
- $i = 0;
- while ($i <= 12) {
- if ($activity[$i]['mois'] == null) {
- $activity[$i]['mois'] = $i;
- $activity[$i]['nbactivite'] = 0;
- } elseif (($indice = intval($activity[$i]['mois'])) != $i) {
- $temp = $activity[$i]; // Stocker temporairement les données actuelles
- $activity[$i]['mois'] = $i;
- $activity[$i]['nbactivite'] = 0;
- $activity[$indice]['mois'] = $indice;
- $activity[$indice]['nbactivite'] = $temp['nbactivite']; // Restaurer les données
+ $monthNames = [
+ 'Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin',
+ 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre'
+ ];
+
+ $currentDate = new DateTime();
+ $interval = new DateInterval('P1M'); // Période d'un mois
+
+ for ($i = 0; $i < 12; $i++) {
+ $currentMonth = $currentDate->format('n'); // Format numérique du mois (1 à 12)
+ $currentMonthName = $monthNames[$currentMonth - 1]; // Mois correspondant dans le tableau
+
+ // Recherche de l'indice du mois dans le tableau $activity
+ $activityIndex = null;
+ for ($j = 0; $j < count($activity); $j++) {
+ if (!empty($activity[$j]['mois']) && $activity[$j]['mois'] == $currentMonth) {
+ $activityIndex = $j;
+ break;
+ }
+ }
+
+ // Récupération du nombre d'activités et réinitialisation à 0
+ $nbActivity = isset($activityIndex) ? $activity[$activityIndex]['nbactivite'] : 0;
+ if (isset($activityIndex)) {
+ $activity[$activityIndex]['nbactivite'] = 0;
}
- $charts[] = ['act' => $activity[$i]['nbactivite'], 'mois' => $activity[$i]['mois']];
- $i++;
+// Log::dd($currentMonth);
+ $charts[] = ['act' => $nbActivity, 'mois' => $currentMonth];
+ $currentDate->sub($interval);
}
+// Inverser l'ordre des éléments si nécessaire
+ $charts = array_reverse($charts);
+
+// Log::dd($charts);
+
+//
+// $charts = [];
+// $monthNames = [
+// 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin',
+// 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'
+// ];
+//
+// $currentDate = new DateTime();
+// $interval = new DateInterval('P1M'); // Période d'un mois
+//
+// for ($i = 0; $i < 12; $i++) {
+//// $currentDate; // Soustraire un mois
+//// Log::dd($currentDate);
+// $currentMonth = $currentDate->format('n'); // Format numérique du mois (1 à 12)
+//// Log::dd($currentMonth);
+// $currentMonthName = $monthNames[$currentMonth - 1]; // Mois correspondant dans le tableau
+// for($j = 12; $j > 0; $j--) {
+// if(!empty($activity[$j]['mois']) || $activity[$j]['mois'] == $currentMonth) {
+// $nbAct = $activity[$j]['nbactivite'];
+// $activity[$j]['nbactivite'] = 0;
+//// Log::dd($activity);
+// break;
+// }
+// }
+//
+// $nbActivity = isset($nbAct) ? $nbAct : 0;
+//// Log::dd($nbActivity);
+//
+// $charts[] = ['act' => $nbActivity, 'mois' => $currentMonthName];
+// $currentDate->sub($interval);
+// }
+// Log::dd($charts);
+
+// Inverser l'ordre des éléments si nécessaire
+// $charts = array_reverse($charts);
+//
+// Log::dd($charts);
return $this->render('./page/home.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
diff --git a/Sources/src/app/router/middleware/AuthMiddleware.php b/Sources/src/app/router/middleware/AuthMiddleware.php
index a2b95c29..e95f389d 100644
--- a/Sources/src/app/router/middleware/AuthMiddleware.php
+++ b/Sources/src/app/router/middleware/AuthMiddleware.php
@@ -13,7 +13,7 @@ class AuthMiddleware extends Middleware {
$this->auth = $auth;
}
public function handle(IRequest $request, callable $next) {
- $excludedUrls = ['/login', '/register','/forgetPassword'];
+ $excludedUrls = ['/login', '/register','/forgetPassword', '/'];
if ($this->auth->getCurrentUser() === null && !in_array($request->getRequestUri(), $excludedUrls)) {
$resp = new RedirectResponse("/login");
diff --git a/Sources/src/app/views/Templates/base.html.twig b/Sources/src/app/views/Templates/base.html.twig
index d187eabb..aed11cb5 100755
--- a/Sources/src/app/views/Templates/base.html.twig
+++ b/Sources/src/app/views/Templates/base.html.twig
@@ -60,7 +60,7 @@
- Analyses
+ Activités
diff --git a/Sources/src/app/views/Templates/page/home.html.twig b/Sources/src/app/views/Templates/page/home.html.twig
index e7df9548..3143ca51 100755
--- a/Sources/src/app/views/Templates/page/home.html.twig
+++ b/Sources/src/app/views/Templates/page/home.html.twig
@@ -31,18 +31,15 @@
const ctx = document.getElementById('myChart');
const labels = [
{% for chart in charts %}
- {{ chart.mois }},
+ {{ chart.mois }},
{% endfor %}
];
const data = [
{% for chart in charts %}
- {{ chart.act }},
+ {{ chart.act }},
{% endfor %}
];
- console.log(labels); // Vérifiez les valeurs dans la console
- console.log(data); // Vérifiez les valeurs dans la console
-
new Chart(ctx, {
type: 'line',
data: {
@@ -59,7 +56,7 @@
options: {
scales: {
x: {
- type: 'linear', // Utiliser une échelle linéaire pour les mois
+ // type: 'linear', // Utiliser une échelle linéaire pour les mois
position: 'bottom'
},
y: {
diff --git a/Sources/src/app/views/Templates/page/import.html.twig b/Sources/src/app/views/Templates/page/import.html.twig
index 1410c69d..4598ceb4 100644
--- a/Sources/src/app/views/Templates/page/import.html.twig
+++ b/Sources/src/app/views/Templates/page/import.html.twig
@@ -44,7 +44,7 @@
select a file
from your computer
-
+
diff --git a/Sources/src/app/views/Templates/page/index.html b/Sources/src/app/views/Templates/page/index.html
index 404946e8..081c934c 100644
--- a/Sources/src/app/views/Templates/page/index.html
+++ b/Sources/src/app/views/Templates/page/index.html
@@ -205,7 +205,7 @@
-
Application bientôt disponible !
+ Application mobile bientôt disponible !