Merge branch 'merged_PLE' of codefirst.iut.uca.fr:HeartDev/Web into merged_PLE

merging_APE
Antoine PEREDERII 1 year ago
commit 90c43b08f2

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

@ -91,10 +91,13 @@ class AthleteController extends BaseController
} else { } else {
try { try {
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$listSearch = $athleteGateway->getAthlete($username); if($username==null){
$listSearch=$athleteGateway->getAthlete();
} else {
$listSearch = $athleteGateway->getAthleteByName($username);
}
$map = new AthleteMapper(); $map = new AthleteMapper();
$athleteEntity = $map->athleteSqlToEntity($listSearch); $athleteEntity = $map->athleteSqlToEntity($listSearch);
$listUsers = []; $listUsers = [];
foreach ($athleteEntity as $entity) { foreach ($athleteEntity as $entity) {
$user = $map->athleteEntityToModel($entity); $user = $map->athleteEntityToModel($entity);

@ -9,6 +9,8 @@ use Shared\Attributes\Route;
use Twig\Environment; use Twig\Environment;
use Data\Core\Preferences; use Data\Core\Preferences;
use Shared\Log; use Shared\Log;
use Database\Athletegateway;
use Database\Connexion;
class UserController extends BaseController class UserController extends BaseController
{ {
@ -43,6 +45,12 @@ class UserController extends BaseController
#[Route(path: '/home', name: 'home', methods: ['GET'])] #[Route(path: '/home', name: 'home', methods: ['GET'])]
public function home(): Response public function home(): Response
{ {
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$activity = $athleteGateway->getListActivity('1');//$currentUser->getId()
foreach($activity as $act){
$chart["act"] = $act["nbActivite"];
$chart["mois"] = date('M', mktime(0, 0, 0, $act["mois"], 10));
}
return $this->render('./page/home.html.twig',[ return $this->render('./page/home.html.twig',[
'css' => $this->preference->getCookie(), 'css' => $this->preference->getCookie(),
'pp' => "test2", 'pp' => "test2",
@ -50,6 +58,7 @@ class UserController extends BaseController
'role' => "Athlète", 'role' => "Athlète",
'friendship' => [], 'friendship' => [],
'analyzes' => [], 'analyzes' => [],
'chart' => $chart,
'mails' => [], 'mails' => [],
'users' => [], 'users' => [],
'infoUser' => [], 'infoUser' => [],

@ -22,7 +22,26 @@
Stastiques globales Stastiques globales
</div> </div>
<div class="card-body"> <div class="card-body">
{# <canvas id="myAreaChart" width="100%" height="40"></canvas> #} <canvas id="myAreaChart" width="100%" height="40">
<script src="path/to/chartjs/dist/chart.umd.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const ctx = document.getElementById('myAreaChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: chart.map(entry => entry.mois),
datasets: [{
label: 'Nombre d\'activité',
data: chart.map(entry => entry.act),
fill: false
}]
}
});
});
</script>
</canvas>
</div> </div>
</div> </div>
</div> </div>

@ -30,7 +30,7 @@ class AthleteGateway {
public function getAthleteByName(string $name): array public function getAthleteByName(string $name): array
{ {
$query = "SELECT * FROM Athlete WHERE nom = :name AND isCoach=FALSE"; $query = "SELECT * FROM Athlete WHERE nom = :name AND isCoach=FALSE";
$params = [':name' => [$name, PDO::PARAM_STR]]; $params = [':name' => $name];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
@ -87,6 +87,17 @@ class AthleteGateway {
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
public function getListActivity(int $idAthlete): array
{
$query = "SELECT count(ac.idActivite) AS nbActivite, MONTH(ac.date) AS mois FROM Athlete at, Activite ac WHERE at.idAthlete = :idAthlete AND ac.date > DATE_SUB(date, INTERVAL 1 YEAR) AND ac.athleteId=at.idAthlete GROUP BY mois";
$params = [
':idAthlete' => $idAthlete,
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function addAthlete(AthleteEntity $athlete): array public function addAthlete(AthleteEntity $athlete): array
{ {
$query = "INSERT INTO Athlete (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) $query = "INSERT INTO Athlete (nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach)

@ -20,8 +20,8 @@ class NotificationGateway
} }
public function addNotification(NotificationEntity $notif){ public function addNotification(NotificationEntity $notif){
$query = "INSERT INTO Notification (idnotif, message, date, statut, urgence, athleteid) VALUES (:idNotif, :message, :date, :statut, :urgence, :idAthlete)"; $query = "INSERT INTO Notification (message, date, statut, urgence, athleteid) VALUES (:message, :date, :statut, :urgence, :idAthlete)";
$params = [':idNotif'=>$notif->getIdNotif(), ':message'=>$notif->getMessage(), ':date'=>$notif->getDate(), ':statut'=>$notif->getStatut(), ':urgence'=>$notif->getUrgence(), ':idAthlete'=>$notif->getIdAthlete()]; $params = [':message'=>$notif->getMessage(), ':date'=>$notif->getDate(), ':statut'=>$notif->getStatut(), ':urgence'=>$notif->getUrgence(), ':idAthlete'=>$notif->getIdAthlete()];
return $this->connection->executeWithErrorHandling($query, $params); return $this->connection->executeWithErrorHandling($query, $params);
} }
} }
Loading…
Cancel
Save