Files
animethemes-server/app/Events/Base/Document/DocumentDeletedEvent.php
T

79 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Events\Base\Document;
use App\Constants\Config\ServiceConstants;
use App\Contracts\Events\FilamentNotificationEvent;
use App\Contracts\Models\SoftDeletable;
use App\Enums\Auth\Role as RoleEnum;
use App\Events\Base\BaseDeletedEvent;
use App\Filament\Actions\Base\MarkAsReadAction;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
/**
* @template TModel of \App\Models\BaseModel
*
* @extends BaseDeletedEvent<TModel>
*/
abstract class DocumentDeletedEvent extends BaseDeletedEvent implements FilamentNotificationEvent
{
public function getDiscordChannel(): string
{
return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED);
}
public function shouldSendFilamentNotification(): bool
{
$model = $this->getModel();
if ($model instanceof SoftDeletable) {
return ! $model->isForceDeleting();
}
return false;
}
public function getFilamentNotification(): Notification
{
return Notification::make()
->body($this->getNotificationMessage())
->warning()
->actions([
Action::make('view')
->button()
->url($this->getFilamentNotificationUrl()),
MarkAsReadAction::make(),
]);
}
public function getFilamentNotificationRecipients(): Collection
{
return User::query()
->whereRelation(User::RELATION_ROLES, Role::ATTRIBUTE_NAME, RoleEnum::ADMIN->value)
->get();
}
protected function getDiscordMessageDescription(): string
{
return "{$this->privateLabel($this->getModel())} '**{$this->getModel()->getName()}**' has been deleted.";
}
protected function getNotificationMessage(): string
{
return "{$this->privateLabel($this->getModel())} '{$this->getModel()->getName()}' has been deleted. It will be automatically pruned in one week. Please review.";
}
/**
* Get the URL for the filament notification.
*/
abstract protected function getFilamentNotificationUrl(): string;
}