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]>
74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Notifications\Application\UseCases;
|
|
|
|
use App\Modules\Jobs\Application\Contracts\UpcomingTasks;
|
|
use App\Modules\Notifications\Application\Services\WorkingDays;
|
|
use App\Modules\Notifications\Domain\Contracts\NotificationRepository;
|
|
use App\Modules\Notifications\Domain\ValueObjects\NewNotification;
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
use App\Modules\Users\Application\Contracts\Clock;
|
|
|
|
/**
|
|
* The daily run: on a working day, tells the assignee and members of every
|
|
* task starting by the next working day (after today) that it starts, e.g.
|
|
* on Friday about tasks starting on Saturday to Monday. Running again does
|
|
* not notify twice. Notifications older than a week are removed.
|
|
*/
|
|
final class NotifyTasksStartingSoon
|
|
{
|
|
/**
|
|
* How long notifications are kept and shown.
|
|
*/
|
|
public const int KEEP_DAYS = 7;
|
|
|
|
public function __construct(
|
|
private UpcomingTasks $tasks,
|
|
private NotificationRepository $notifications,
|
|
private WorkingDays $workingDays,
|
|
private TransactionManager $transactions,
|
|
private Clock $clock,
|
|
) {}
|
|
|
|
/**
|
|
* @return int How many notifications were added.
|
|
*/
|
|
public function execute(): int
|
|
{
|
|
$today = $this->clock->today();
|
|
$now = $this->clock->now();
|
|
|
|
return $this->transactions->run(function () use ($today, $now): int {
|
|
$this->notifications->deleteOlderThan($now->modify('-'.self::KEEP_DAYS.' days'));
|
|
|
|
if (! $this->workingDays->isWorkingDay($today)) {
|
|
return 0;
|
|
}
|
|
|
|
$until = $this->workingDays->nextAfter($today)->format('Y-m-d');
|
|
$added = 0;
|
|
|
|
foreach ($this->tasks->startingBetween($today->format('Y-m-d'), $until) as $task) {
|
|
$params = [
|
|
'task_id' => $task->taskId,
|
|
'task_title' => $task->title,
|
|
'job_id' => $task->jobId,
|
|
'job_number' => $task->jobNumber,
|
|
'job_name' => $task->jobName,
|
|
'starts_on' => $task->plannedFrom,
|
|
];
|
|
|
|
foreach ($task->recipientIds as $userId) {
|
|
if ($this->notifications->addIfNew(NewNotification::taskStartsSoon($userId, $task->taskId, $task->plannedFrom, $params, $now))) {
|
|
$added++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $added;
|
|
});
|
|
}
|
|
}
|