update training add in coach
continuous-integration/drone/push Build is passing Details

issue_16_statistics_coach
Antoine PEREDERII 1 year ago
parent d61d120f08
commit a8035d5be0

@ -2,9 +2,11 @@
namespace Console; namespace Console;
use DateTime;
use Model\Athlete; use Model\Athlete;
use Model\Coach; use Model\Coach;
use Model\Role; use Model\Role;
use Model\Training;
use Stub\StubData; use Stub\StubData;
use Manager\DataManager; use Manager\DataManager;
@ -287,22 +289,50 @@ function ArrayTrainingMenu(DataManager $model)
switch ($coachChoice) { switch ($coachChoice) {
case '1': case '1':
echo "Renseignez l'id de l'entrainement : "; // echo "Renseignez l'id de l'entrainement : ";
$idTraining = trim(fgets(STDIN)); // $idTraining = trim(fgets(STDIN));
if($model->coachMgr->addTraining($idTraining)){ // if($model->coachMgr->addTraining($idTraining)){
// echo "Ajout avec succès !";
// } else {
// echo "Pb ajout !";
// }
// sleep(2);
// break;
// ...
// ...
$existingTrainings = $model->coachMgr->getTrainingsList();
$lastTraining = end($existingTrainings);
$lastTrainingId = $lastTraining ? $lastTraining->getId() : 0;
$newTrainingId = $lastTrainingId + 1;
echo "L'ID de l'entraînement sera automatiquement défini sur : $newTrainingId\n";
$date = new DateTime();
echo "Renseignez la latitude de l'entraînement : ";
$latitude = trim(fgets(STDIN));
echo "Renseignez la longitude de l'entraînement : ";
$longitude = trim(fgets(STDIN));
echo "Renseignez la description de l'entraînement : ";
$description = trim(fgets(STDIN));
$training = new Training($newTrainingId, $date, $latitude, $longitude, $description, null);
if($model->coachMgr->addTraining($training)){
echo "Ajout avec succès !"; echo "Ajout avec succès !";
} else { } else {
echo "Pb ajout !"; echo "Pb ajout !";
} }
sleep(2); sleep(2);
break; break;
case '2': case '2':
echo "Renseignez l'id de l'entrainement : "; echo "Renseignez l'id de l'entrainement : ";
$idTraining = trim(fgets(STDIN)); $idTraining = trim(fgets(STDIN));
if($model->coachMgr->removeTraining($idTraining)){ if($model->coachMgr->removeTraining($idTraining)){
echo "Suppression avec succès !"; echo "Suppression avec succès !";
} else { } else {
echo "Pb suppression ou aucun utilisateur de ce nom !"; echo "Pb suppression ou aucun entrainement de cet id !";
} }
sleep(2); sleep(2);
break; break;

@ -18,7 +18,7 @@ class CoachAthlete extends Coach {
public function getUserList(User $user): User { public function getUserList(User $user): User {
foreach ($this->usersList as $existingUser) { foreach ($this->usersList as $existingUser) {
if ($existingUser->getId() === $user->getId()) { if ($existingUser->getId() === $user->getId()) {
return $user; // L'utilisateur est présent dans la liste return $existingUser; // L'utilisateur est présent dans la liste
} }
} }
return null; // L'utilisateur n'est pas dans la liste return null; // L'utilisateur n'est pas dans la liste
@ -35,7 +35,7 @@ class CoachAthlete extends Coach {
public function getTrainingList(Training $training): ?Training { public function getTrainingList(Training $training): ?Training {
foreach ($this->trainingRepository->getTrainingsList() as $existingTraining) { foreach ($this->trainingRepository->getTrainingsList() as $existingTraining) {
if ($existingTraining->getId() === $training->getId()) { if ($existingTraining->getId() === $training->getId()) {
return $training; // L'utilisateur est présent dans la liste return $existingTraining; // L'utilisateur est présent dans la liste
} }
} }
return null; // L'utilisateur n'est pas dans la liste return null; // L'utilisateur n'est pas dans la liste
@ -64,8 +64,8 @@ class CoachAthlete extends Coach {
$key = array_search($user, $this->usersList); $key = array_search($user, $this->usersList);
if ($key !== false) { if ($key !== false) {
array_splice($this->usersList, $key, 1); array_splice($this->usersList, $key, 1);
return true;
} }
return true;
} }
return false; return false;
} }
@ -81,10 +81,10 @@ class CoachAthlete extends Coach {
$array = (array)$this->trainingRepository->getTrainingsList(); $array = (array)$this->trainingRepository->getTrainingsList();
$key = array_search($training, $array); $key = array_search($training, $array);
if ($key !== false) { if ($key !== false) {
$trainingsList = $this->trainingRepository->getTrainingsList(); array_splice($array, $key, 1);
array_splice($trainingsList, $key, 1); $this->trainingRepository->setTrainingsList($array);
return true;
} }
return true;
} }
return false; return false;
} }

@ -11,16 +11,16 @@ class Training
private \DateTime $date; private \DateTime $date;
private float $latitude; private float $latitude;
private float $longitude; private float $longitude;
private String $description; private ?String $description;
private String $feedback; private ?String $feedback;
public function __construct( public function __construct(
int $idTraining, int $idTraining,
\DateTime $date, \DateTime $date,
float $latitude, float $latitude,
float $longitude, float $longitude,
?String $description, ?String $description = null,
?String $feedback ?String $feedback = null
) { ) {
$this->idTraining = $idTraining; $this->idTraining = $idTraining;
$this->date = $date; $this->date = $date;
@ -29,32 +29,6 @@ class Training
$this->description = $description; $this->description = $description;
$this->feedback = $feedback; $this->feedback = $feedback;
} }
public function __construct_Coach(
int $idTraining,
\DateTime $date,
float $latitude,
float $longitude,
String $description
) {
$this->idTraining = $idTraining;
$this->date = $date;
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->description = $description;
}
public function __construct_Athlete(
int $idTraining,
\DateTime $date,
float $latitude,
float $longitude,
String $feedback
) {
$this->idTraining = $idTraining;
$this->date = $date;
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->feedback = $feedback;
}
public function getId():int { public function getId():int {
return $this->idTraining; return $this->idTraining;
} }

@ -16,16 +16,11 @@ 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 getTrainingRepository():TrainingRepository {
return $this->trainingRepository;
}
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()) {
@ -48,7 +43,7 @@ class CoachManager
} }
} }
} }
return false; return false;
} }
public function removeUser(String $username): bool public function removeUser(String $username): bool
{ {
@ -61,13 +56,11 @@ class CoachManager
} }
return false; return false;
} }
public function addTraining(String $trainingId): bool public function addTraining(Training $training): bool
{ {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) { 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()->addTraining($training)) {
if ($this->authService->currentUser->getRole()->addTraining($training)) { return true;
return true;
}
} }
} }
return false; return false;

@ -22,10 +22,14 @@ class TrainingRepository implements ITrainingRepository {
/** /**
* @return array * @return array
*/ */
public function getTrainingsList(): array { public function &getTrainingsList(): array {
return $this->trainingsList; return $this->trainingsList;
} }
public function setTrainingsList(array $trainingsList): void {
$this->trainingsList = $trainingsList;
}
public function getItemById(int $id): ?Training { public function getItemById(int $id): ?Training {
foreach ($this->trainingsList as $training) { foreach ($this->trainingsList as $training) {
if ($training->getId() === $id) { if ($training->getId() === $id) {

Loading…
Cancel
Save