51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification as FilamentNotification;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* A digest: what this person looks after that is about to close or come off
|
|
* the site.
|
|
*/
|
|
class ExpiringSoon extends Notification
|
|
{
|
|
/**
|
|
* @param Collection<int, array<string, mixed>> $items
|
|
*/
|
|
public function __construct(public readonly Collection $items) {}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database'];
|
|
}
|
|
|
|
public function toDatabase(object $notifiable): array
|
|
{
|
|
$first = $this->items->first();
|
|
|
|
return FilamentNotification::make()
|
|
->title(trans_choice('panel.expiring.notification.title', $this->items->count(), ['count' => $this->items->count()]))
|
|
->body($this->items
|
|
->map(fn (array $item) => $item['title'].' — '.__("panel.expiring.events.{$item['event']}", [
|
|
'when' => $item['at']->diffForHumans(),
|
|
'date' => $item['at']->isoFormat('LL'),
|
|
]))
|
|
->implode("\n"))
|
|
->icon('heroicon-o-clock')
|
|
->iconColor('warning')
|
|
->actions($this->items->count() === 1 ? [
|
|
Action::make('open')
|
|
->label(__('panel.expiring.notification.open'))
|
|
->url($first['url'])
|
|
->markAsRead(),
|
|
] : [])
|
|
->getDatabaseMessage();
|
|
}
|
|
}
|