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>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-29 19:01:48 +01:00
1 parent 791786ed3e
commit d2b1a853dc
21 files changed
+618 -106

No files matched your search

@@ -45,7 +45,7 @@ public static function configure(Schema $schema): Schema
Text::make(fn (?Appearance $record): string => self::photoSummary($record)),
]),
Section::make('Texte')
->description('Leer lassen = Text der Seite bzw. kein Banner.')
->description('Leer lassen = Text der Seite. Banner pflegen Sie unter Webseite › Banner & Hinweise – dort auch nur für dieses Erscheinungsbild.')
->columns(2)
->collapsible()
->schema(collect(Appearance::OVERRIDABLE)
@@ -9,6 +9,10 @@
use App\Filament\Resources\Notices\Schemas\NoticeForm;
use App\Filament\Resources\Notices\Tables\NoticesTable;
use App\Models\Notice;
use App\Models\Site;
use App\Tenancy\TenantContext;
use App\Themes\Banner;
use App\Themes\ThemeFactory;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
@@ -26,9 +30,9 @@ class NoticeResource extends Resource
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
protected static ?string $modelLabel = 'Hinweis';
protected static ?string $modelLabel = 'Banner';
protected static ?string $pluralModelLabel = 'Hinweis-Banner';
protected static ?string $pluralModelLabel = 'Banner & Hinweise';
protected static ?int $navigationSort = 6;
@@ -49,6 +53,31 @@ public static function getRelations(): array
];
}
/**
* The banner each website shows today (none = null), with the website.
*
* @return list<array{site: Site, banner: Banner|null}>
*/
public static function bannersToday(): array
{
$tenantId = app(TenantContext::class)->id();
// once() keys its cache by the variables the closure uses, so each landlord gets its own entry.
return once(function () use ($tenantId): array {
return Site::query()->when($tenantId, fn ($query) => $query->where('tenant_id', $tenantId))->orderBy('name')->get()
->map(fn (Site $site): array => ['site' => $site, 'banner' => app(ThemeFactory::class)->forSite($site)->banner()])
->all();
});
}
/**
* @return list<int>
*/
public static function noticeIdsShownToday(): array
{
return collect(self::bannersToday())->pluck('banner')->filter()->map(fn (Banner $banner): int => $banner->notice->id)->unique()->values()->all();
}
public static function getPages(): array
{
return [
@@ -10,6 +10,23 @@ class ListNotices extends ListRecords
{
protected static string $resource = NoticeResource::class;
/**
* Which banner the website shows today – the answer to "why do I see this banner?".
*/
public function getSubheading(): ?string
{
$today = NoticeResource::bannersToday();
if ($today === []) {
return null;
}
return collect($today)->map(function (array $entry) use ($today): string {
$prefix = count($today) > 1 ? $entry['site']->name.': ' : '';
return $prefix.($entry['banner'] ? 'Heute sichtbar: „'.$entry['banner']->text.'“' : 'Heute ist kein Banner sichtbar.');
})->implode(' · ');
}
protected function getHeaderActions(): array
{
return [
@@ -3,10 +3,17 @@
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
@@ -14,36 +21,87 @@ class NoticeForm
public static function configure(Schema $schema): Schema
{
return $schema
->columns(2)
->components([
TextInput::make('text')
->label('Hinweistext')
->placeholder('z. B. Kurzfristig frei: 12.–15.11. mit 15 % Rabatt')
->required()
->maxLength(255)
->columnSpanFull(),
Select::make('tone')
->label('Art')
->options(NoticeTone::class)
->default(NoticeTone::Info)
->required(),
Toggle::make('is_active')
->label('Aktiv')
->default(true)
->inline(false),
DatePicker::make('starts_on')
->label('Anzeigen ab (optional)'),
DatePicker::make('ends_on')
->label('Anzeigen bis (optional)')
->afterOrEqual('starts_on'),
TextInput::make('link_label')
->label('Link-Text (optional)')
->placeholder('z. B. Jetzt anfragen')
->maxLength(100),
TextInput::make('link_url')
->label('Link-Ziel (optional)')
->placeholder('/buchen')
->maxLength(255),
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();
}
}
@@ -2,8 +2,11 @@
namespace App\Filament\Resources\Notices\Tables;
use App\Filament\Resources\Notices\NoticeResource;
use App\Models\Notice;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Table;
@@ -13,14 +16,33 @@ class NoticesTable
public static function configure(Table $table): Table
{
return $table
->defaultSort('starts_on', 'desc')
->defaultSort('priority', 'desc')
->columns([
TextColumn::make('text')->label('Hinweis')->wrap()->searchable(),
TextColumn::make('tone')->label('Art')->badge(),
IconColumn::make('shown_today')
->label('Heute')
->state(fn (Notice $record): bool => in_array($record->id, NoticeResource::noticeIdsShownToday(), true))
->boolean()
->trueIcon('heroicon-s-eye')
->falseIcon('heroicon-o-minus')
->tooltip(fn (bool $state): string => $state ? 'Wird heute auf der Website gezeigt' : 'Heute nicht sichtbar'),
TextColumn::make('text')
->label('Banner')
->state(fn (Notice $record): string => filled($record->text) ? $record->text : 'Text aus dem Angebot')
->description(fn (Notice $record): ?string => $record->specialOffer ? 'Angebot: '.$record->specialOffer->name : null)
->wrap()
->searchable(),
TextColumn::make('appearance_ids')
->label('Erscheinungsbilder')
->state(fn (Notice $record): array => $record->appearanceNames())
->badge()
->placeholder('immer'),
TextColumn::make('site.name')->label('Website')->placeholder('alle')->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('starts_on')->label('Ab')->date('d.m.Y')->placeholder('sofort'),
TextColumn::make('ends_on')->label('Bis')->date('d.m.Y')->placeholder('unbegrenzt'),
TextColumn::make('priority')->label('Priorität')->sortable(),
ToggleColumn::make('is_active')->label('Aktiv'),
])
->modifyQueryUsing(fn ($query) => $query->with(['specialOffer', 'site']))
->recordActions([
EditAction::make(),
DeleteAction::make(),
@@ -3,8 +3,12 @@
namespace App\Filament\Resources\Properties\RelationManagers;
use App\Enums\DiscountType;
use App\Enums\NoticeTone;
use App\Enums\OfferKind;
use App\Filament\Resources\Notices\NoticeResource;
use App\Models\Notice;
use App\Models\SpecialOffer;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
@@ -21,9 +25,11 @@
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Gate;
class SpecialOffersRelationManager extends RelationManager
{
@@ -218,6 +224,21 @@ public function table(Table $table): Table
])
->recordActions([
EditAction::make(),
Action::make('banner')
->label('Als Banner zeigen')
->icon(Heroicon::OutlinedMegaphone)
->visible(fn (SpecialOffer $record): bool => $record->is_public && blank($record->code) && Gate::allows('create', Notice::class))
->action(function (SpecialOffer $record) {
$notice = Notice::query()->create([
'site_id' => $record->property?->site_id,
'special_offer_id' => $record->id,
'tone' => NoticeTone::Offer,
'priority' => 30,
'is_active' => true,
]);
return redirect(NoticeResource::getUrl('edit', ['record' => $notice]));
}),
ReplicateAction::make()->label('Duplizieren')->schema(fn (Schema $schema): Schema => $this->form($schema)),
DeleteAction::make(),
]);