Affichage ami

merged_PLE
Paul LEVRAULT 1 year ago
parent 6786eea1c4
commit bc0b4ee2d6

@ -12,10 +12,10 @@ $dotenv->safeLoad();
// const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger'; // const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger';
define("APP_ENV", 'development'); define("APP_ENV", 'development');
const DB_SERVER = 'pgsql'; const DB_SERVER = 'mysql';
const DB_HOST = 'localhost'; const DB_HOST = 'localhost';
const DB_DATABASE = 'sae_3'; const DB_DATABASE = 'new';
const DB_USER = 'Perederii'; const DB_USER = 'root';
const DB_PASSWORD = ''; const DB_PASSWORD = '';
//const APP_ENV = 'console'; //const APP_ENV = 'console';

@ -421,20 +421,25 @@ class AthleteController extends BaseController
try { try {
$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();
$friendEntity = $athleteGateway->getListIdFriends(1/*$currentUser->getId()*/); $friendEntity = $athleteGateway->getListIdFriends(3/*$currentUser->getId()*/);
foreach($friendEntity as $friendship){
$friendList = []; if($friendship['idAthlete1']==3/*$currentUser->getId()*/){
$listUserEntity = []; $listFriend[]=$friendship['idAthlete2'];
foreach($friendEntity as $users) {
if ($users['idathlete1']==1/*$currentUser->getId()*/){
$user=(int)$users['idathlete2'];
} else { } else {
$user=(int)$users['idathlete1']; $listFriend[]=$friendship['idAthlete1'];
} }
$listUserEntity[] = $map->athleteSqlToEntity($athleteGateway->getAthleteById(1));
} }
foreach($listFriend as $friend){
$friends[]=$athleteGateway->getById($friend);
}
foreach($friends as $friend){
$friendlist[]=$friend[0];
}
$listUserEntity = $map->athleteSqlToEntity($friendlist);
foreach ($listUserEntity as $user) { foreach ($listUserEntity as $user) {
$friendList[] = ['nom' => $user[0]->getNom(), 'prenom' => $user[0]->getPrenom(), 'img' => 'test', 'username' => 'test']; $friendList[] = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()];
} }
$response = $this->render('./page/friend.html.twig',[ $response = $this->render('./page/friend.html.twig',[

@ -22,7 +22,6 @@ class AthleteGateway {
{ {
$query = "SELECT * FROM Athlete WHERE idAthlete = :id AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE idAthlete = :id AND isCoach=FALSE";
$params = [':id' => $userId]; $params = [':id' => $userId];
// log::dd($params);
$res = $this->connection->executeWithErrorHandling($query, $params); $res = $this->connection->executeWithErrorHandling($query, $params);
return $res; return $res;
} }
@ -90,10 +89,10 @@ 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 at, Activite ac FROM Athlete ath, Activite ac
WHERE at.idAthlete = :idAthlete WHERE ath.idAthlete = :idAthlete
AND ac.date > CURRENT_DATE - INTERVAL '1 YEAR' AND ac.date > CURRENT_DATE - INTERVAL '1 YEAR'
AND ac.athleteId = at.idAthlete AND ac.athleteId = ath.idAthlete
GROUP BY mois"; GROUP BY mois";
$params = [ $params = [
@ -158,6 +157,14 @@ class AthleteGateway {
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getById(int $userId): array
{
$query = "SELECT * FROM Athlete WHERE idAthlete = :id";
$params = [':id' => $userId];
$res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
}
} }

Loading…
Cancel
Save