ok
continuous-integration/drone/push Build is failing Details

issue_a
David D'ALMEIDA 1 year ago
parent fae5e35610
commit 94a5e9ead4

@ -75,7 +75,6 @@ function displayCoachMenu()
clearScreen(); clearScreen();
echo "\n--- Menu Coach ---\n"; echo "\n--- Menu Coach ---\n";
echo "1. Liste des athlètes\n"; echo "1. Liste des athlètes\n";
echo "2. Statistiques globales\n";
echo "3. Analyses par athlète\n"; echo "3. Analyses par athlète\n";
echo "4. Gérer la liste de mes athlètes\n"; echo "4. Gérer la liste de mes athlètes\n";
// Gérer les athlètes (comprend : Ajouter un athlète, Supprimer un athlète, Consulter les statistiques d'un athlète) // Gérer les athlètes (comprend : Ajouter un athlète, Supprimer un athlète, Consulter les statistiques d'un athlète)
@ -848,6 +847,7 @@ while (true) {
break; break;
case '7': // Notifications case '7': // Notifications
echo "Affichage des notifications...\n"; echo "Affichage des notifications...\n";
break; break;

@ -61,7 +61,7 @@ abstract class Role {
public function addTraining(Training $training) public function addTraining(Training $training)
{ {
$this->trainingList [] = $training; $this->trainingList [] = $training;
return true;
} }
public function getTrainingsList(): array public function getTrainingsList(): array
{ {

@ -2,6 +2,7 @@
namespace Manager; namespace Manager;
use Model\Coach;
use Model\Training; use Model\Training;
use Network\IAuthService; use Network\IAuthService;
@ -26,10 +27,7 @@ class CoachManager
return null; return null;
} }
public function getTrainingsList(): ?array { public function getTrainingsList(): ?array {
if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole()->getTrainingsList()) { return $this->dataManager->trainingRepository->getItems(0,10);
return $this->authService->getCurrentUser()->getRole()->getTrainingsList();
}
return null;
} }
public function addUser(string $username): bool public function addUser(string $username): bool
{ {
@ -56,7 +54,8 @@ class CoachManager
} }
public function addTraining(Training $training): bool public function addTraining(Training $training): bool
{ {
if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole()) { if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole() instanceof Coach) {
if ($this->authService->getCurrentUser()->getRole()->addTraining($training)) { if ($this->authService->getCurrentUser()->getRole()->addTraining($training)) {
$this->dataManager->trainingRepository->addItem($training); $this->dataManager->trainingRepository->addItem($training);
return true; return true;
@ -66,7 +65,11 @@ class CoachManager
} }
public function removeTraining(String $trainingId): bool public function removeTraining(String $trainingId): bool
{ {
$index = array_search($trainingId, $this->authService->getCurrentUser()->getRole()->getTrainingsList());
if ($index !== false) {
unset($this->authService->getCurrentUser()->getRole()->getTrainingsList()[$index]);
return true;
}
return false; return false;
} }

@ -3,47 +3,83 @@
namespace Stub; namespace Stub;
use Repository\INotificationRepository; use Repository\INotificationRepository;
use Model\Notification;
class NotificationRepository implements INotificationRepository class NotificationRepository implements INotificationRepository
{ {
private $notifications = []; // Array to store notifications
public function __construct()
{
// Initialize with some sample notifications for user IDs 1, 2, and 3
$this->notifications[] = new Notification(1, 'info', 'Welcome to our service!');
$this->notifications[] = new Notification(2, 'alert', 'Your subscription is about to expire.');
$this->notifications[] = new Notification(3, 'info', 'New features available.');
$this->notifications[] = new Notification(1, 'reminder', 'Dont forget your upcoming appointment.');
$this->notifications[] = new Notification(2, 'update', 'Service update completed.');
// Add more notifications as needed
}
public function getItemById(int $id) public function getItemById(int $id)
{ {
// TODO: Implement getItemById() method. // Assuming each notification has a unique ID
foreach ($this->notifications as $notification) {
if ($notification->getId() == $id) {
return $notification;
}
}
return null;
} }
public function getNbItems(): int public function getNbItems(): int
{ {
// TODO: Implement getNbItems() method. return count($this->notifications);
} }
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
{ {
// TODO: Implement getItems() method. // For simplicity, returning a slice of the array
return array_slice($this->notifications, $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
{ {
// TODO: Implement getItemsByName() method. $filtered = array_filter($this->notifications, function($notification) use ($substring) {
return strpos($notification->getMessage(), $substring) !== false;
});
// For simplicity, just returning a slice without ordering
return array_slice($filtered, $index, $count);
} }
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)
{ {
// TODO: Implement getItemByName() method. $items = $this->getItemsByName($substring, $index, $count, $orderingPropertyName, $descending);
return $items ? $items[0] : null;
} }
public function updateItem($oldItem, $newItem): void public function updateItem($oldItem, $newItem): void
{ {
// TODO: Implement updateItem() method. // Find and update the item. This is a simplistic implementation.
foreach ($this->notifications as $key => $notification) {
if ($notification === $oldItem) {
$this->notifications[$key] = $newItem;
break;
}
}
} }
public function addItem($item): void public function addItem($item): void
{ {
// TODO: Implement addItem() method. $this->notifications[] = $item;
} }
public function deleteItem($item): bool public function deleteItem($item): bool
{ {
// TODO: Implement deleteItem() method. foreach ($this->notifications as $key => $notification) {
if ($notification === $item) {
unset($this->notifications[$key]);
return true;
}
}
return false;
} }
} }

@ -2,48 +2,72 @@
namespace Stub; namespace Stub;
use Model\Training;
use Repository\ITrainingRepository; use Repository\ITrainingRepository;
class TrainingRepository implements ITrainingRepository class TrainingRepository implements ITrainingRepository {
{ private array $trainings = [];
public function getItemById(int $id) public function __construct() {
{
// TODO: Implement getItemById() method. }
public function getItemById(int $id): ?Training {
foreach ($this->trainings as $training) {
if ($training->getId() === $id) {
return $training;
}
}
return null;
} }
public function getNbItems(): int public function getNbItems(): int {
{ return count($this->trainings);
// TODO: Implement getNbItems() method.
} }
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 {
{ // Implement the logic for ordering and slicing the array
// TODO: Implement getItems() method. return array_slice($this->trainings, $index, $count);
} }
public function getItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array public function getItemsByDate(\DateTime $date, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
{ $filteredTrainings = array_filter($this->trainings, function ($training) use ($date) {
// TODO: Implement getItemsByName() method. return $training->getDate() == $date;
});
// Implement sorting if necessary
return array_slice($filteredTrainings, $index, $count);
} }
public function getItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false) public function updateItem( $oldTraining, $newTraining): void {
{ $index = array_search($oldTraining, $this->trainings);
// TODO: Implement getItemByName() method. if ($index !== false) {
$this->trainings[$index] = $newTraining;
}
} }
public function updateItem($oldItem, $newItem): void public function addItem( $training): void {
{ $this->trainings[] = $training;
// TODO: Implement updateItem() method.
} }
public function addItem($item): void public function deleteItem( $training): bool {
{ $index = array_search($training, $this->trainings);
// TODO: Implement addItem() method. if ($index !== false) {
unset($this->trainings[$index]);
return true;
}
return false;
}
public function getItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
$filteredTrainings = array_filter($this->trainings, function ($training) use ($substring) {
// Assuming the 'description' field is the one to be searched
return str_contains(strtolower($training->getDescription()), strtolower($substring));
});
// Implement sorting if necessary
return array_slice($filteredTrainings, $index, $count);
} }
public function deleteItem($item): bool public function getItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): ?Training {
{ $filteredTrainings = $this->getItemsByName($substring, $index, $count, $orderingPropertyName, $descending);
// TODO: Implement deleteItem() method. return $filteredTrainings[0] ?? null;
} }
} }
Loading…
Cancel
Save