modif ajout d'amis

merged_PLE
Paul LEVRAULT 1 year ago
parent bc0b4ee2d6
commit d39694036a

@ -201,8 +201,8 @@ class AthleteController extends BaseController
$listActivity = []; $listActivity = [];
foreach ($activityGateway as $entity) { foreach ($activityGateway as $entity) {
$activity = $map->activityEntityToModel($entity); $activity = $map->activityEntityToModel($entity);
$listActivity[] = ['idactivity' => number_format($activity->getIdActivity()), 'type' => $activity->getType(), $listActivity[] = ['idactivite' => 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"), '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(), 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(),
'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(), 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(),
'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' => $activity->getAvrTemperature()]; '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'])] #[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 {/* try {/*
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $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)); $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$map = new AthleteMapper(); $map = new AthleteMapper();
$userSearched = $athleteGateway->getAthleteByFirstName("Bryan"); $userSearched = $athleteGateway->getAthleteById((int)$id);
$athleteEntity = $map->athleteSqlToEntity($userSearched); $athleteEntity = $map->athleteSqlToEntity($userSearched);
// $user = $athleteGateway->getAthleteById(1); // $user = $athleteGateway->getAthleteById(1);
// $currentUser = $map->athleteToEntity($user); // $currentUser = $map->athleteToEntity($user);
@ -334,18 +334,17 @@ class AthleteController extends BaseController
// foreach($userSearched as $user) { // foreach($userSearched as $user) {
// $listUser[] = $map->athleteToEntity($user); // $listUser[] = $map->athleteToEntity($user);
// } // }
$users=[];
foreach ($athleteEntity as $user) { foreach ($athleteEntity as $user) {
// $this->userMgr->getCurrentUser()->addFriend($user); // $this->userMgr->getCurrentUser()->addFriend($user);
// $currentUser->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)); $notif = new NotificationGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$mapper = new NotificationMapper(); $mapper = new NotificationMapper();
$date = new DateTime(); $date = new DateTime();
// DateTime::createFromFormat('d/m/Y', date('d/m/Y')); // DateTime::createFromFormat('d/m/Y', date('d/m/Y'));
// Log::dd($date); // 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)); $notif->addNotification($mapper->notificationToEntity($myNotif));
return $this->render('./page/addfriend.html.twig',[ return $this->render('./page/addfriend.html.twig',[
'css' => $this->preference->getCookie(), 'css' => $this->preference->getCookie(),
@ -359,7 +358,7 @@ class AthleteController extends BaseController
'infoUser' => [], 'infoUser' => [],
'exos' => [], 'exos' => [],
'member' => [], 'member' => [],
'responce' => "Notification d'ajout envoyée à $username" 'responce' => "Notification d'ajout envoyée à ".$users[0]['username']
]); ]);
} catch (\Throwable $th) { } catch (\Throwable $th) {
throw $th; throw $th;

@ -5,6 +5,7 @@ namespace App\Controller;
use App\Container; use App\Container;
use App\Router\Request\IRequest; use App\Router\Request\IRequest;
use App\Router\Response\Response; use App\Router\Response\Response;
use Database\ActivityMapper;
use Shared\Attributes\Route; use Shared\Attributes\Route;
use Twig\Environment; use Twig\Environment;
use Data\Core\Preferences; use Data\Core\Preferences;
@ -49,6 +50,7 @@ class UserController extends BaseController
$activity = $athleteGateway->getListActivity('1');//$currentUser->getId() $activity = $athleteGateway->getListActivity('1');//$currentUser->getId()
// Log::dd($activity); // Log::dd($activity);
$chart = []; $chart = [];
// PROBLEME AVEC LE GRAPHIQUE Soucis avec le graphique : Undefined array key "nbactivite" ligne 57
foreach($activity as $act){ foreach($activity as $act){
$chart[] = ['act' => $act['nbactivite'], 'mois' => date('m', $act['mois'])]; $chart[] = ['act' => $act['nbactivite'], 'mois' => date('m', $act['mois'])];
} }

@ -43,10 +43,9 @@
<img src="/assets/img/person/{{utili.img}}.png" width="35px" height="35px" class="image-ronde"></td> <img src="/assets/img/person/{{utili.img}}.png" width="35px" height="35px" class="image-ronde"></td>
<td>{{utili.nom}}</td> <td>{{utili.nom}}</td>
<td>{{utili.prenom}}</td> <td>{{utili.prenom}}</td>
<td style=" <td style="padding-left: 45%;">
padding-left: 45%;"> <form method="post" action="/add-friend">
<form method="post" action="/add-friend"> <input type="hidden" name="id" value="{{ utili.idathlete }}">
<input type="hidden" name="username" value="{{ utili.username }}">
<button class="btn btn-primary" type="submit">Ajouter un ami</button> <button class="btn btn-primary" type="submit">Ajouter un ami</button>
</form> </form>

@ -18,7 +18,7 @@ class ActivityEntity {
private $temperatureMoyenne; private $temperatureMoyenne;
// Getters // Getters
public function getIdActivity() { public function getIdActivity() :int {
return $this->idActivity; return $this->idActivity;
} }

@ -73,7 +73,7 @@ class ActivityMapper {
/** /**
* @throws \Exception * @throws \Exception
*/ */
public function ActivityEntityToModel(ActivityEntity $activiteEntity):Activity { public function activityEntityToModel(ActivityEntity $activiteEntity):Activity {
$date = new DateTime($activiteEntity->getDate()); $date = new DateTime($activiteEntity->getDate());
$heureDebut = new \DateTime($activiteEntity->getHeureDebut()); $heureDebut = new \DateTime($activiteEntity->getHeureDebut());
$heureFin = new \DateTime($activiteEntity->getHeureFin()); $heureFin = new \DateTime($activiteEntity->getHeureFin());

@ -88,12 +88,19 @@ class AthleteGateway {
public function getListActivity(int $idAthlete): array 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 ath, Activite ac FROM Athlete at, Activite ac
WHERE ath.idAthlete = :idAthlete WHERE at.idAthlete = :idAthlete
AND ac.date > CURRENT_DATE - INTERVAL '1 YEAR' AND ac.date > CURRENT_DATE - INTERVAL '1 YEAR'
AND ac.athleteId = ath.idAthlete AND ac.athleteId = at.idAthlete
GROUP BY mois"; 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 = [ $params = [
':idAthlete' => $idAthlete, ':idAthlete' => $idAthlete,

Loading…
Cancel
Save