>> task id => user id => day => minutes */ public array $bookings = []; public function __construct(private InMemoryTaskRepository $tasks) {} public function replaceFor(int $taskId, int $userId, array $minutesByDay): void { $this->bookings[$taskId][$userId] = array_filter($minutesByDay, fn (int $minutes): bool => $minutes > 0); } public function deleteForTask(int $taskId, array $keepUserIds = []): void { foreach (array_keys($this->bookings[$taskId] ?? []) as $userId) { if (! in_array($userId, $keepUserIds, true)) { unset($this->bookings[$taskId][$userId]); } } } public function otherOpenMinutes(int $userId, string $from, string $to, int $exceptTaskId): array { $minutes = []; foreach ($this->bookings as $taskId => $users) { if ($taskId === $exceptTaskId || ($this->tasks->tasks[$taskId] ?? null)?->status() === TaskStatus::Done) { continue; } foreach ($users[$userId] ?? [] as $day => $booked) { if ($day >= $from && $day <= $to) { $minutes[$day] = ($minutes[$day] ?? 0) + $booked; } } } ksort($minutes); return $minutes; } /** * @return array */ public function of(int $taskId, int $userId): array { $days = $this->bookings[$taskId][$userId] ?? []; ksort($days); return $days; } }