Files
fewo-stommer/app/Filament/Resources/Notices/Schemas/NoticeForm.php
T
LarsandClaude Opus 5.5 d2b1a853dc Banner zentral: je Website, Saison und Prioritaet, auch fuer Sonderangebote
Hinweise werden zu Bannern mit Website, Erscheinungsbildern, Prioritaet und
optionalem Sonderangebot (Text, Termin und Link aus dem Angebot, sichtbar nur
solange es beworben wird). Sonderangebote lassen sich mit einem Klick als Banner
zeigen; die Liste nennt das heute sichtbare Banner. Banner-Texte der
Erscheinungsbilder werden zu saisonalen Bannern.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 19:01:48 +01:00

108 lines
5.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Resources\Notices\Schemas;
use App\Enums\NoticeTone;
use App\Filament\Resources\Photos\Schemas\PhotoForm;
use App\Models\Appearance;
use App\Models\Property;
use App\Models\Site;
use App\Models\SpecialOffer;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
class NoticeForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Inhalt')
->columns(2)
->schema([
Select::make('special_offer_id')
->label('Sonderangebot bewerben (optional)')
->options(fn (): array => self::offerOptions())
->placeholder('– kein Angebot –')
->searchable()
->live()
->helperText('Mit Angebot kommen Text, Termin und Link aus dem Angebot, und das Banner erscheint nur, solange die Website das Angebot bewirbt – bei festen Terminen also nur, solange sie frei sind.')
->columnSpanFull(),
TextInput::make('text')
->label('Text')
->placeholder(fn (Get $get): string => filled($get('special_offer_id')) ? 'leer = Text aus dem Angebot' : 'z. B. Kurzfristig frei: 12.–15.11. mit 15 % Rabatt')
->required(fn (Get $get): bool => blank($get('special_offer_id')))
->maxLength(255)
->columnSpanFull(),
TextInput::make('link_label')
->label('Link-Text (optional)')
->placeholder(fn (Get $get): string => filled($get('special_offer_id')) ? 'Zum Angebot' : 'z. B. Jetzt anfragen')
->maxLength(100),
TextInput::make('link_url')
->label('Link-Ziel (optional)')
->placeholder(fn (Get $get): string => filled($get('special_offer_id')) ? 'Buchung mit den Angebotsterminen' : '/buchen')
->maxLength(255),
Select::make('tone')
->label('Art')
->options(NoticeTone::class)
->default(NoticeTone::Info)
->required(),
]),
Section::make('Wann und wo')
->description('Es erscheint immer nur ein Banner: Gelten mehrere gleichzeitig, gewinnt die höchste Priorität, bei Gleichstand das neueste.')
->columns(2)
->schema([
Select::make('site_id')
->label('Website')
->options(fn (): array => Site::query()->pluck('name', 'id')->all())
->placeholder('alle Websites')
->visible(fn (): bool => Site::query()->count() > 1),
Select::make('appearance_ids')
->label('Nur in Erscheinungsbildern')
->multiple()
->options(fn (): array => Appearance::photoOptions())
->placeholder('immer')
->helperText('Leer = in jedem Erscheinungsbild, z. B. Weihnachten und Silvester für ein Festtagsbanner.')
->dehydrateStateUsing(fn (?array $state): ?array => PhotoForm::appearanceIds($state)),
DatePicker::make('starts_on')
->label('Anzeigen ab (optional)'),
DatePicker::make('ends_on')
->label('Anzeigen bis (optional)')
->afterOrEqual('starts_on'),
TextInput::make('priority')
->label('Priorität')
->integer()
->minValue(0)
->maxValue(999)
->default(10)
->required(),
Toggle::make('is_active')
->label('Aktiv')
->default(true)
->inline(false),
]),
]);
}
/**
* Offers the website can advertise (public, without a code), named with their apartment when there are several.
*
* @return array<int, string>
*/
public static function offerOptions(): array
{
$severalProperties = Property::query()->count() > 1;
return SpecialOffer::query()->with('property')->where('is_public', true)->whereNull('code')->orderBy('name')->get()
->mapWithKeys(fn (SpecialOffer $offer): array => [$offer->id => $offer->name
.($severalProperties ? ' · '.$offer->property?->name : '')
.($offer->is_active ? '' : ' (inaktiv)')])
->all();
}
}