46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
enum ActivityEventLabel: string
|
|
{
|
|
case Created = 'created';
|
|
case Updated = 'updated';
|
|
case Deleted = 'deleted';
|
|
case Login = 'login';
|
|
case Logout = 'logout';
|
|
|
|
public function label(): string
|
|
{
|
|
return match ($this) {
|
|
self::Created => 'Dibuat',
|
|
self::Updated => 'Diperbarui',
|
|
self::Deleted => 'Dihapus',
|
|
self::Login => 'Masuk',
|
|
self::Logout => 'Keluar',
|
|
};
|
|
}
|
|
|
|
public static function labelFor(?string $event): string
|
|
{
|
|
if ($event === null || $event === '') {
|
|
return '-';
|
|
}
|
|
|
|
return self::tryFrom($event)?->label() ?? ucfirst($event);
|
|
}
|
|
|
|
/**
|
|
* @return list<array{value: string, label: string}>
|
|
*/
|
|
public static function selectOptions(): array
|
|
{
|
|
return collect(self::cases())
|
|
->map(fn (self $event) => [
|
|
'value' => $event->value,
|
|
'label' => $event->label(),
|
|
])
|
|
->all();
|
|
}
|
|
}
|