mirror of
https://github.com/pacnpal/thrillwiki_laravel.git
synced 2025-12-22 14:31:09 -05:00
Add models, enums, and services for user roles, theme preferences, slug history, and ID generation
This commit is contained in:
80
app/Enums/ParkStatus.php
Normal file
80
app/Enums/ParkStatus.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ParkStatus: string
|
||||
{
|
||||
case OPERATING = 'OPERATING';
|
||||
case CLOSED_TEMP = 'CLOSED_TEMP';
|
||||
case CLOSED_PERM = 'CLOSED_PERM';
|
||||
case UNDER_CONSTRUCTION = 'UNDER_CONSTRUCTION';
|
||||
case DEMOLISHED = 'DEMOLISHED';
|
||||
case RELOCATED = 'RELOCATED';
|
||||
|
||||
/**
|
||||
* Get the display label for the status
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::OPERATING => 'Operating',
|
||||
self::CLOSED_TEMP => 'Temporarily Closed',
|
||||
self::CLOSED_PERM => 'Permanently Closed',
|
||||
self::UNDER_CONSTRUCTION => 'Under Construction',
|
||||
self::DEMOLISHED => 'Demolished',
|
||||
self::RELOCATED => 'Relocated',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Tailwind CSS classes for status badge
|
||||
*/
|
||||
public function getStatusClasses(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::OPERATING => 'bg-green-100 text-green-800',
|
||||
self::CLOSED_TEMP => 'bg-yellow-100 text-yellow-800',
|
||||
self::CLOSED_PERM => 'bg-red-100 text-red-800',
|
||||
self::UNDER_CONSTRUCTION => 'bg-blue-100 text-blue-800',
|
||||
self::DEMOLISHED => 'bg-gray-100 text-gray-800',
|
||||
self::RELOCATED => 'bg-purple-100 text-purple-800',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the park is currently operational
|
||||
*/
|
||||
public function isOperational(): bool
|
||||
{
|
||||
return $this === self::OPERATING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the park is permanently closed
|
||||
*/
|
||||
public function isPermanentlyClosed(): bool
|
||||
{
|
||||
return in_array($this, [self::CLOSED_PERM, self::DEMOLISHED]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the park is temporarily closed
|
||||
*/
|
||||
public function isTemporarilyClosed(): bool
|
||||
{
|
||||
return $this === self::CLOSED_TEMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all status options as an array for forms
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
return array_reduce(self::cases(), function ($carry, $status) {
|
||||
$carry[$status->value] = $status->label();
|
||||
return $carry;
|
||||
}, []);
|
||||
}
|
||||
}
|
||||
25
app/Enums/ThemePreference.php
Normal file
25
app/Enums/ThemePreference.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ThemePreference: string
|
||||
{
|
||||
case LIGHT = 'light';
|
||||
case DARK = 'dark';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::LIGHT => 'Light',
|
||||
self::DARK => 'Dark',
|
||||
};
|
||||
}
|
||||
|
||||
public function cssClass(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::LIGHT => 'theme-light',
|
||||
self::DARK => 'theme-dark',
|
||||
};
|
||||
}
|
||||
}
|
||||
37
app/Enums/UserRole.php
Normal file
37
app/Enums/UserRole.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum UserRole: string
|
||||
{
|
||||
case USER = 'USER';
|
||||
case MODERATOR = 'MODERATOR';
|
||||
case ADMIN = 'ADMIN';
|
||||
case SUPERUSER = 'SUPERUSER';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::USER => 'User',
|
||||
self::MODERATOR => 'Moderator',
|
||||
self::ADMIN => 'Admin',
|
||||
self::SUPERUSER => 'Superuser',
|
||||
};
|
||||
}
|
||||
|
||||
public function canModerate(): bool
|
||||
{
|
||||
return match($this) {
|
||||
self::MODERATOR, self::ADMIN, self::SUPERUSER => true,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
public function canAdmin(): bool
|
||||
{
|
||||
return match($this) {
|
||||
self::ADMIN, self::SUPERUSER => true,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user