💩 🚧 add TrainingRepository and and Training Menu in Console.php
continuous-integration/drone/push Build is passing Details

issue_16_statistics_coach
Antoine PEREDERII 1 year ago
parent 5c925326a9
commit a696e4eb5a

@ -81,6 +81,7 @@ function displayCoachMenu()
echo "3. Analyses par athlète\n"; echo "3. Analyses par athlète\n";
echo "4. Gérer la liste de mes athlètes\n"; echo "4. Gérer la liste de mes athlètes\n";
// Gérer les athlètes (comprend : Ajouter un athlète, Supprimer un athlète, Consulter les statistiques d'un athlète) // Gérer les athlètes (comprend : Ajouter un athlète, Supprimer un athlète, Consulter les statistiques d'un athlète)
echo "5. Gérer la liste de mes exercices\n";
echo "0. Retour au menu principal\n"; echo "0. Retour au menu principal\n";
echo "Choisissez une option: "; echo "Choisissez une option: ";
} }
@ -110,6 +111,34 @@ function displaySettingsMenu()
echo "0. Retour au menu principal\n"; echo "0. Retour au menu principal\n";
echo "Choisissez une option: "; echo "Choisissez une option: ";
} }
function displayManagementArrayAthlete()
{
clearScreen();
echo "\n--- Menu Management Groupe Athlete ---\n";
echo "1. Ajouter un athlète\n";
echo "2. Supprimer un athlète\n";
echo "3. Voir tout les athlètes de la liste\n";
echo "0. Retour au menu du coach\n";
echo "Choisissez une option: ";
}
function displayManagementArrayTraining()
{
clearScreen();
echo "\n--- Menu Management des entrainements ---\n";
echo "1. Ajouter un entrainement\n";
echo "2. Supprimer un entrainement\n";
echo "3. Voir tout les entrainements de la liste\n";
echo "0. Retour au menu du coach\n";
echo "Choisissez une option: ";
}
/**
* Fonction permettant à un utilisateur de se connecter.
*
* @param DataManager $model La couche d'accès au modèle de données.
* @return bool Retourne true si l'utilisateur s'est connecté avec succès, sinon false.
*/
function loginUser(DataManager $model) function loginUser(DataManager $model)
{ {
try { try {
@ -133,7 +162,12 @@ function loginUser(DataManager $model)
} }
} }
/**
* Fonction permettant à un utilisateur de s'inscrire.
*
* @param DataManager $model La couche d'accès au modèle de données.
* @return bool Retourne true si l'inscription a réussi, sinon false.
*/
function registerUser(DataManager $model) function registerUser(DataManager $model)
{ {
try { try {
@ -197,21 +231,10 @@ function registerUser(DataManager $model)
} }
} }
function displayManagementArray() function ArrayAthleteMenu(DataManager $model)
{
clearScreen();
echo "\n--- Menu Management Groupe Athlete ---\n";
echo "1. Ajouter un athlète\n";
echo "2. Supprimer un athlète\n";
echo "3. Voir tout les athlètes de la liste\n";
echo "0. Retour au menu du coach\n";
echo "Choisissez une option: ";
}
function ArrayMenu(DataManager $model)
{ {
do { do {
displayManagementArray(); displayManagementArrayAthlete();
$coachChoice = trim(fgets(STDIN)); $coachChoice = trim(fgets(STDIN));
switch ($coachChoice) { switch ($coachChoice) {
@ -256,6 +279,54 @@ function ArrayMenu(DataManager $model)
} while($coachChoice); } while($coachChoice);
} }
function ArrayTrainingMenu(DataManager $model)
{
do {
displayManagementArrayTraining();
$coachChoice = trim(fgets(STDIN));
switch ($coachChoice) {
case '1':
echo "Renseignez l'id de l'entrainement : ";
$idTraining = trim(fgets(STDIN));
if($model->coachMgr->addTraining($idTraining)){
echo "Ajout avec succès !";
} else {
echo "Pb ajout !";
}
sleep(2);
break;
case '2':
echo "Renseignez l'id de l'entrainement : ";
$idTraining = trim(fgets(STDIN));
if($model->coachMgr->removeTraining($idTraining)){
echo "Suppression avec succès !";
} else {
echo "Pb suppression ou aucun utilisateur de ce nom !";
}
sleep(2);
break;
case '3':
$trainingArray = $model->coachMgr->getTrainingsList();
if (!empty($trainingArray)) {
foreach ($trainingArray as $value) {
echo $value->__toString() . "\n";
}
} else {
echo "Aucun entrainement dans la liste\n";
}
sleep(2);
break;
case '0':
return;
default :
echo "Option invalide. Veuillez réessayer.\n";
sleep(2);
break;
}
} while($coachChoice);
}
//function displayCoachMenu() //function displayCoachMenu()
//{ //{
// clearScreen(); // clearScreen();
@ -265,6 +336,7 @@ function ArrayMenu(DataManager $model)
// echo "3. Analyses par athlète\n"; // echo "3. Analyses par athlète\n";
// echo "4. Gérer la liste de mes athlètes\n"; // echo "4. Gérer la liste de mes athlètes\n";
// // Gérer les athlètes (comprend : Ajouter un athlète, Supprimer un athlète, Consulter les statistiques d'un athlète) // // Gérer les athlètes (comprend : Ajouter un athlète, Supprimer un athlète, Consulter les statistiques d'un athlète)
// echo "5. Gérer la liste de mes exercices\n";
// echo "0. Retour au menu principal\n"; // echo "0. Retour au menu principal\n";
// echo "Choisissez une option: "; // echo "Choisissez une option: ";
//} //}
@ -357,7 +429,10 @@ function CoachMenu(DataManager $model)
sleep(2); sleep(2);
break; break;
case '4': // echo "4. Gérer la liste de mes athlètes\n"; case '4': // echo "4. Gérer la liste de mes athlètes\n";
ArrayMenu($model); ArrayAthleteMenu($model);
break;
case '5': // echo "5. Gérer la liste de mes exercices\n";
ArrayTrainingMenu($model);
break; break;
case '0': // Quitter case '0': // Quitter
return; return;

@ -3,7 +3,7 @@
namespace Model; namespace Model;
class CoachAthlete extends Coach { class CoachAthlete extends Coach {
private Training $arrayTraining; private array $trainingsList = [];
public function getUsersList(): ?array { public function getUsersList(): ?array {
if (!empty($this->usersList)) { if (!empty($this->usersList)) {
return $this->usersList; return $this->usersList;
@ -18,12 +18,32 @@ class CoachAthlete extends Coach {
} }
return null; // L'utilisateur n'est pas dans la liste return null; // L'utilisateur n'est pas dans la liste
} }
public function getTrainingsList(): ?array {
if (!empty($this->trainingsList)) {
return $this->trainingsList;
}
return null;
}
public function getTrainingList(Training $training): ?Training {
foreach ($this->trainingsList as $existingTraining) {
if ($existingTraining->getId() === $training->getId()) {
return $training; // L'utilisateur est présent dans la liste
}
}
return null; // L'utilisateur n'est pas dans la liste
}
public function CheckAdd(User $user) : bool { public function CheckAdd(User $user) : bool {
if($user->getRole() instanceof \Model\Athlete){ if($user->getRole() instanceof \Model\Athlete){
return true; return true;
} }
return false; return false;
} }
public function CheckAddTraining(Training $training) : bool {
if($training instanceof \Model\Training){
return true;
}
return false;
}
public function addUser(User $user): bool { public function addUser(User $user): bool {
if($this->CheckAdd($user)){ if($this->CheckAdd($user)){
array_push($this->usersList, $user); array_push($this->usersList, $user);
@ -41,4 +61,21 @@ class CoachAthlete extends Coach {
} }
return false; return false;
} }
public function addTraining(Training $training): bool {
if($this->CheckAddTraining($training)){
array_push($this->trainingsList, $training);
return true;
}
return false;
}
public function removeTraining(Training $training): bool {
if($this->CheckAddTraining($training)){
$key = array_search($training, $this->trainingsList);
if ($key !== false) {
array_splice($this->trainingsList, $key, 1);
}
return true;
}
return false;
}
} }

@ -19,14 +19,14 @@ class Training
public function getDate():String { public function getDate():String {
return $this->date; return $this->date;
} }
public function getLocation():String { public function getLocation(): String {
return $this->longitude . $this->latitude; return $this->longitude . $this->latitude;
} }
public function getDescription(): Text public function getDescription(): Text
{ {
return $this->description; return $this->description;
} }
public function getFeedback():Text { public function getFeedback(): Text {
return $this->feedback; return $this->feedback;
} }
} }

@ -6,29 +6,26 @@ use Model\Coach;
use Model\Role; use Model\Role;
use Model\Statistic; use Model\Statistic;
use Model\User; use Model\User;
use \Model\Training;
use Network\IAuthService; use Network\IAuthService;
use Stub\AuthService; use Stub\AuthService;
use Stub\TrainingRepository;
use Stub\UserRepository;
class CoachManager class CoachManager
{ {
// public ?User $currentUser = null; // Initialisé à null // public ?User $currentUser = null; // Initialisé à null
private AuthService $authService; private AuthService $authService;
private TrainingRepository $trainingRepository;
function __construct(AuthService $authService) function __construct(AuthService $authService)
{ {
$this->authService = $authService; $this->authService = $authService;
} }
public function getRole(): void public function getTrainingRepository():TrainingRepository {
{ return $this->trainingRepository;
// Assurez-vous que currentUser n'est pas null avant d'accéder à getRole()
// if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
// return $this->authService->currentUser->getRole();
// }
var_dump($this->authService->currentUser->getRole());
// return null;
} }
public function getUsersList(): ?array public function getUsersList(): ?array
{ {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()->getUsersList()) { if ($this->authService->currentUser && $this->authService->currentUser->getRole()->getUsersList()) {
@ -36,6 +33,12 @@ class CoachManager
} }
return null; return null;
} }
public function getTrainingsList(): ?array {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()->getTrainingsList()) {
return $this->authService->currentUser->getRole()->getTrainingsList();
}
return null;
}
public function addUser(String $username): bool public function addUser(String $username): bool
{ {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) { if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
@ -58,6 +61,28 @@ class CoachManager
} }
return false; return false;
} }
public function addTraining(String $training): bool
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if(($training = $this->authService->getTrainingRepository()->GetItemByName($training,0,1))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->currentUser->getRole()->addTraining($training)) {
return true;
}
}
}
return false;
}
public function removeTraining(String $training): bool
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if(($user = $this->authService->getTrainingRepository()->GetItemByName($training,0,1))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->currentUser->getRole()->removeUser($user)) {
return true;
}
}
}
return false;
}
// public function getStatistics(User $user) : ?Statistic { // public function getStatistics(User $user) : ?Statistic {
// if ($this->authService->currentUser && $this->authService->currentUser->getRole()) { // if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {

@ -0,0 +1,8 @@
<?php
namespace Repository;
interface ITrainingRepository extends IGenericRepository {
}
?>

@ -0,0 +1,73 @@
<?php
namespace Stub;
use Model\Athlete;
use Model\CoachAthlete;
use Model\Training;
use Model\User;
use Repository\ITrainingRepository;
class TrainingRepository implements ITrainingRepository {
private array $training = [];
public function __construct() {
$this->training[] = new Training(1, new \DateTime("1985-05-10"), 48.5, 55.8, "john.doe@example.com", "hello");
$this->training[] = new Training(2, new \DateTime("1986-06-12"), 48.5, 55.8, "john.doe@exavdffgmple.com", "hedfdfllo");
$this->training[] = new Training(3, new \DateTime("1989-07-14"), 48.5, 55.8, "john.doe@exdfdfample.com", "hedfdfllo");
$this->training[] = new Training(4, new \DateTime("1990-08-16"), 48.5, 55.8, "john.doe@exdfdfample.com", "hedffdllo");
$this->training[] = new Training(5, new \DateTime("2000-09-18"), 48.5, 55.8, "john.doe@exdffdample.com", "hedfdfllo");
}
public function getItemById(int $id): ?Training {
foreach ($this->training as $training) {
if ($training->getId() === $id) {
return $training;
}
}
return null;
}
public function GetNbItems(): int {
return count($this->training);
}
public function GetItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
// Cette méthode est un exemple simple, on ne gère pas l'ordonnancement ici
return array_slice($this->training, $index, $count);
}
public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
$filteredTrainings = array_filter($this->training, function ($training) use ($substring) {
return strpos(strtolower($training->getDescription()), strtolower($substring)) !== false || strpos(strtolower($training->getFeedback()), strtolower($substring)) !== false;
});
return array_slice($filteredTrainings, $index, $count);
}
public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): ?Training {
$filteredTrainings = $this->GetItemsByName($substring, $index, $count, $orderingPropertyName, $descending);
return isset($filteredTrainings[0]) ? $filteredTrainings[0] : null;
}
// should have type here
public function UpdateItem($oldTraining, $newTraining): void {
$index = array_search($oldTraining, $this->training);
if ($index !== false) {
$this->training[$index] = $newTraining;
}
}
// should have type here
public function AddItem($training): void {
$this->training[] = $training;
}
// should have type here
public function DeleteItem($training): bool {
$index = array_search($training, $this->training);
if ($index !== false) {
unset($this->training[$index]);
return true;
}
return false;
}
}
Loading…
Cancel
Save