A new Notifications module shows a bell beside the profile menu with the number of unseen notifications and a panel of the last 7 days; opening it marks them seen, and each notification links to its job or task. - A daily run at 14.00 (notifications:task-starts) tells the assignee and members of tasks that start by the next working day, skipping holidays and days off, done tasks and archived jobs. - Jobs publishes PeopleAddedToTask and PeopleAddedToJob when someone else makes a user a task's assignee or member or gives them a role on a job; those users are notified at once. UpdateTask and ScheduleTask now take the acting user. - A notification link to #task-<id> opens that task card on the job page. Also: simplifying job fields per service unit (K31) moves to the end of phase 4, and the workflow template browser test waits for Livewire's progress bar before its last accessibility check. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
78 lines
3.0 KiB
PHP
78 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Jobs\Application\UseCases;
|
|
|
|
use App\Modules\Jobs\Application\DTOs\ScheduleResult;
|
|
use App\Modules\Jobs\Application\Services\TaskPlanner;
|
|
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
|
|
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
|
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
|
use App\Modules\Jobs\Domain\Events\PeopleAddedToTask;
|
|
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
|
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
|
|
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
|
use App\Modules\Shared\Application\Contracts\EventDispatcher;
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
|
|
/**
|
|
* Moves a task in the task calendar: a new planned period, and possibly
|
|
* from one person's row to another's (the person on the new row becomes
|
|
* the assignee; null is the "no assignee" row; members stay). Without an
|
|
* end, the task lasts as many working days as its estimate needs.
|
|
*/
|
|
final class ScheduleTask
|
|
{
|
|
public function __construct(
|
|
private CustomerJobRepository $jobs,
|
|
private TaskRepository $tasks,
|
|
private TaskReferenceChecker $references,
|
|
private TaskPlanner $planner,
|
|
private TransactionManager $transactions,
|
|
private EventDispatcher $events,
|
|
) {}
|
|
|
|
/**
|
|
* @throws CustomerJobNotFound
|
|
* @throws TaskNotFound
|
|
* @throws InvalidTaskReference
|
|
* @throws PlanEndsBeforeStart
|
|
*/
|
|
public function execute(int $jobId, int $taskId, ?int $fromUserId, ?int $toUserId, string $plannedFrom, ?string $plannedTo, int $actorUserId): ScheduleResult
|
|
{
|
|
$from = TaskInput::date($plannedFrom) ?? throw new PlanEndsBeforeStart;
|
|
$to = TaskInput::date($plannedTo);
|
|
|
|
return $this->transactions->run(function () use ($jobId, $taskId, $fromUserId, $toUserId, $from, $to, $actorUserId): ScheduleResult {
|
|
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
|
$task = $this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId);
|
|
$peopleBefore = PeopleAddedToTask::peopleOf($task);
|
|
|
|
if ($fromUserId !== $toUserId) {
|
|
$this->references->check($job, $task->workTypeId(), $toUserId, [], $task);
|
|
$task->assignTo($toUserId);
|
|
}
|
|
|
|
$task->schedule($from, $to ?? $this->planner->defaultEnd($from, $task));
|
|
|
|
$task = $this->tasks->save($task);
|
|
$extended = $this->planner->plan($task);
|
|
$task = $this->tasks->save($task);
|
|
|
|
$added = PeopleAddedToTask::between($peopleBefore, $task, $job, $actorUserId);
|
|
|
|
if ($added !== null) {
|
|
$this->events->dispatch($added);
|
|
}
|
|
|
|
return new ScheduleResult(
|
|
(string) $task->plannedFrom()?->format('Y-m-d'),
|
|
(string) $task->plannedTo()?->format('Y-m-d'),
|
|
$extended,
|
|
);
|
|
});
|
|
}
|
|
}
|