Files
Toiminnanohjaus/app/Modules/Jobs/Domain/Events/PeopleAddedToJob.php
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

83 lines
2.3 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\ValueObjects\JobDetails;
/**
* Someone got a role on a customer job: responsible person, contact
* person, biller or member. Published after the change is saved, for
* notifying them (not the one who made it).
*/
final readonly class PeopleAddedToJob
{
public const string RESPONSIBLE = 'responsible';
public const string CONTACT = 'contact';
public const string BILLER = 'biller';
public const string MEMBER = 'member';
/**
* @param array<int, list<string>> $newRoles The new roles by user id.
*/
public function __construct(
public int $jobId,
public string $jobNumber,
public string $jobName,
public array $newRoles,
public int $actorUserId,
) {}
/**
* The roles the saved job gives that the details before did not (a new
* job has none before); null when nobody got a new role.
*/
public static function between(?JobDetails $before, CustomerJob $after, int $actorUserId): ?self
{
$old = $before === null ? [] : self::rolesOf($before);
$newRoles = [];
foreach (self::rolesOf($after->details()) as $userId => $roles) {
$added = array_values(array_diff($roles, $old[$userId] ?? []));
if ($added !== []) {
$newRoles[$userId] = $added;
}
}
if ($newRoles === []) {
return null;
}
return new self((int) $after->id(), $after->number()->format(), $after->details()->name->value, $newRoles, $actorUserId);
}
/**
* @return array<int, list<string>>
*/
private static function rolesOf(JobDetails $details): array
{
$roles = [];
$roles[$details->responsibleUserId][] = self::RESPONSIBLE;
if ($details->contactUserId !== null) {
$roles[$details->contactUserId][] = self::CONTACT;
}
if ($details->billerUserId !== null) {
$roles[$details->billerUserId][] = self::BILLER;
}
foreach ($details->memberUserIds as $memberId) {
$roles[$memberId][] = self::MEMBER;
}
return $roles;
}
}