settings->get(self::CAPACITY_KEY) ?? ''); return (int) round(($hours > 0 && $hours <= 24 ? $hours : self::DEFAULT_CAPACITY_HOURS) * 60); } /** * Rebooks the task's assignees and, if their days were full, moves the * task's planned end later. The task must be saved (have an id); * save it again afterwards. * * @return bool Whether the planned end moved later. */ public function plan(Task $task): bool { $taskId = (int) $task->id(); $from = $task->plannedFrom(); $to = $task->plannedTo(); if ($from === null || $to === null) { $this->bookings->deleteForTask($taskId); return false; } $this->bookings->deleteForTask($taskId, $task->assigneeUserIds()); $minutes = (int) round(($task->estimatedHours()->value ?? 0) * 60); $lookahead = $to->add(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d'); $holidays = $this->holidays->activeDatesBetween($from->format('Y-m-d'), $lookahead); $capacity = $this->capacityMinutes(); $end = $to; foreach ($task->assigneeUserIds() as $userId) { $schedule = TaskScheduler::schedule( $from, $to, $minutes, $this->bookings->otherOpenMinutes($userId, $from->format('Y-m-d'), $lookahead, $taskId), $capacity, $holidays, ); $this->bookings->replaceFor($taskId, $userId, $schedule->minutesByDay); if ($schedule->end > $end) { $end = $schedule->end; } } if ($end > $to) { $task->schedule($from, $end); return true; } return false; } /** * The end of a task placed on a day without an end (TaskScheduler::defaultEnd). */ public function defaultEnd(DateTimeImmutable $from, Task $task): DateTimeImmutable { $minutes = (int) round(($task->estimatedHours()->value ?? 0) * 60); $lookahead = $from->add(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d'); return TaskScheduler::defaultEnd($from, $minutes, $this->capacityMinutes(), $this->holidays->activeDatesBetween($from->format('Y-m-d'), $lookahead)); } }