diff --git a/Sources/src/app/AppCreator.php b/Sources/src/app/AppCreator.php
index d2ac0de6..56e3b2c2 100644
--- a/Sources/src/app/AppCreator.php
+++ b/Sources/src/app/AppCreator.php
@@ -24,6 +24,13 @@ class AppCreator
return $this;
}
+ public function registerSingleton(string $serviceId, $service): self
+ {
+ $this->container->set($serviceId, $service, Container::SINGLETON);
+ $this->services[] = $serviceId;
+ return $this;
+ }
+
/**
* Create an instance or perform actions based on the current application environment.
*
@@ -71,7 +78,7 @@ class AppCreator
if ($reflectionClass->isSubclassOf(BaseController::class)) {
// Register in DI container
$this->container->set($fullClassName, function () use ($fullClassName) {
- $controllerInstance = new $fullClassName();
+ $controllerInstance = $this->container->resolve($fullClassName);
$controllerInstance->setContainer($this->container);
return $controllerInstance;
});
@@ -81,7 +88,6 @@ class AppCreator
return $this;
}
-
public function getServiceRegistered(): array
{
return $this->services;
diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php
index fc22b38a..1f8b0bf6 100644
--- a/Sources/src/app/controller/AthleteController.php
+++ b/Sources/src/app/controller/AthleteController.php
@@ -2,10 +2,17 @@
namespace App\Controller;
+use Database\ActivityGateway;
+use Database\ActivityMapper;
use Database\AthleteEntity;
use Database\AthleteMapper;
use Database\EntrainementGateway;
use Database\EntrainementMapper;
+use Database\NotificationEntity;
+use Database\NotificationGateway;
+use Database\NotificationMapper;
+use DateTime;
+use Model\Notification;
use Shared\Validation;
use App\Container;
use App\Router\Request\IRequest;
@@ -23,11 +30,12 @@ class AthleteController extends BaseController
private Environment $twig;
protected Preferences $preference;
+// private UserManager $userMgr;
public function __construct()
{
- //session_start();
$this->preference = new Preferences();
+// $this->userMgr = $manager;
}
// #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])]
@@ -87,21 +95,19 @@ class AthleteController extends BaseController
$athleteEntity = $map->athleteSqlToEntity($listSearch);
$listUsers = [];
- $i = 0;
foreach ($athleteEntity as $entity) {
$user = $map->athleteEntityToModel($entity);
- $listUsers[$i] = ['idathlete' => number_format($user->getId(), 1), 'nom' => $user->getNom(),
+ $listUsers[] = ['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()];
- $i++;
}
$response = $this->render('./page/addfriend.html.twig',[
'css' => $_COOKIE['preferences'],
'pp' => 'test',
- 'user' => 'johndoe',//$currentUser->getUsername(),
+ 'user' => 'John',//$currentUser->getUsername(),
'role' => 'Athlete',//$currentUser->getRole(),
'users' => $listUsers
]);
@@ -117,39 +123,78 @@ class AthleteController extends BaseController
#[Route(path: '/analyses', name: 'analyses', methods: ['GET'])]
public function analyses(): Response
{
- return $this->render('./page/analyze.html.twig',[
- 'css' => $this->preference->getCookie(),
- 'pp' => "test2",
- 'user' => 'johndoe',//$currentUser->getUsername(),
- 'role' => 'Athlete',//$currentUser->getRole(),
- 'friendship' => [],
- 'analyzes' => [],
- 'mails' => [],
- 'users' => [],
- 'infoUser' => [],
- 'exos' => [],
- 'member' => []
- ]);
+ try {
+ $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
+ $listSearch = $activityGateway->getActivity();
+ $map = new ActivityMapper();
+ $activityGateway = $map->activitySqlToEntity($listSearch);
+ $listActivity = [];
+ foreach ($activityGateway as $entity) {
+ $activity = $map->activityEntityToModel($entity);
+ $listActivity[] = ['idactivity' => number_format($activity->getIdActivity(), 1), '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"),
+ 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(),
+ 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(),
+ 'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' =>$activity->getAvrTemperature()];
+ }
+
+ $response = $this->render('./page/analyze.html.twig',[
+ 'css' => $this->preference->getCookie(),
+ 'pp' => "test2",
+ 'user' => 'johndoe',//$currentUser->getUsername(),
+ 'role' => 'Athlete',//$currentUser->getRole(),
+ 'friendship' => [],
+ 'analyzes' => $listActivity,
+ 'mails' => [],
+ 'users' => [],
+ 'infoUser' => [],
+ 'exos' => [],
+ 'member' => []
+ ]);
+ } catch (\Throwable $th) {
+ throw $th;
+ return $this->render("./page/analyze.html.twig", ['tabError' => $taberror]);
+ }
+ return $response;
}
#[Route(path: '/activity', name: 'activity', methods: ['GET'])]
public function activity(): Response
{
- return $this->render('./page/activity.html.twig',[
- 'css' => $this->preference->getCookie(),
- 'pp' => "test",
- 'user' => 'johndoe',//$currentUser->getUsername(),
- 'role' => 'Athlete',//$currentUser->getRole(),
- 'friendship' => [],
- 'analyzes' => [],
- 'mails' => [],
- 'users' => [],
- 'infoUser' => [],
- 'exos' => [],
- 'member' => []
- ]);
- }
+ try {
+ $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
+ $listSearch = $activityGateway->getActivity();
+ $map = new ActivityMapper();
+ $activityGateway = $map->activitySqlToEntity($listSearch);
+ $listActivity = [];
+ foreach ($activityGateway as $entity) {
+ $activity = $map->activityEntityToModel($entity);
+ $listActivity[] = ['idactivity' => number_format($activity->getIdActivity(), 1), '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"),
+ 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(),
+ 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(),
+ 'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' => $activity->getAvrTemperature()];
+ }
+ $response = $this->render('./page/activity.html.twig', [
+ 'css' => $this->preference->getCookie(),
+ 'pp' => "test2",
+ 'user' => 'johndoe',//$currentUser->getUsername(),
+ 'role' => 'Athlete',//$currentUser->getRole(),
+ 'friendship' => [],
+ 'analyzes' => $listActivity,
+ 'mails' => [],
+ 'users' => [],
+ 'infoUser' => [],
+ 'exos' => [],
+ 'member' => []
+ ]);
+ } catch (\Throwable $th) {
+ throw $th;
+ return $this->render("./page/analyze.html.twig", ['tabError' => $taberror]);
+ }
+ return $response;
+ }
#[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8
public function exercice(): Response
@@ -161,13 +206,11 @@ class AthleteController extends BaseController
$entrainementEntity = $map->entrainementSqlToEntity($listSearch);
$listUsers = [];
- $i = 0;
foreach ($entrainementEntity as $entity) {
$training = $map->entrainementEntityToModel($entity);
- $listUsers[$i] = ['idTraining' => number_format($training->getId(), 1), 'date' => $training->getDate()->format("D j F Y"),
+ $listUsers[] = ['idTraining' => number_format($training->getId(), 1), 'date' => $training->getDate()->format("D j F Y"),
'location' => $training->getLocation(), 'description' => $training->getDescription(),
'feedback' => $training->getFeedback()];
- $i++;
}
$response = $this->render('./page/exercice.html.twig',[
@@ -220,23 +263,58 @@ class AthleteController extends BaseController
#[Route(path: '/add-friend', name: 'add-friend', methods: ['POST'])]
public function addFriend(string $username, IRequest $req): Response
{
- try {
+ try {/*
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
- $map= new AthleteMapper();
- $userSearched=$athleteGateway->getAthleteByFirstName($username);
- $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()];
+ $map=new AthleteMapper();
+ $friendEntity = $athleteGateway->getListIdFriends(1);
+
+ foreach($friendEntity as $users) {
+ if ($users['idathlete1']==1){
+ $user=(int)$users['idathlete2'];
+ } else {
+ $user=(int)$users['idathlete1'];
}
+ $listUserEntity[] = $map->athleteSqlToEntity($athleteGateway->getAthleteById(1));
}
- else{
- $users=[];
+ foreach ($listUserEntity as $user) {
+ $friendList[] = ['nom' => $user[0]->getNom(), 'prenom' => $user[0]->getPrenom(), 'img' => 'test', 'username' => 'test'];
+ }*/
+// $entrainementGateway = new EntrainementGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
+// $listSearch = $entrainementGateway->getEntrainements();
+// $map = new EntrainementMapper();
+// $entrainementEntity = $map->entrainementSqlToEntity($listSearch);
+//
+// $listUsers = [];
+// foreach ($entrainementEntity as $entity) {
+// $training = $map->entrainementEntityToModel($entity);
+// $listUsers[] = ['idTraining' => number_format($training->getId(), 1), 'date' => $training->getDate()->format("D j F Y"),
+// 'location' => $training->getLocation(), 'description' => $training->getDescription(),
+// 'feedback' => $training->getFeedback()];
+// }
+
+ $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
+ $map = new AthleteMapper();
+ $userSearched = $athleteGateway->getAthleteByFirstName("Bryan");
+ $athleteEntity = $map->athleteSqlToEntity($userSearched);
+// $user = $athleteGateway->getAthleteById(1);
+// $currentUser = $map->athleteToEntity($user);
+// Log::dd($currentUser);
+// 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()];
}
+ $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);
+ $notif->addNotification($mapper->notificationToEntity($myNotif));
return $this->render('./page/addfriend.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
@@ -311,10 +389,12 @@ class AthleteController extends BaseController
try {
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$map=new AthleteMapper();
- $friendEntity = $athleteGateway->getListIdFriends(1/*currentUser->getId()*/);
+ $friendEntity = $athleteGateway->getListIdFriends(1/*$currentUser->getId()*/);
+ $friendList = [];
+ $listUserEntity = [];
foreach($friendEntity as $users) {
- if ($users['idathlete1']==1/*currentUser->getId()*/){
+ if ($users['idathlete1']==1/*$currentUser->getId()*/){
$user=(int)$users['idathlete2'];
} else {
$user=(int)$users['idathlete1'];
@@ -331,12 +411,6 @@ class AthleteController extends BaseController
'user' => "Doe",
'role' => "Athlète",
'friendship' => $friendList,
- 'analyzes' => [],
- 'mails' => [],
- 'users' => $users,
- 'infoUser' => [],
- 'exos' => [],
- 'member' => [],
]);
} catch (\Throwable $th) {
diff --git a/Sources/src/app/controller/AuthController.php b/Sources/src/app/controller/AuthController.php
index c99af373..31d11e83 100644
--- a/Sources/src/app/controller/AuthController.php
+++ b/Sources/src/app/controller/AuthController.php
@@ -18,6 +18,19 @@ class AuthController extends BaseController
public function __construct(){
$this->preference = new Preferences();
}
+// ! private UserManager $userMgr;
+// public function __construct(UserManager $manager){
+// parent::__construct();
+// $this->userMgr = $manager;
+// }
+
+
+
+
+
+
+
+
#[Route('/login', name: 'login')]
public function login(?string $username, ?string $password ,IRequest $request): Response {
diff --git a/Sources/src/app/controller/SocialController.php b/Sources/src/app/controller/SocialController.php
index c4ef8805..f2867f55 100644
--- a/Sources/src/app/controller/SocialController.php
+++ b/Sources/src/app/controller/SocialController.php
@@ -17,17 +17,12 @@ use Shared\Log;
class SocialController extends BaseController
{
-
- private Environment $twig;
protected Preferences $preference;
- public function __construct()
- {
- session_start();
- $this->preference = new Preferences();
+ public function __construct(){
+ $this->preference = new Preferences();
}
-
#[Route(path: '/notification', name: 'notification', methods: ['GET'])]
public function mail(): Response
{
@@ -42,7 +37,7 @@ class SocialController extends BaseController
foreach ($notificationEntity as $entity) {
$notification = $map->notificationEntityToModel($entity);
$listUsers[] = ['idnotif' => $notification->getId(), 'message' => $notification->getMessage(),
- 'date' => $notification->getDate(),'statut' => $notification->getStatut(), 'urgence' => $notification->getUrgence(),
+ 'date' => $notification->getDate()->format("D j F Y"),'statut' => $notification->getStatut(), 'urgence' => $notification->getUrgence(),
'idathlete' => $notification->getToUserId()];
}
@@ -62,7 +57,7 @@ class SocialController extends BaseController
} catch (\Throwable $th) {
throw $th;
- return $this->render("addfriend.html.twig", ['tabError' => $taberror]);
+ return $this->render("notification.html.twig", ['tabError' => $taberror]);
}
return $response;
}
diff --git a/Sources/src/app/controller/UserController.php b/Sources/src/app/controller/UserController.php
index 1ee0adc3..6b3091af 100644
--- a/Sources/src/app/controller/UserController.php
+++ b/Sources/src/app/controller/UserController.php
@@ -18,7 +18,6 @@ class UserController extends BaseController
public function __construct()
{
- session_start();
$this->preference = new Preferences();
}
diff --git a/Sources/src/app/views/Templates/base.html.twig b/Sources/src/app/views/Templates/base.html.twig
index f1911f1d..d067781d 100755
--- a/Sources/src/app/views/Templates/base.html.twig
+++ b/Sources/src/app/views/Templates/base.html.twig
@@ -10,6 +10,7 @@
+