You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Web/Sources/src/data/model/manager/CoachManager.php

95 lines
3.2 KiB

<?php
namespace Manager;
use Model\Coach;
use Model\Role;
use Model\Statistic;
use Model\User;
use \Model\Training;
use Network\IAuthService;
use Stub\AuthService;
use Stub\TrainingRepository;
use Stub\UserRepository;
class CoachManager
{
// public ?User $currentUser = null; // Initialisé à null
private AuthService $authService;
function __construct(AuthService $authService)
{
$this->authService = $authService;
}
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 {
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;
// }
}
?>