update some parts with database

DockerDeploying_test
Antoine PEREDERII 1 year ago
parent d3d6dbb12f
commit 2efb321f6a

@ -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';

@ -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));

@ -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()
]);
}

@ -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;
}
$charts[] = ['act' => $activity[$i]['nbactivite'], 'mois' => $activity[$i]['mois']];
$i++;
}
// 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;
}
// 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",

@ -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");

@ -60,7 +60,7 @@
</a>
<a class="nav-link" href="/activity">
<div class="sb-nav-link-icon"><i class="fas fa-chart-area"></i></div>
Analyses
Activités
</a>
<div class="sb-sidenav-menu-heading">Social</div>
<a class="nav-link" href="/friendlist">

@ -40,9 +40,6 @@
{% 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: {

@ -44,7 +44,7 @@
<span class="text-blue-600 hover:underline">select a file</span>
from your computer</p>
</div>
<input type="file" class="hidden" id="file-input" name="uploaded_file">
<input type="file" class="hidden" id="file-input" name="uploaded_file" accept=".fit">
</label>
<p id="file-name-display" class="text-sm text-gray-500"></p>
</div>

@ -205,7 +205,7 @@
<!-- App badge section-->
<section class="bg-gradient-primary-to-secondary" id="download">
<div class="container px-5">
<h2 class="text-center text-white font-alt mb-4">Application bientôt disponible !</h2>
<h2 class="text-center text-white font-alt mb-4">Application mobile bientôt disponible !</h2>
<!-- <div class="d-flex flex-column flex-lg-row align-items-center justify-content-center">
<a class="me-lg-3 mb-4 mb-lg-0" href="#!"><img class="app-badge" src="assets/img/google-play-badge.svg" alt="..." /></a>
<a href="#!"><img class="app-badge" src="assets/img/app-store-badge.svg" alt="..." /></a>

@ -2,12 +2,14 @@
namespace Database;
use DateTime;
class ActivityEntity {
private $idActivity;
private $type;
private $date;
private $heureDebut;
private $heureFin;
private DateTime $date;
private DateTime $heureDebut;
private DateTime $heureFin;
private $effortRessenti;
private $variabilite;
private $variance;

@ -13,28 +13,28 @@ class ActivityMapper {
foreach ($data as $activityData) {
$activity = new ActivityEntity();
if (isset($activityData['idactivite'])) {
$activity->setIdActivity($activityData['idactivite']);
if (isset($activityData['idActivite'])) {
$activity->setIdActivity($activityData['idActivite']);
}
if (isset($activityData['type'])) {
$activity->setType($activityData['type']);
}
if (isset($activityData['date'])) {
$activity->setDate($activityData['date']);
}
// if (isset($activityData['date'])) {
// $activity->setDate(DateTime::createFromFormat('yyyy-mm--dd',$activityData['date']));
// }
if (isset($activityData['heurededebut'])) {
$activity->setHeureDebut($activityData['heurededebut']);
if (isset($activityData['heureDeDebut'])) {
$activity->setHeureDebut(new DateTime($activityData['heureDeDebut']));
}
if (isset($activityData['heuredefin'])) {
$activity->setHeureFin($activityData['heuredefin']);
if (isset($activityData['heureDeFin'])) {
$activity->setHeureFin(new DateTime($activityData['heureDeFin']));
}
if (isset($activityData['effortressent'])) {
$activity->setEffortRessenti($activityData['effortressent']);
if (isset($activityData['effortRessent'])) {
$activity->setEffortRessenti($activityData['effortRessent']);
}
if (isset($activityData['variabilite'])) {
@ -45,8 +45,8 @@ class ActivityMapper {
$activity->setVariance($activityData['variance']);
}
if (isset($activityData['ecarttype'])) {
$activity->setEcartType($activityData['ecarttype']);
if (isset($activityData['ecartType'])) {
$activity->setEcartType($activityData['ecartType']);
}
if (isset($activityData['moyenne'])) {
@ -61,12 +61,13 @@ class ActivityMapper {
$activity->setMinimum($activityData['minimum']);
}
if (isset($activityData['temperaturemoyenne'])) {
$activity->setTemperatureMoyenne($activityData['temperaturemoyenne']);
if (isset($activityData['temperatureMoyenne'])) {
$activity->setTemperatureMoyenne($activityData['temperatureMoyenne']);
}
$activityEntities[] = $activity;
}
Log::dd($activityEntities);
return $activityEntities;
}
@ -83,7 +84,6 @@ class ActivityMapper {
$ecartType = floatval($activiteEntity->getEcartType());
$act = new Activity(
$activiteEntity->getIdActivity(),
$activiteEntity->getType(),
$date,
$heureDebut,
@ -104,7 +104,6 @@ class ActivityMapper {
//public function ActivityToEntity(Activity model): ActivityEntity;
public function activityToEntity(Activity $act):ActivityEntity{
$actEntity = new ActivityEntity();
$actEntity->setIdActivity($act->getIdActivity());
$actEntity->setType($act->getType());

@ -47,6 +47,12 @@ class AthleteGateway {
$params = [':email' => $email];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByEmail(string $email): array
{
$query = "SELECT * FROM Athlete WHERE email = :email";
$params = [':email' => $email];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getAthleteByGender(string $gender): array
{
@ -89,12 +95,25 @@ class AthleteGateway {
public function getListActivity(int $idAthlete): array
{
$query = "SELECT count(ac.idActivite) AS nbActivite, EXTRACT(MONTH FROM ac.date) AS mois
/*$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 = 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";
// $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 = at.idAthlete
// GROUP BY mois";
$params = [
':idAthlete' => $idAthlete,
@ -127,12 +146,13 @@ class AthleteGateway {
public function updateAthlete(AthleteEntity $oldAthlete, AthleteEntity $newAthlete): array
{
$query = "UPDATE Athlete
SET nom = :nom, prenom = :prenom, email = :email, sexe = :sexe,
SET username = :username, nom = :nom, prenom = :prenom, email = :email, sexe = :sexe,
taille = :taille, poids = :poids, motDePasse = :motDePasse, dateNaissance = :dateNaissance, isCoach = :isCoach
WHERE idAthlete = :idAthlete";
$params = [
':idAthlete' => $oldAthlete->getIdAthlete(),
':username' => $newAthlete->getUsername(),
':nom' => $newAthlete->getNom(),
':prenom' => $newAthlete->getPrenom(),
':email' => $newAthlete->getEmail(),

@ -71,7 +71,6 @@ class AthleteMapper {
$taille = floatval($athleteEntity->getTaille());
$user = new User(
$athleteEntity->getIdAthlete(),
$athleteEntity->getNom(),
$athleteEntity->getPrenom(),
$athleteEntity->getUsername(),

@ -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);
}
}

@ -1,6 +1,6 @@
INSERT INTO Athlete (idAthlete, username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES
(1, 'johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 70, 'password123', '1990-01-01', FALSE),
(2, 'janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE),
(3, 'bryanO', 'OConner', 'Bryan', 'bryan.oconner@example.com', 'M', 1.88, 86, 'password789', '1973-09-12', FALSE),
(4, 'dominicT', 'Toretto', 'Dominic', 'dominic.toretto@example.com', 'M', 1.83, 94, 'password987', '1967-07-18', TRUE),
(5, 'miaT', 'Toretto', 'Mia', 'mia.toretto@example.com', 'F', 1.70, 56, 'password654', '1980-04-26', FALSE);
INSERT INTO Athlete (username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES
('johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 70, 'password123', '1990-01-01', FALSE),
('janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE),
('bryanO', 'OConner', 'Bryan', 'bryan.oconner@example.com', 'M', 1.88, 86, 'password789', '1973-09-12', FALSE),
('dominicT', 'Toretto', 'Dominic', 'dominic.toretto@example.com', 'M', 1.83, 94, 'password987', '1967-07-18', TRUE),
('miaT', 'Toretto', 'Mia', 'mia.toretto@example.com', 'F', 1.70, 56, 'password654', '1980-04-26', FALSE);

@ -1,21 +1,22 @@
INSERT INTO FrequenceCardiaque VALUES(1, 100, '08:15:00', 15, 130, 45.75771709151474, 3.113484980409329, 1);
INSERT INTO FrequenceCardiaque VALUES
(2, ROUND(RANDOM() * 10 + 90), '08:16:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75772709151474, 3.113494980409329, 1),
(3, ROUND(RANDOM() * 10 + 90), '08:17:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75773709151474, 3.113504980409329, 1),
(4, ROUND(RANDOM() * 10 + 90), '08:18:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75774709151474, 3.113514980409329, 1),
(5, ROUND(RANDOM() * 10 + 90), '08:19:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75775709151474, 3.113524980409329, 1),
(6, ROUND(RANDOM() * 10 + 90), '08:20:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75776709151474, 3.113534980409329, 1),
(7, ROUND(RANDOM() * 10 + 90), '08:21:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75777709151474, 3.113544980409329, 1),
(8, ROUND(RANDOM() * 10 + 90), '08:22:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75778709151474, 3.113554980409329, 1),
(9, ROUND(RANDOM() * 10 + 90), '08:23:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75779709151474, 3.113564980409329, 1),
(10, ROUND(RANDOM() * 10 + 90), '08:24:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75780709151474, 3.113574980409329, 1),
(11, ROUND(RANDOM() * 10 + 90), '08:25:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75781709151474, 3.113584980409329, 1),
(12, ROUND(RANDOM() * 10 + 90), '08:26:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75782709151474, 3.113594980409329, 1),
(13, ROUND(RANDOM() * 10 + 90), '08:27:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75783709151474, 3.113604980409329, 1),
(14, ROUND(RANDOM() * 10 + 90), '08:28:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75784709151474, 3.113614980409329, 1),
(15, ROUND(RANDOM() * 10 + 90), '08:29:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75785709151474, 3.113624980409329, 1),
(16, ROUND(RANDOM() * 10 + 90), '08:30:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75786709151474, 3.113634980409329, 1),
(17, ROUND(RANDOM() * 10 + 90), '08:31:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75787709151474, 3.113644980409329, 1),
(18, ROUND(RANDOM() * 10 + 90), '08:32:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75788709151474, 3.113654980409329, 1),
(19, ROUND(RANDOM() * 10 + 90), '08:33:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75789709151474, 3.113664980409329, 1),
(20, ROUND(RANDOM() * 10 + 90), '08:34:00', ROUND(RANDOM() * 5 + 10), ROUND(RANDOM() * 20 + 110), 45.75790709151474, 3.113674980409329, 1);
INSERT INTO FrequenceCardiaque
VALUES
(1, 100, '08:15:00', 15, 130, 45.75771709151474, 3.113484980409329, 1),
(2, ROUND(RAND() * 10 + 90), '08:16:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75772709151474, 3.113494980409329, 1),
(3, ROUND(RAND() * 10 + 90), '08:17:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75773709151474, 3.113504980409329, 1),
(4, ROUND(RAND() * 10 + 90), '08:18:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75774709151474, 3.113514980409329, 1),
(5, ROUND(RAND() * 10 + 90), '08:19:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75775709151474, 3.113524980409329, 1),
(6, ROUND(RAND() * 10 + 90), '08:20:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75776709151474, 3.113534980409329, 1),
(7, ROUND(RAND() * 10 + 90), '08:21:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75777709151474, 3.113544980409329, 1),
(8, ROUND(RAND() * 10 + 90), '08:22:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75778709151474, 3.113554980409329, 1),
(9, ROUND(RAND() * 10 + 90), '08:23:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75779709151474, 3.113564980409329, 1),
(10, ROUND(RAND() * 10 + 90), '08:24:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75780709151474, 3.113574980409329, 1),
(11, ROUND(RAND() * 10 + 90), '08:25:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75781709151474, 3.113584980409329, 1),
(12, ROUND(RAND() * 10 + 90), '08:26:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75782709151474, 3.113594980409329, 1),
(13, ROUND(RAND() * 10 + 90), '08:27:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75783709151474, 3.113604980409329, 1),
(14, ROUND(RAND() * 10 + 90), '08:28:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75784709151474, 3.113614980409329, 1),
(15, ROUND(RAND() * 10 + 90), '08:29:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75785709151474, 3.113624980409329, 1),
(16, ROUND(RAND() * 10 + 90), '08:30:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75786709151474, 3.113634980409329, 1),
(17, ROUND(RAND() * 10 + 90), '08:31:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75787709151474, 3.113644980409329, 1),
(18, ROUND(RAND() * 10 + 90), '08:32:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75788709151474, 3.113654980409329, 1),
(19, ROUND(RAND() * 10 + 90), '08:33:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75789709151474, 3.113664980409329, 1),
(20, ROUND(RAND() * 10 + 90), '08:34:00', ROUND(RAND() * 5 + 10), ROUND(RAND() * 20 + 110), 45.75790709151474, 3.113674980409329, 1);

@ -24,6 +24,3 @@ INSERT INTO SourceDonnee (idSource, type, modele, precision2, athleteId) VALUES
INSERT INTO Activite (idActivite, type, date, heureDeDebut, heureDeFin, effortRessent, variabilite, variance, ecartType, moyenne, maximum, minimum, temperatureMoyenne, athleteId, sourceId) VALUES
(1, 'Running', '2023-03-10', '08:00:00', '09:00:00', 3, 0.5, 1, 0.1, 140, 160, 120, 20, 1, 1),
(2, 'Running Forest', '2023-04-13', '10:00:00', '12:00:00', 5, 0.5, 1, 0.1, 140, 160, 120, 20, 1, 1);
INSERT INTO FrequenceCardiaque (idFc, altitude, temps, temperature, bpm, longitude, latitude, activiteId) VALUES
(1, 100, '08:15:00', 15, 130, -74.0060, 40.7128, 1);

@ -1,7 +1,8 @@
DROP TABLE IF EXISTS Athlete, Friendship, Notification, Statistique, Entrainement, Participe, SourceDonnee, Activite, FrequenceCardiaque CASCADE;
CREATE TABLE Athlete (
idAthlete SERIAL PRIMARY KEY,
idAthlete INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255),
nom VARCHAR(255),
prenom VARCHAR(255),
email VARCHAR(255) UNIQUE,
@ -12,7 +13,6 @@ CREATE TABLE Athlete (
dateNaissance DATE,
isCoach BOOLEAN
);
CREATE TABLE Friendship (
idAthlete1 INT,
idAthlete2 INT,
@ -23,7 +23,7 @@ CREATE TABLE Friendship (
);
CREATE TABLE Notification (
idNotif INT PRIMARY KEY,
idNotif INT AUTO_INCREMENT PRIMARY KEY,
message TEXT,
date DATE,
statut BOOLEAN,
@ -33,7 +33,7 @@ CREATE TABLE Notification (
);
CREATE TABLE Statistique (
idStatistique INT PRIMARY KEY,
idStatistique INT AUTO_INCREMENT PRIMARY KEY,
poids DECIMAL,
fcMoyenne DECIMAL,
fcMax DECIMAL,
@ -44,7 +44,7 @@ CREATE TABLE Statistique (
);
CREATE TABLE Entrainement (
idEntrainement INT PRIMARY KEY,
idEntrainement INT AUTO_INCREMENT PRIMARY KEY,
date DATE,
description TEXT,
latitude DECIMAL,
@ -63,7 +63,7 @@ CREATE TABLE Participe (
);
CREATE TABLE SourceDonnee (
idSource INT PRIMARY KEY,
idSource INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(255),
modele VARCHAR(255),
precision2 DECIMAL,
@ -72,7 +72,7 @@ CREATE TABLE SourceDonnee (
);
CREATE TABLE Activite (
idActivite INT PRIMARY KEY,
idActivite INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(255),
date DATE,
heureDeDebut TIME,
@ -92,7 +92,7 @@ CREATE TABLE Activite (
);
CREATE TABLE FrequenceCardiaque (
idFc INT PRIMARY KEY,
idFc INT AUTO_INCREMENT PRIMARY KEY,
altitude DECIMAL,
temps TIME,
temperature DECIMAL,
@ -103,5 +103,5 @@ CREATE TABLE FrequenceCardiaque (
FOREIGN KEY (activiteId) REFERENCES Activite(idActivite)
);
\i athlete.sql
\i friendship.sql
-- \i athlete.sql
-- \i friendship.sql

@ -2,6 +2,9 @@
namespace Network;
use App\Router\Session;
use Database\AthleteGateway;
use Database\AthleteMapper;
use Database\Connexion;
use Model\User;
use Model\Athlete;
use Model\CoachAthlete;
@ -24,11 +27,22 @@ class AuthService implements IAuthService
public function login(string $email, string $password): bool
{
$user = $this->userRepository->getItemByEmail($email);
if ($user === null || !$this->passwordHacher->isPasswordValid( $user->getMotDePasse(),$password)) {
// $user = $this->userRepository->getItemByEmail($email);
$userGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$userRepository = $userGateway->getUserByEmail($email);
$map = new AthleteMapper();
$userEntity = $map->athleteSqlToEntity($userRepository);
// $map->athleteEntityToModel($userRepository)
$user = ['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'];
if ($user === null || !$this->passwordHacher->isPasswordValid($user[0]['motdepasse'],$password)) {
return false;
}
$this->currentUser = $user;
$this->currentUser = $user[0];
Session::getInstance()->__set(USER, $this->currentUser->getId());
return true;
}
@ -58,7 +72,6 @@ class AuthService implements IAuthService
}
$user = new User(
random_int(0, 100),
$nom,
$prenom,
$username,
@ -68,7 +81,6 @@ class AuthService implements IAuthService
$taille,
$poids,
$dateNaissance,
//should use reflexion
$role
);
$this->userRepository->addItem($user);

@ -17,7 +17,7 @@ namespace Model;
*/
class Activity
{
private static int $lastId = 100;
private static int $lastId = 0;
private int $idActivity;
private String $type;
private \DateTime $date;
@ -53,7 +53,6 @@ class Activity
* @throws \Exception Si l'effort ressenti n'est pas compris entre 0 et 5.
*/
public function __construct(
int $idActivity,
String $type,
\DateTime $date,
\DateTime $heureDebut,

@ -6,6 +6,7 @@ use DateTime;
class Notification
{
private static $lastId = 0;
private int $idNotif;
private string $message;
private \DateTime $date;
@ -17,7 +18,6 @@ class Notification
* @param string $message
*/
public function __construct(
int $idNotif,
string $message,
DateTime $date,
string $statut,
@ -25,13 +25,18 @@ class Notification
int $toUserId
)
{
$this->idNotif = $idNotif;
$this->idNotif = self::generateId();
$this->message = $message;
$this->date = $date;
$this->statut = $statut;
$this->urgence = $urgence;
$this->toUserId =$toUserId;
}
private static function generateId(): int
{
self::$lastId++;
return self::$lastId;
}
public function getId(){ return $this->idNotif;}
public function getDate(){ return $this->date;}

@ -18,7 +18,6 @@ use Stub\TrainingRepository;
* @brief Classe abstraite représentant le rôle d'un utilisateur.
*/
abstract class Role {
protected int $id;
protected array $usersList = [];
protected array $usersRequests = [];
protected array $trainingList = [];

@ -4,6 +4,7 @@ namespace Model;
class Training
{
private static $lastId = 0;
private int $idTraining;
private \DateTime $date;
private float $latitude;
@ -12,20 +13,24 @@ class Training
private ?String $feedback;
public function __construct(
int $idTraining,
\DateTime $date,
float $latitude,
float $longitude,
?String $description = null,
?String $feedback = null
) {
$this->idTraining = $idTraining;
$this->idTraining = self::generateId();
$this->date = $date;
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->description = $description;
$this->feedback = $feedback;
}
private static function generateId(): int
{
self::$lastId++;
return self::$lastId;
}
public function getId():int {
return $this->idTraining;
}

@ -16,6 +16,7 @@ namespace Model;
* @brief Classe représentant un utilisateur.
*/
class User {
private static $lastId = 0;
private int $id;
private String $username;
private string $nom;
@ -30,14 +31,6 @@ class User {
protected array $notifications = [];
private array $listFriend = [];
/**
* @return array
*/
public function getNotifications(): array
{
return $this->notifications;
}
/**
* @param int $id
* @param string $nom
@ -51,11 +44,11 @@ class User {
* @param \DateTime $dateNaissance
* @param \Model\Role $role
*/
public function __construct(int $id, string $nom, string $prenom, string $username, string $email,
public function __construct(string $nom, string $prenom, string $username, string $email,
string $motDePasse, string $sexe, float $taille, float $poids, \DateTime $dateNaissance,
Role $role)
{
$this->id = $id;
$this->id = self::generateId();
$this->nom = $nom;
$this->prenom = $prenom;
$this->username = $username;
@ -67,6 +60,18 @@ class User {
$this->dateNaissance = $dateNaissance;
$this->role = $role;
}
private static function generateId(): int
{
self::$lastId++;
return self::$lastId;
}
/**
* @return array
*/
public function getNotifications(): array
{
return $this->notifications;
}
public function addNotification($notification): void {
$this->notifications[] = $notification;

@ -170,7 +170,7 @@ class ActivityManager
// Création de l'objet Activity
$newActivity = new Activity(
13,
15,
$type,
$startDate,
$startTime,

@ -13,11 +13,11 @@ class NotificationRepository implements INotificationRepository
{
$date = DateTime::createFromFormat('d/m/Y', date('d/m/Y'));
// Initialize with some sample notifications for user IDs 1, 2, and 3
$this->notifications[] = new Notification(1, 'info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification(2, 'info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification(3, 'info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification(1, 'info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification(2, 'info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification('info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification('info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification('info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification('info', $date,'Welcome to our service!', '1', 1);
$this->notifications[] = new Notification('info', $date,'Welcome to our service!', '1', 1);
}
public function getItemById(int $id)
{

@ -27,11 +27,11 @@ class UserRepository implements IUserRepository {
* Constructeur de la classe UserRepository.
*/
public function __construct() {
$this->users[] = new User(1, "Doe", "John", "Doe","john.doe@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete());
$this->users[] = new User(2, "Smith", "Jane","Smith", "jane.smith@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'F', 1.65, 60, new \DateTime("1990-03-10"), new Athlete());
$this->users[] = new User(3, "Martin", "Paul","Martin", "paul.martin@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'M', 1.75, 68, new \DateTime("1988-08-20"), new CoachAthlete());
$this->users[] = new User(4, "Brown", "Anna","Brown", "anna.brown@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'F', 1.70, 58, new \DateTime("1992-11-25"), new Athlete());
$this->users[] = new User(5, "Lee", "Bruce","Lee", "bruce.lee@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'M', 1.72, 70, new \DateTime("1970-02-05"), new Athlete());
$this->users[] = new User("Doe", "John", "Doe","john.doe@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete());
$this->users[] = new User("Smith", "Jane","Smith", "jane.smith@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'F', 1.65, 60, new \DateTime("1990-03-10"), new Athlete());
$this->users[] = new User("Martin", "Paul","Martin", "paul.martin@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'M', 1.75, 68, new \DateTime("1988-08-20"), new CoachAthlete());
$this->users[] = new User("Brown", "Anna","Brown", "anna.brown@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'F', 1.70, 58, new \DateTime("1992-11-25"), new Athlete());
$this->users[] = new User("Lee", "Bruce","Lee", "bruce.lee@example.com", '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', 'M', 1.72, 70, new \DateTime("1970-02-05"), new Athlete());
// $this->users[] = new User(1, "Doe", "John", "Doe","john.doe@example.com", "password123", 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete());
// $this->users[] = new User(2, "Smith", "Jane","Smith", "jane.smith@example.com", "secure456", 'F', 1.65, 60, new \DateTime("1990-03-10"), new Athlete());
// $this->users[] = new User(3, "Martin", "Paul","Martin", "paul.martin@example.com", "super789", 'M', 1.75, 68, new \DateTime("1988-08-20"), new CoachAthlete());

Loading…
Cancel
Save