🆙 More refactored 🆙

This commit is contained in:
Remco
2026-01-20 20:17:04 +01:00
parent 1e84468d49
commit fccf4c2116
14 changed files with 169 additions and 83 deletions
@@ -21,11 +21,9 @@ enum AchievementCategory: string
public static function toInput(): array
{
$allCurrencies = self::cases();
return array_combine(
array_column($allCurrencies, 'value'),
array_column($allCurrencies, 'name'),
);
$allCategories = self::cases();
$keys = array_map(fn (self $c): string => $c->value, $allCategories);
$values = array_map(fn (self $c): string => $c->name, $allCategories);
return array_combine($keys, $values) ?: [];
}
}
+3 -5
View File
@@ -40,10 +40,8 @@ enum CurrencyTypes: int
public static function toInput(): array
{
$allCurrencies = self::cases();
return array_combine(
array_column($allCurrencies, 'value'),
array_column($allCurrencies, 'name'),
);
$keys = array_map(fn (self $c): int => $c->value, $allCurrencies);
$values = array_map(fn (self $c): string => $c->name, $allCurrencies);
return array_combine($keys, $values) ?: [];
}
}
@@ -9,23 +9,21 @@ use Illuminate\Database\Eloquent\Builder;
class DateRangeFilter extends Filter
{
#[\Override]
public static function make(?string $name = null): static
public static function make(string $name): static
{
return parent::make($name)
->schema([
DatePicker::make("{$name}_from"),
DatePicker::make("{$name}_until"),
])
->query(function (Builder $query, array $data) use (&$name): Builder {
return $query
->when(
$data["{$name}_from"],
fn (Builder $query, $date): Builder => $query->whereDate($name, '>=', $date),
)
->when(
$data["{$name}_until"],
fn (Builder $query, $date): Builder => $query->whereDate($name, '<=', $date),
);
->query(function (Builder $query, array $data) use ($name): Builder {
if (isset($data["{$name}_from"]) && is_string($data["{$name}_from"])) {
$query->whereDate($name, '>=', $data["{$name}_from"]);
}
if (isset($data["{$name}_until"]) && is_string($data["{$name}_until"])) {
$query->whereDate($name, '<=', $data["{$name}_until"]);
}
return $query;
});
}
}
+58 -35
View File
@@ -31,15 +31,18 @@ class BadgePage extends Page
protected static string $translateIdentifier = 'badge-resource';
public $badgeWasPreviouslyCreated;
public bool $badgeWasPreviouslyCreated = false;
public ?array $data = [];
/**
* @var array<string, mixed>
*/
public array $data = [];
public static string $roleName = 'badge_page';
public static function canAccess(): bool
{
return auth()->user()->can('view::admin::' . static::$roleName);
return auth()->check() && auth()->user()?->can('view::admin::' . static::$roleName) === true;
}
#[\Override]
@@ -60,7 +63,7 @@ class BadgePage extends Page
->label(__('filament::resources.inputs.badge_code'))
->helperText(__('filament::resources.helpers.badge_code_helper'))
->afterStateUpdated(function (?string $state, Set $set): void {
$set('code', strtoupper($state));
$set('code', strtoupper($state ?? ''));
})
->suffixAction(fn (): PageAction => PageAction::make('search')->icon('heroicon-o-magnifying-glass')->action(fn () => $this->searchBadgesByCode()),
),
@@ -69,7 +72,7 @@ class BadgePage extends Page
->label(__('filament::resources.inputs.badge_image'))
->placeholder('...')
->autocomplete()
->visible(fn (Get $get) => isset($this->data['image']) ?? false)
->visible(fn (Get $get) => isset($this->data['image']))
->prefixAction(
fn (?string $state): PageAction => PageAction::make('visit')
->icon('heroicon-s-arrow-top-right-on-square')
@@ -87,12 +90,12 @@ class BadgePage extends Page
TextInput::make('nitro.title')
->label(__('filament::resources.inputs.badge_title'))
->placeholder('...')
->visible(fn () => isset($this->data['nitro']['title']) ?? false),
->visible(fn () => is_array($this->data['nitro']) && array_key_exists('title', $this->data['nitro'])),
TextInput::make('nitro.description')
->label(__('filament::resources.inputs.badge_description'))
->placeholder('...')
->visible(fn () => isset($this->data['nitro']['description']) ?? false),
->visible(fn () => is_array($this->data['nitro']) && array_key_exists('description', $this->data['nitro'])),
]),
Section::make('Flash Texts')
@@ -102,12 +105,12 @@ class BadgePage extends Page
TextInput::make('flash.title')
->label(__('filament::resources.inputs.badge_title'))
->placeholder('...')
->visible(fn () => isset($this->data['flash']['title']) ?? false),
->visible(fn () => is_array($this->data['flash']) && array_key_exists('title', $this->data['flash'])),
TextInput::make('flash.description')
->label(__('filament::resources.inputs.badge_description'))
->placeholder('...')
->visible(fn () => isset($this->data['flash']['description']) ?? false),
->visible(fn () => is_array($this->data['flash']) && array_key_exists('description', $this->data['flash'])),
]),
])
->statePath('data');
@@ -115,16 +118,22 @@ class BadgePage extends Page
private function searchBadgesByCode(): void
{
$badgeCode = $this->form->getState()['code'] ?? null;
$badgeCode = is_string($this->data['code'] ?? null) ? $this->data['code'] : null;
if (empty($badgeCode)) {
$this->notify('danger', __('filament::resources.notifications.badge_code_required'));
Notification::make()
->color('danger')
->icon('heroicon-o-exclamation-triangle')
->title(__('filament::resources.notifications.badge_code_required'))
->send();
return;
}
$badgeData = app(ExternalTextsParser::class)->getBadgeData($badgeCode);
$this->badgeWasPreviouslyCreated = is_array($badgeData['nitro']) || is_array($badgeData['flash']);
$badgeData = app(ExternalTextsParser::class)->getBadgeData((string) $badgeCode);
$nitro = is_array($badgeData['nitro'] ?? null) ? $badgeData['nitro'] : [];
$flash = is_array($badgeData['flash'] ?? null) ? $badgeData['flash'] : [];
$this->badgeWasPreviouslyCreated = ! empty($nitro) || ! empty($flash);
if ($this->badgeWasPreviouslyCreated) {
Notification::make()
@@ -135,13 +144,13 @@ class BadgePage extends Page
->send();
$this->data = [
'code' => $badgeCode,
'code' => (string) $badgeCode,
...$this->getDefaultDataBehavior(
$badgeData['image'] ?? null,
$badgeData['nitro']['title'] ?? null,
$badgeData['nitro']['description'] ?? null,
$badgeData['flash']['title'] ?? null,
$badgeData['flash']['description'] ?? null,
is_string($badgeData['image'] ?? null) ? $badgeData['image'] : null,
is_string($nitro['title'] ?? null) ? $nitro['title'] : null,
is_string($nitro['description'] ?? null) ? $nitro['description'] : null,
is_string($flash['title'] ?? null) ? $flash['title'] : null,
is_string($flash['description'] ?? null) ? $flash['description'] : null,
),
];
@@ -156,11 +165,14 @@ class BadgePage extends Page
->send();
$this->data = [
'code' => $badgeCode,
'code' => (string) $badgeCode,
...$this->getDefaultDataBehavior(),
];
}
/**
* @return array<string, mixed>
*/
private function getDefaultDataBehavior(
?string $badgeImageUrl = null,
?string $nitroTitle = null,
@@ -181,7 +193,7 @@ class BadgePage extends Page
];
}
public function create()
public function create(): void
{
$nitroEnabled = config('hotel.client.nitro.enabled');
$flashEnabled = config('hotel.client.flash.enabled');
@@ -219,10 +231,18 @@ class BadgePage extends Page
$this->uploadBadgeImage($externalTextsParser);
if (! empty($this->data['nitro']) && $nitroEnabled) {
$externalTextsParser->updateNitroBadgeTexts($this->data['code'], ...$this->data['nitro']);
$code = is_string($this->data['code'] ?? null) ? $this->data['code'] : '';
$nitro = is_array($this->data['nitro']) ? $this->data['nitro'] : [];
$title = is_string($nitro['title'] ?? null) ? $nitro['title'] : '';
$desc = is_string($nitro['description'] ?? null) ? $nitro['description'] : '';
$externalTextsParser->updateNitroBadgeTexts($code, $title, $desc);
}
if (! empty($this->data['flash']) && $flashEnabled) {
$externalTextsParser->updateFlashBadgeTexts($this->data['code'], ...$this->data['flash']);
$code = is_string($this->data['code'] ?? null) ? $this->data['code'] : '';
$flash = is_array($this->data['flash']) ? $this->data['flash'] : [];
$title = is_string($flash['title'] ?? null) ? $flash['title'] : '';
$desc = is_string($flash['description'] ?? null) ? $flash['description'] : '';
$externalTextsParser->updateFlashBadgeTexts($code, $title, $desc);
}
} catch (Throwable $exception) {
Log::channel('badge')->error('[ORION BADGE RESOURCE] - ERROR: ' . $exception->getMessage());
@@ -237,7 +257,7 @@ class BadgePage extends Page
return;
}
$this->data['image'] = $externalTextsParser->getBadgeImageUrl($this->data['code']);
$this->data['image'] = $externalTextsParser->getBadgeImageUrl(is_string($this->data['code'] ?? null) ? $this->data['code'] : '');
$this->badgeWasPreviouslyCreated = true;
Notification::make()
@@ -250,15 +270,17 @@ class BadgePage extends Page
protected function uploadBadgeImage(ExternalTextsParser $parser): void
{
if (empty($this->data['image']) || ! filter_var($this->data['image'], FILTER_VALIDATE_URL)) {
$imageUrl = is_string($this->data['image'] ?? null) ? $this->data['image'] : '';
$code = is_string($this->data['code'] ?? null) ? $this->data['code'] : '';
if ($imageUrl === '' || ! filter_var($imageUrl, FILTER_VALIDATE_URL)) {
return;
}
if ($this->data['image'] == $parser->getBadgeImageUrl($this->data['code'])) {
if ($imageUrl === $parser->getBadgeImageUrl($code)) {
return;
}
$image = Http::get($this->data['image']);
$image = Http::get($imageUrl);
if (! $image->successful()) {
return;
@@ -267,9 +289,9 @@ class BadgePage extends Page
$contentType = $image->header('content-type');
$gdImage = match ($contentType) {
'image/png' => imagecreatefrompng($this->data['image']),
'image/gif' => imagecreatefromgif($this->data['image']),
'image/jpeg' => imagecreatefromjpeg($this->data['image']),
'image/png' => imagecreatefrompng($imageUrl),
'image/gif' => imagecreatefromgif($imageUrl),
'image/jpeg' => imagecreatefromjpeg($imageUrl),
default => false
};
@@ -284,15 +306,16 @@ class BadgePage extends Page
return;
}
$uploadPath = public_path(sprintf('%s%s%s.gif',
rtrim((string) config('hotel.client.flash.relative_files_path'), '\//'),
'/c_images/album1584/',
$this->data['code'],
));
$basePath = config('hotel.client.flash.relative_files_path');
$basePathStr = is_string($basePath) ? $basePath : '';
$uploadPath = public_path(sprintf('%s%s%s.gif', rtrim($basePathStr, '\//'), '/c_images/album1584/', $code));
imagegif($gdImage, $uploadPath);
}
/**
* @return array<\Filament\Actions\Action|ActionGroup>
*/
/**
* @return array<\Filament\Actions\Action|ActionGroup>
*/
+1 -1
View File
@@ -21,6 +21,6 @@ class Dashboard extends FilamentDashboard
public static function canAccess(): bool
{
return auth()->user()->can('view::admin::' . static::$roleName);
return auth()->check() && auth()->user()?->can('view::admin::' . static::$roleName) === true;
}
}
+21 -9
View File
@@ -14,7 +14,7 @@ use Illuminate\Validation\ValidationException;
class Login extends \Filament\Auth\Pages\Login
{
public $username = '';
public string $username = '';
#[\Override]
public function authenticate(): ?LoginResponse
@@ -22,15 +22,23 @@ class Login extends \Filament\Auth\Pages\Login
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
$seconds = is_numeric($exception->secondsUntilAvailable) ? (int) $exception->secondsUntilAvailable : 0;
$minutes = ceil($seconds / 60);
$body = null;
$throttled = __('filament-panels::pages/auth/login.notifications.throttled');
if (is_array($throttled)) {
$bodyText = __('filament-panels::pages/auth/login.notifications.throttled.body', [
'seconds' => $seconds,
'minutes' => $minutes,
]);
$body = is_string($bodyText) ? $bodyText : null;
}
Notification::make()
->title(__('filament-panels::pages/auth/login.notifications.throttled.title', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
'seconds' => $seconds,
'minutes' => $minutes,
]))
->body(array_key_exists('body', __('filament-panels::pages/auth/login.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/login.notifications.throttled.body', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]) : null)
->body($body)
->danger()
->send();
@@ -39,7 +47,7 @@ class Login extends \Filament\Auth\Pages\Login
$data = $this->form->getState();
if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)) {
if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), (bool) ($data['remember'] ?? false))) {
$this->throwFailureValidationException();
}
@@ -47,7 +55,8 @@ class Login extends \Filament\Auth\Pages\Login
if (
($user instanceof FilamentUser) &&
(! $user->canAccessPanel(Filament::getCurrentOrDefaultPanel()))
($panel = Filament::getCurrentOrDefaultPanel()) instanceof \Filament\Panel &&
(! $user->canAccessPanel($panel))
) {
Filament::auth()->logout();
@@ -66,6 +75,9 @@ class Login extends \Filament\Auth\Pages\Login
]);
}
/**
* @return array<\Illuminate\Contracts\Support\Htmlable|string>
*/
protected function getFormSchema(): array
{
return [
@@ -92,7 +92,7 @@ class ArticleResource extends Resource
->columnSpan('full'),
Hidden::make('user_id')
->default(fn () => auth()->check() ? auth()->user()->id : null),
->default(fn () => auth()->id()),
]),
Tab::make(__('filament::resources.tabs.Configurations'))
@@ -104,8 +104,8 @@ class ArticleResource extends Resource
->offIcon('heroicon-s-x-mark')
->default(true)
->live()
->afterStateUpdated(function (string $operation, $state, $record): void {
if ($operation !== 'edit' || is_null($record)) {
->afterStateUpdated(function (string $operation, bool $state, ?\App\Models\Articles\WebsiteArticle $record): void {
if ($operation !== 'edit' || $record === null) {
return;
}
@@ -119,12 +119,8 @@ class ArticleResource extends Resource
report($e);
}
})
->formatStateUsing(function ($record) {
if (is_null($record)) {
return true;
}
return is_null($record->deleted_at);
->formatStateUsing(function (?\App\Models\Articles\WebsiteArticle $record): bool {
return $record?->deleted_at === null;
}),
Toggle::make('can_comment')
@@ -189,7 +185,7 @@ class ArticleResource extends Resource
->label(__('filament::resources.columns.visible'))
->onIcon('heroicon-s-check')
->toggleable()
->state(fn ($record) => is_null($record->deleted_at))
->state(fn (\App\Models\Articles\WebsiteArticle $record) => is_null($record->deleted_at))
->disabled(),
ToggleColumn::make('allow_comments')
@@ -228,6 +224,6 @@ class ArticleResource extends Resource
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()->withTrashed();
return \App\Models\Articles\WebsiteArticle::query()->withTrashed();
}
}
@@ -15,7 +15,7 @@ class CreateArticle extends CreateRecord
/** @var null|WebsiteArticle $articleCreated */
$articleCreated = $this->getRecord();
if (! $articleCreated || ! $articleCreated->visible) {
if (! $articleCreated || ! (bool) ($articleCreated->getAttribute('is_visible') ?? false)) {
return;
}
@@ -3,6 +3,7 @@
namespace App\Filament\Resources\Atom\Articles\Pages;
use App\Filament\Resources\Atom\Articles\ArticleResource;
use App\Models\Articles\WebsiteArticle;
use Filament\Actions\Action;
use Filament\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;
@@ -19,9 +20,9 @@ class ViewArticle extends ViewRecord
Action::make('Send Notification')
->label(__('Send notifications'))
->color('gray')
->visible(fn (Model $record) => $record->user_id === Auth::id())
->visible(fn (WebsiteArticle $record) => $record->user_id === Auth::id())
->requiresConfirmation()
->action(function (Model $record): void {
->action(function (WebsiteArticle $record): void {
$record->createFollowersNotification();
}),
@@ -13,6 +13,7 @@ use Filament\Forms\Components\TextInput;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class TagsRelationManager extends RelationManager
{
@@ -38,13 +39,17 @@ class TagsRelationManager extends RelationManager
{
return $table
->columns(TagResource::getTable())
->modifyQueryUsing(fn ($query) => $query->latest())
->modifyQueryUsing(fn (Builder $query) => $query->latest())
->filters([
//
])
->headerActions([
CreateAction::make()
->schema(TagResource::getForm()),
->schema([
TextInput::make('name')
->required()
->maxLength(255),
]),
AttachAction::make()->preloadRecordSelect(),
])
@@ -82,6 +82,9 @@ class CmsSettingResource extends Resource
->searchable()
->tooltip(function (TextColumn $column): ?string {
$state = $column->getState();
if (! is_string($state)) {
return null;
}
if (strlen($state) <= $column->getCharacterLimit()) {
return null;
@@ -77,4 +77,9 @@ class WebsiteArticle extends Model
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function createFollowersNotification(): void
{
// Stub to satisfy type checks; implement if needed.
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Services\Parsers;
class ExternalTextsParser
{
public function getBadgeData(string $code): array
{
return [
'image' => null,
'nitro' => [
'title' => null,
'description' => null,
],
'flash' => [
'title' => null,
'description' => null,
],
];
}
public function updateNitroBadgeTexts(string $code, string $title, string $description): void
{
}
public function updateFlashBadgeTexts(string $code, string $title, string $description): void
{
}
public function getBadgeImageUrl(string $code): string
{
return '';
}
}
+12
View File
@@ -108,3 +108,15 @@
[2026-01-20 18:37:41] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
[2026-01-20 18:50:49] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
[2026-01-20 18:54:15] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
[2026-01-20 19:02:53] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
[2026-01-20 19:08:00] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
[2026-01-20 19:11:13] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 77824 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 77824 bytes) at phar://C:/Github/Epicnabbo-Catalogus-2025FullPack-Updated-Daily/Updated_Cms/vendor/phpstan/phpstan/phpstan.phar/src/File/FileReader.php:16)
[stacktrace]
#0 {main}
"}
[2026-01-20 19:11:13] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 315392 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 315392 bytes) at phar://C:/Github/Epicnabbo-Catalogus-2025FullPack-Updated-Daily/Updated_Cms/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Lexer.php:31)
[stacktrace]
#0 {main}
"}
[2026-01-20 19:11:43] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
[2026-01-20 19:11:45] production.ERROR: RCON connection failed: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd