Files
animethemes-server/app/Events/Base/Wiki/WikiDeletedEvent.php
T
paranarimasu 088ea287c5 feat: initial migration to pennant features for feature flags and global site config [incremental] (#573)
* feat: initial commit for feature management

* style: fix StyleCI findings

* fix(api): prohibit features of nonnull scope from API & fix(admin): wrong translate key

* style: fix Static Analysis error
2023-04-23 18:54:34 -05:00

87 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Events\Base\Wiki;
use App\Constants\Config\ServiceConstants;
use App\Contracts\Events\NovaNotificationEvent;
use App\Events\Base\BaseDeletedEvent;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Laravel\Nova\Notifications\NovaNotification;
/**
* Class WikiDeletedEvent.
*
* @template TModel of \App\Models\BaseModel
*
* @extends BaseDeletedEvent<TModel>
*/
abstract class WikiDeletedEvent extends BaseDeletedEvent implements NovaNotificationEvent
{
/**
* Get Discord channel the message will be sent to.
*
* @return string
*/
public function getDiscordChannel(): string
{
return Config::get(ServiceConstants::DB_UPDATES_DISCORD_CHANNEL_QUALIFIED);
}
/**
* Determine if the notifications should be sent.
*
* @return bool
*/
public function shouldSendNovaNotification(): bool
{
$model = $this->getModel();
return ! $model->isForceDeleting();
}
/**
* Get the nova notification.
*
* @return NovaNotification
*/
public function getNovaNotification(): NovaNotification
{
return NovaNotification::make()
->icon('flag')
->message($this->getNotificationMessage())
->type(NovaNotification::INFO_TYPE)
->url($this->getNovaNotificationUrl());
}
/**
* Get the users to notify.
*
* @return Collection
*/
public function getNovaNotificationRecipients(): Collection
{
return User::query()
->whereRelation(User::RELATION_ROLES, Role::ATTRIBUTE_NAME, 'Admin')
->get();
}
/**
* Get the message for the nova notification.
*
* @return string
*/
abstract protected function getNotificationMessage(): string;
/**
* Get the URL for the nova notification.
*
* @return string
*/
abstract protected function getNovaNotificationUrl(): string;
}