🚧 🧪 add Listing TrainingList
continuous-integration/drone/push Build is passing Details

issue_16_statistics_coach
Antoine PEREDERII 1 year ago
parent a696e4eb5a
commit d61d120f08

File diff suppressed because it is too large Load Diff

@ -2,11 +2,17 @@
namespace Model; namespace Model;
use Stub\TrainingRepository;
class Athlete extends Role { class Athlete extends Role {
// Attributs spécifiques a l'athlete si nécessaire // Attributs spécifiques a l'athlete si nécessaire
private array $arrayStats = []; private array $arrayStats = [];
private array $arrayActivities = []; private array $arrayActivities = [];
private array $arrayDateSources = []; private array $arrayDateSources = [];
public function __construct(?TrainingRepository $trainingRepository) {
$this->trainingRepository = $trainingRepository;
}
public function getAthlete():Athlete { public function getAthlete():Athlete {
return $this; return $this;
} }
@ -29,14 +35,26 @@ class Athlete extends Role {
public function getUserList(User $user): \Model\User{ public function getUserList(User $user): \Model\User{
return $user; return $user;
} }
private function CheckAdd(User $user) public function getTraining(): ?TrainingRepository{
{ return null;
}
public function getTrainingsList(): ?array {
return $this->trainingRepository->getTrainingsList();
}
public function getTrainingList(Training $training): ?Training {
return $training;
}
public function CheckAdd(User $user): bool {
if($user instanceof \Model\Athlete){ if($user instanceof \Model\Athlete){
return true; return true;
} else { } else {
return false; return false;
} }
} }
public function CheckAddTraining(Training $training) : bool {
return false;
}
public function addUser(\Model\User $user): bool public function addUser(\Model\User $user): bool
{ {
if($this->CheckAdd($user)){ if($this->CheckAdd($user)){
@ -62,6 +80,13 @@ class Athlete extends Role {
return false; return false;
} }
public function addTraining(Training $training): bool {
return false;
}
public function removeTraining(Training $training): bool {
return true;
}
} }
?> ?>

@ -1,13 +1,25 @@
<?php <?php
namespace Model; namespace Model;
use Stub\TrainingRepository;
abstract class Coach extends Role { abstract class Coach extends Role {
public abstract function addUser(User $user): bool;
public abstract function removeUser(User $user): bool; public abstract function __construct(?TrainingRepository $trainingRepository);
public abstract function CheckAdd(User $user) : bool;
// Méthode pour obtenir la liste des utilisateurs
public abstract function getUsersList(): ?array; public abstract function getUsersList(): ?array;
public abstract function getUserList(User $user): \Model\User; public abstract function getUserList(User $user): \Model\User;
public abstract function getTraining(): ?TrainingRepository;
public abstract function getTrainingsList(): ?array;
public abstract function getTrainingList(Training $training): ?Training;
public abstract function CheckAdd(User $user) : bool;
public abstract function CheckAddTraining(Training $training) : bool;
public abstract function addUser(User $user): bool;
public abstract function removeUser(User $user): bool;
public abstract function addTraining(Training $training): bool;
public abstract function removeTraining(Training $training): bool;
} }
?> ?>

@ -2,8 +2,13 @@
namespace Model; namespace Model;
use Stub\TrainingRepository;
class CoachAthlete extends Coach { class CoachAthlete extends Coach {
private array $trainingsList = [];
public function __construct(?TrainingRepository $trainingRepository) {
$this->trainingRepository = $trainingRepository;
}
public function getUsersList(): ?array { public function getUsersList(): ?array {
if (!empty($this->usersList)) { if (!empty($this->usersList)) {
return $this->usersList; return $this->usersList;
@ -18,14 +23,17 @@ 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 getTraining(): TrainingRepository {
return $this->trainingRepository;
}
public function getTrainingsList(): ?array { public function getTrainingsList(): ?array {
if (!empty($this->trainingsList)) { if (!empty($this->trainingRepository->getTrainingsList())) {
return $this->trainingsList; return $this->trainingRepository->getTrainingsList();
} }
return null; return null;
} }
public function getTrainingList(Training $training): ?Training { public function getTrainingList(Training $training): ?Training {
foreach ($this->trainingsList 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 $training; // L'utilisateur est présent dans la liste
} }
@ -63,16 +71,18 @@ class CoachAthlete extends Coach {
} }
public function addTraining(Training $training): bool { public function addTraining(Training $training): bool {
if($this->CheckAddTraining($training)){ if($this->CheckAddTraining($training)){
array_push($this->trainingsList, $training); $this->trainingRepository->getTrainingsList()[] = $training;
return true; return true;
} }
return false; return false;
} }
public function removeTraining(Training $training): bool { public function removeTraining(Training $training): bool {
if($this->CheckAddTraining($training)){ if($this->CheckAddTraining($training)){
$key = array_search($training, $this->trainingsList); $array = (array)$this->trainingRepository->getTrainingsList();
$key = array_search($training, $array);
if ($key !== false) { if ($key !== false) {
array_splice($this->trainingsList, $key, 1); $trainingsList = $this->trainingRepository->getTrainingsList();
array_splice($trainingsList, $key, 1);
} }
return true; return true;
} }

@ -1,32 +1,33 @@
<?php <?php
namespace Model; namespace Model;
use PhpParser\Node\Expr\Array_;
use Model\User; use Model\User;
use PhpParser\Node\Expr\Array_;
use Model\Coach; use Model\Coach;
use Stub\TrainingRepository;
abstract class Role { abstract class Role {
private int $id; private int $id;
protected array $usersList = []; protected array $usersList = [];
protected ?TrainingRepository $trainingRepository;
// Méthode pour ajouter un utilisateur à la liste public abstract function __construct(?TrainingRepository $trainingRepository);
/**
* @param User $user
* @return void
*/
public abstract function addUser(User $user): bool;
public abstract function removeUser(User $user): bool;
// public function removeUser(User $user): void { // Méthode pour ajouter un utilisateur à la liste
// $this->usersList[]
// }
/**
* @return void
*/
public abstract function getUsersList(): ?array; public abstract function getUsersList(): ?array;
public abstract function getUserList(User $user): \Model\User; public abstract function getUserList(User $user): \Model\User;
public abstract function getTraining(): ?TrainingRepository;
public abstract function getTrainingsList(): ?array;
public abstract function getTrainingList(Training $training): ?Training;
public abstract function CheckAdd(User $user) : bool;
public abstract function CheckAddTraining(Training $training) : bool;
public abstract function addUser(User $user): bool;
public abstract function removeUser(User $user): bool;
public abstract function addTraining(Training $training): bool;
public abstract function removeTraining(Training $training): bool;
} }

@ -8,25 +8,71 @@ use SebastianBergmann\CodeCoverage\Report\Text;
class Training class Training
{ {
private int $idTraining; private int $idTraining;
private Date $date; private \DateTime $date;
private float $latitude; private float $latitude;
private float $longitude; private float $longitude;
private text $description; private String $description;
private text $feedback; private String $feedback;
public function getId():String {
return $this->getId(); public function __construct(
int $idTraining,
\DateTime $date,
float $latitude,
float $longitude,
?String $description,
?String $feedback
) {
$this->idTraining = $idTraining;
$this->date = $date;
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->description = $description;
$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 getDate():String { public function getId():int {
return $this->idTraining;
}
public function getDate():\DateTime {
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(): String
{ {
return $this->description; return $this->description;
} }
public function getFeedback(): Text { public function getFeedback(): String {
return $this->feedback; return $this->feedback;
} }
public function __toString(): String {
return $this->idTraining . " - " . $this->description;
}
} }

@ -61,10 +61,10 @@ class CoachManager
} }
return false; return false;
} }
public function addTraining(String $training): bool public function addTraining(String $trainingId): bool
{ {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) { 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(($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;
} }
@ -72,11 +72,11 @@ class CoachManager
} }
return false; return false;
} }
public function removeTraining(String $training): bool public function removeTraining(String $trainingId): bool
{ {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) { 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(($training = $this->authService->currentUser->getRole()->getTraining()->getItemById($trainingId))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->currentUser->getRole()->removeUser($user)) { if ($this->authService->currentUser->getRole()->removeTraining($training)) {
return true; return true;
} }
} }

@ -6,7 +6,7 @@ interface IGenericRepository
public function getItemById(int $id); public function getItemById(int $id);
public function GetNbItems(): int; public function GetNbItems(): int;
public function GetItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array; public function GetItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array;
public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array; public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): ?array;
public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false); public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false);
public function UpdateItem($oldItem, $newItem) : void; public function UpdateItem($oldItem, $newItem) : void;
public function AddItem($item) : void; public function AddItem($item) : void;

@ -9,18 +9,25 @@ use Model\User;
use Repository\ITrainingRepository; use Repository\ITrainingRepository;
class TrainingRepository implements ITrainingRepository { class TrainingRepository implements ITrainingRepository {
private array $training = []; private array $trainingsList = [];
public function __construct() { public function __construct() {
$this->training[] = new Training(1, new \DateTime("1985-05-10"), 48.5, 55.8, "john.doe@example.com", "hello"); $this->trainingsList[] = 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->trainingsList[] = new Training(2, new \DateTime("1986-06-12"), 48.5, 55.8, "john.doe@exavdffgmple.com", "hedfdffllo");
$this->training[] = new Training(3, new \DateTime("1989-07-14"), 48.5, 55.8, "john.doe@exdfdfample.com", "hedfdfllo"); $this->trainingsList[] = 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->trainingsList[] = new Training(4, new \DateTime("1990-08-16"), 48.5, 55.8, "john.doe@exdfdfample.com", "hedffhdllo");
$this->training[] = new Training(5, new \DateTime("2000-09-18"), 48.5, 55.8, "john.doe@exdffdample.com", "hedfdfllo"); $this->trainingsList[] = new Training(5, new \DateTime("2000-09-18"), 48.5, 55.8, "john.doe@exdffdample.com", "hedfdfgllo");
}
/**
* @return array
*/
public function getTrainingsList(): array {
return $this->trainingsList;
} }
public function getItemById(int $id): ?Training { public function getItemById(int $id): ?Training {
foreach ($this->training as $training) { foreach ($this->trainingsList as $training) {
if ($training->getId() === $id) { if ($training->getId() === $id) {
return $training; return $training;
} }
@ -29,45 +36,47 @@ class TrainingRepository implements ITrainingRepository {
} }
public function GetNbItems(): int { public function GetNbItems(): int {
return count($this->training); return count($this->trainingsList);
} }
public function GetItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array { 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 // Cette méthode est un exemple simple, on ne gère pas l'ordonnancement ici
return array_slice($this->training, $index, $count); return array_slice($this->trainingsList, $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 // should have type here
public function UpdateItem($oldTraining, $newTraining): void { public function UpdateItem($oldTraining, $newTraining): void {
$index = array_search($oldTraining, $this->training); $index = array_search($oldTraining, $this->trainingsList);
if ($index !== false) { if ($index !== false) {
$this->training[$index] = $newTraining; $this->trainingsList[$index] = $newTraining;
} }
} }
// should have type here // should have type here
public function AddItem($training): void { public function AddItem($training): void {
$this->training[] = $training; $this->trainingsList[] = $training;
} }
// should have type here // should have type here
public function DeleteItem($training): bool { public function DeleteItem($training): bool {
$index = array_search($training, $this->training); $index = array_search($training, $this->trainingsList);
if ($index !== false) { if ($index !== false) {
unset($this->training[$index]); unset($this->trainingsList[$index]);
return true; return true;
} }
return false; return false;
} }
public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): ?array
{
return null;
// TODO: Implement GetItemsByName() method.
}
public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false)
{
return null;
// TODO: Implement GetItemByName() method.
}
} }

@ -12,13 +12,14 @@ class UserRepository implements IUserRepository {
private array $users = []; private array $users = [];
public function __construct() { public function __construct() {
$this->users[] = new User(1, "Doe", "Doe", "John", "john.doe@example.com", "password123", 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete()); $training = new \Stub\TrainingRepository();
$this->users[] = new User(2, "Smith", "Smith", "Jane", "jane.smith@example.com", "secure456", 'F', 1.65, 60, new \DateTime("1990-03-10"), new Athlete()); $this->users[] = new User(1, "Doe", "Doe", "John", "john.doe@example.com", "password123", 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete($training));
$this->users[] = new User(3, "Martin", "Martin", "Paul", "paul.martin@example.com", "super789", 'M', 1.75, 68, new \DateTime("1988-08-20"), new CoachAthlete()); $this->users[] = new User(2, "Smith", "Smith", "Jane", "jane.smith@example.com", "secure456", 'F', 1.65, 60, new \DateTime("1990-03-10"), new Athlete(null));
$this->users[] = new User(4, "Brown", "Brown", "Anna", "anna.brown@example.com", "test000", 'F', 1.70, 58, new \DateTime("1992-11-25"), new Athlete()); $this->users[] = new User(3, "Martin", "Martin", "Paul", "paul.martin@example.com", "super789", 'M', 1.75, 68, new \DateTime("1988-08-20"), new CoachAthlete($training));
$this->users[] = new User(5, "Lee", "Lee", "Bruce", "bruce.lee@example.com", "hello321", 'M', 1.72, 70, new \DateTime("1970-02-05"), new Athlete()); $this->users[] = new User(4, "Brown", "Brown", "Anna", "anna.brown@example.com", "test000", 'F', 1.70, 58, new \DateTime("1992-11-25"), new Athlete(null));
$this->users[] = new User(6, "c", "c", "c", "coach@example.com", "c1", 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete()); $this->users[] = new User(5, "Lee", "Lee", "Bruce", "bruce.lee@example.com", "hello321", 'M', 1.72, 70, new \DateTime("1970-02-05"), new Athlete(null));
$this->users[] = new User(7, "athlete", "athlete", "a", "athlete@example.com", "hello321", 'F', 1.55, 67, new \DateTime("1999-09-30"), new Athlete()); $this->users[] = new User(6, "c", "c", "c", "coach@example.com", "c1", 'M', 1.80, 75, new \DateTime("1985-05-15"), new CoachAthlete($training));
$this->users[] = new User(7, "athlete", "athlete", "a", "athlete@example.com", "hello321", 'F', 1.55, 67, new \DateTime("1999-09-30"), new Athlete(null));
} }
public function getItemById(int $id): ?User { public function getItemById(int $id): ?User {
@ -48,7 +49,7 @@ class UserRepository implements IUserRepository {
return array_slice($this->users, $index, $count); return array_slice($this->users, $index, $count);
} }
public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array { public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): ?array {
$filteredUsers = array_filter($this->users, function ($user) use ($substring) { $filteredUsers = array_filter($this->users, function ($user) use ($substring) {
return strpos(strtolower($user->getNom()), strtolower($substring)) !== false || strpos(strtolower($user->getPrenom()), strtolower($substring)) !== false; return strpos(strtolower($user->getNom()), strtolower($substring)) !== false || strpos(strtolower($user->getPrenom()), strtolower($substring)) !== false;
}); });

Loading…
Cancel
Save