users[] = new User(1, "Doe", "John", "john.doe@example.com", "password123", "Masculin", 1.80, 75, new \DateTime("1985-05-15"), new Coach()); $this->users[] = new User(2, "Smith", "Jane", "jane.smith@example.com", "secure456", "Féminin", 1.65, 60, new \DateTime("1990-03-10"), new Athlete()); $this->users[] = new User(3, "Martin", "Paul", "paul.martin@example.com", "super789", "Masculin", 1.75, 68, new \DateTime("1988-08-20"), new Coach()); $this->users[] = new User(4, "Brown", "Anna", "anna.brown@example.com", "test000", "Féminin", 1.70, 58, new \DateTime("1992-11-25"), new Athlete()); $this->users[] = new User(5, "Lee", "Bruce", "bruce.lee@example.com", "hello321", "Masculin", 1.72, 70, new \DateTime("1970-02-05"), new Athlete()); } public function getItemById(int $id): ?User { foreach ($this->users as $user) { if ($user->id === $id) { return $user; } } return null; } public function GetNbItems(): int { return count($this->users); } 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 return array_slice($this->users, $index, $count); } 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) { return strpos(strtolower($user->nom), strtolower($substring)) !== false || strpos(strtolower($user->prenom), strtolower($substring)) !== false; }); return array_slice($filteredUsers, $index, $count); } public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false):User { return $this->GetItemsByName($substring, $index, $count, $orderingPropertyName, $descending)[0]; } public function UpdateItem(User $oldUser, User $newUser): void { $index = array_search($oldUser, $this->users); if ($index !== false) { $this->users[$index] = $newUser; } } public function AddItem(User $user): void { $this->users[] = $user; } public function DeleteItem(User $user): bool { $index = array_search($user, $this->users); if ($index !== false) { unset($this->users[$index]); return true; } return false; } } ?>