add Athlete Manager ans her dependences
continuous-integration/drone/push Build is passing Details

issue_16_statistics_coach
Antoine PEREDERII 1 year ago
parent 7d8d8fa945
commit 208b134bc7

@ -92,11 +92,12 @@ function displaySocialManagementMenu()
{ {
clearScreen(); clearScreen();
echo "\n--- Gestion sociale ---\n"; echo "\n--- Gestion sociale ---\n";
echo "1. Rechercher des utilisateurs\n"; echo "1. Rechercher des coach\n";
echo "2. Gérer la liste d'amis\n"; echo "2. Rechercher des athletes\n";
echo "3. Gérer la liste d'amis\n";
// Ajouter des amis // Ajouter des amis
// Supprimer des amis ... // Supprimer des amis ...
echo "3. Options de partage\n"; echo "4. Options de partage\n";
echo "0. Retour au menu principal\n"; echo "0. Retour au menu principal\n";
echo "Choisissez une option: "; echo "Choisissez une option: ";
} }
@ -289,19 +290,6 @@ function ArrayTrainingMenu(DataManager $model)
switch ($coachChoice) { switch ($coachChoice) {
case '1': 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;
// ...
// ...
$existingTrainings = $model->coachMgr->getTrainingsList(); $existingTrainings = $model->coachMgr->getTrainingsList();
$lastTraining = end($existingTrainings); $lastTraining = end($existingTrainings);
$lastTrainingId = $lastTraining ? $lastTraining->getId() : 0; $lastTrainingId = $lastTraining ? $lastTraining->getId() : 0;
@ -474,6 +462,126 @@ function CoachMenu(DataManager $model)
} while($coachChoice); } while($coachChoice);
} }
//function displaySocialManagementMenu()
//{
// clearScreen();
// echo "\n--- Gestion sociale ---\n";
// echo "1. Rechercher des coach\n";
// echo "2. Rechercher des athletes\n";
// echo "3. Gérer la liste d'amis\n";
// // Ajouter des amis
// // Supprimer des amis ...
// echo "4. Options de partage\n";
// echo "0. Retour au menu principal\n";
// echo "Choisissez une option: ";
//}
function socialManagementMenu(DataManager $model) {
do {
displaySocialManagementMenu();
$managementChoice = trim(fgets(STDIN));
switch ($managementChoice) {
case '1': // echo "1. Rechercher des coach\n";
echo "Renseignez le surnom du coach que vous recherchez : ";
$coachUsername = trim(fgets(STDIN));
if (($coach = $model->athleteMgr->getCoachByName($coachUsername)) != null) {
$coach->__toString();
} else {
echo "Aucun coach de ce nom : $coachUsername\n";
}
sleep(2);
break;
case '2': // echo "1. Rechercher des athletes\n";
echo "Renseignez le surnom de l'athlete que vous recherchez : ";
$athleteUsername = trim(fgets(STDIN));
if (($athlete = $model->athleteMgr->getAthleteByName($athleteUsername)) != null) {
$athlete->__toString();
} else {
echo "Aucun athlete de ce nom : $athleteUsername\n";
}
sleep(2);
break;
case '3': // echo "3. Gérer la liste d'amis\n";
$arrayUsers = $model->coachMgr->getUsersList();
if (!empty($arrayUsers)) {
do {
clearScreen();
$cpt = 0;
foreach ($arrayUsers as $value) {
echo $cpt . " - " . $value->__toString() . "\n";
$cpt = $cpt + 1;
}
echo "Renseignez le numéro de l'utilisateur choisi : ";
$usernameNumber = trim(fgets(STDIN));
// Vérifier si l'index saisi est valide
if (isset($arrayUsers[$usernameNumber])) {
$selectedUser = $arrayUsers[$usernameNumber];
if (($arrayStats = $model->coachMgr->getStatistics($selectedUser))) {
foreach ($arrayStats as $value) {
echo $value->__toString() . "\n";
}
} else {
echo "Pas de statistiques valides présentent !\n";
}
} else {
echo "Numéro d'utilisateur non valide.\n";
$cpt = 0;
}
} while($cpt == 0);
} else {
echo "Aucun utilisateur dans la liste.\n";
}
sleep(2);
break;
case '4': // echo "4. Options de partage\n";
$arrayUsers = $model->coachMgr->getUsersList();
if (!empty($arrayUsers)) {
do {
clearScreen();
$cpt = 0;
foreach ($arrayUsers as $value) {
echo $cpt . " - " . $value->__toString() . "\n";
$cpt = $cpt + 1;
}
echo "Renseignez le numéro de l'utilisateur choisi : ";
$usernameNumber = trim(fgets(STDIN));
// Vérifier si l'index saisi est valide
if (isset($arrayUsers[$usernameNumber])) {
$selectedUser = $arrayUsers[$usernameNumber];
if (($arrayStats = $model->coachMgr->getAnalyse($selectedUser))) {
foreach ($arrayStats as $value) {
echo $value->__toString() . "\n";
}
} else {
echo "Pas d'Analyses valides présentent !\n";
}
} else {
echo "Numéro d'utilisateur non valide.\n";
$cpt = 0;
}
} while($cpt == 0);
} else {
echo "Aucun utilisateur dans la liste.\n";
}
sleep(2);
break;
case '0': // echo "0. Retour au menu principal\n";
return;
default:
echo "Option invalide. Veuillez réessayer.\n";
sleep(2);
break;
}
} while($managementChoice);
}
while (true) { while (true) {
$loggedIn = false; $loggedIn = false;
@ -531,8 +639,7 @@ while (true) {
break; break;
case '4': // Gestion sociale case '4': // Gestion sociale
displaySocialManagementMenu(); socialManagementMenu($model);
$socialChoice = trim(fgets(STDIN));
// TODO: Ajouter la logique pour les options de gestion sociale ici. // TODO: Ajouter la logique pour les options de gestion sociale ici.
break; break;

@ -38,12 +38,15 @@ class Athlete extends Role {
public function getTraining(): ?TrainingRepository{ public function getTraining(): ?TrainingRepository{
return null; return null;
} }
public function getTrainingsList(): ?array { // public function getTrainingsList(): ?array {
return $this->trainingRepository->getTrainingsList(); // if(foreach())
} // }
public function getTrainingList(Training $training): ?Training { public function getTrainingList(Training $training): ?Training {
return $training; return $training;
} }
public function setTrainingsList(array $newTrainingsList): void {
$this->trainingRepository->setTrainingsList($newTrainingsList);
}
public function CheckAdd(User $user): bool { public function CheckAdd(User $user): bool {
if($user instanceof \Model\Athlete){ if($user instanceof \Model\Athlete){
@ -87,6 +90,11 @@ class Athlete extends Role {
return true; return true;
} }
public function getTrainingsList(): ?array
{
// TODO: Implement getTrainingsList() method.
return null;
}
} }
?> ?>

@ -0,0 +1,109 @@
<?php
namespace Manager;
use Model\Athlete;
use Model\Coach;
use Model\CoachAthlete;
use Model\Training;
use Model\User;
use Stub\AuthService;
class AthleteManager {
private AuthService $authService;
function __construct(AuthService $authService)
{
$this->authService = $authService;
}
public function getCoachByName(String $coachUsername): ?User {
if(($coach = $this->authService->getUserRepository()->getItemByName($coachUsername, 0, 1)) instanceof CoachAthlete) {
return $coach;
}
return null;
}
public function getAthleteByName(String $athleteUsername): ?User {
if(($athlete =$this->authService->getUserRepository()->getItemByName($athleteUsername, 0, 1)) instanceof Athlete) {
return $athlete;
}
return null;
}
public function getUsersList(): ?array
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()->getUsersList()) {
return $this->authService->currentUser->getRole()->getUsersList();
}
return null;
}
public function getTrainingsList(): ?array {
foreach ($this->authService->getUserRepository()->getItemByRole() as $coach) {
foreach ($coach->getUsersList()->getUsername() as $username) {
if($this->authService->currentUser->getUsername() == $username) {
$this->authService->currentUser->getRole()->setTrainingsList($coach->getTrainingsList());
}
}
}
if ($this->authService->currentUser && $this->authService->currentUser->getRole()->getTrainingsList()) {
return $this->authService->currentUser->getRole()->getTrainingsList();
}
return null;
}
public function addUser(String $username): bool
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if(($user = $this->authService->getUserRepository()->GetItemByName($username,0,1))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->currentUser->getRole()->addUser($user)) {
return true;
}
}
}
return false;
}
public function removeUser(String $username): bool
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if(($user = $this->authService->getUserRepository()->GetItemByName($username,0,1))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->currentUser->getRole()->removeUser($user)) {
return true;
}
}
}
return false;
}
public function addTraining(Training $training): bool
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if ($this->authService->currentUser->getRole()->addTraining($training)) {
return true;
}
}
return false;
}
public function removeTraining(String $trainingId): bool
{
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if(($training = $this->authService->currentUser->getRole()->getTraining()->getItemById($trainingId))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->currentUser->getRole()->removeTraining($training)) {
return true;
}
}
}
return false;
}
// public function getStatistics(User $user) : ?Statistic {
// if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
// if (($arrayStat = $this->authService->currentUser->getRole()->getUserList($user)->getStatistic())) {
// return $arrayStat;
// }
// }
// return null;
// }
//
// public function getAnalyse(User $user): bool {
// return false;
// }
}
?>

@ -4,6 +4,7 @@ namespace Manager;
abstract class DataManager { abstract class DataManager {
public $userMgr; public $userMgr;
public $coachMgr; public $coachMgr;
public $athleteMgr;
} }

@ -1,8 +1,9 @@
<?php <?php
namespace Stub; namespace Stub;
use Model\Athlete;
use Shared\HashPassword; use Shared\HashPassword;
use Stub\AuthService; use Stub\AuthService;
use Manager\{CoachManager, DataManager, UserManager}; use Manager\{AthleteManager, CoachManager, DataManager, UserManager};
use Stub\UserRepository; use Stub\UserRepository;
class StubData extends DataManager { class StubData extends DataManager {
@ -13,9 +14,8 @@ class StubData extends DataManager {
$this->userMgr = new UserManager($authService); $this->userMgr = new UserManager($authService);
// if($this->userMgr->currentUser != null){
$this->coachMgr = new CoachManager($authService); $this->coachMgr = new CoachManager($authService);
// } $this->athleteMgr = new AthleteManager($authService);
} }
} }

@ -31,6 +31,15 @@ class UserRepository implements IUserRepository {
return null; return null;
} }
public function getItemByRole():?User{
foreach ($this->users as $user) {
if ($user->getRole() instanceof \Model\Coach) {
return $user;
}
}
return null;
}
public function getItemByEmail(string $email): ?User { public function getItemByEmail(string $email): ?User {
foreach ($this->users as $user) { foreach ($this->users as $user) {
if ($user->getEmail() === $email) { if ($user->getEmail() === $email) {

Loading…
Cancel
Save