Files
Toiminnanohjaus/app/Modules/Jobs/Domain/Events/PeopleAddedToTask.php
T
petriandClaude Sonnet 5.5 f906f9a43f Add notifications: header bell, task start run and assignment notices
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]>
2026-11-25 08:28:01 +02:00

68 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Domain\Events;
use App\Modules\Jobs\Domain\Entities\CustomerJob;
use App\Modules\Jobs\Domain\Entities\Task;
/**
* Someone became a task's assignee or one of its members. Published after
* the change is saved, for notifying them (not the one who made it).
*/
final readonly class PeopleAddedToTask
{
/**
* @param list<int> $newMemberIds
*/
public function __construct(
public int $taskId,
public string $taskTitle,
public int $jobId,
public string $jobNumber,
public string $jobName,
public ?int $newAssigneeId,
public array $newMemberIds,
public int $actorUserId,
) {}
/**
* The people the saved task has that it did not have before (a new task
* has none before); null when nobody was added.
*
* @param array{assignee: ?int, members: list<int>}|null $before
*/
public static function between(?array $before, Task $after, CustomerJob $job, int $actorUserId): ?self
{
$assignee = $after->assigneeUserId();
$newAssignee = $assignee !== null && $assignee !== ($before['assignee'] ?? null) ? $assignee : null;
$newMembers = array_values(array_diff($after->memberUserIds(), $before['members'] ?? [], $newAssignee === null ? [] : [$newAssignee]));
if ($newAssignee === null && $newMembers === []) {
return null;
}
return new self(
(int) $after->id(),
$after->title()->value,
$job->id() ?? $after->jobId(),
$job->number()->format(),
$job->details()->name->value,
$newAssignee,
$newMembers,
$actorUserId,
);
}
/**
* Who the task has now, to compare with after a change.
*
* @return array{assignee: ?int, members: list<int>}
*/
public static function peopleOf(Task $task): array
{
return ['assignee' => $task->assigneeUserId(), 'members' => $task->memberUserIds()];
}
}