add Athlete Manager ans her dependences
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
7d8d8fa945
commit
208b134bc7
@ -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;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in new issue