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(),
]);
+4 -9
View File
@@ -12,8 +12,8 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, texts and banner
* change, photos made for it (Photo::appearance_ids) are shown – the page structure does not (sections may be limited to
* A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens and texts change,
* photos and banners made for it (appearance_ids) are shown – the page structure does not (sections may be limited to
* appearances, see SectionRegistry). Offers are advertised by their own rules (OfferShowcase). The period recurs every year ("MM-DD" to "MM-DD",
* inclusive; a period may run over the turn of the year). The default appearance applies when none matches.
*/
@@ -27,9 +27,6 @@ class Appearance extends Model
* Texts an appearance can replace, with their admin labels. Sections read them through Theme::text().
*/
public const OVERRIDABLE = [
'banner.text' => 'Banner: Text',
'banner.link_label' => 'Banner: Link-Text',
'banner.link_url' => 'Banner: Link-Ziel',
'hero.eyebrow' => 'Titelbereich: kleine Überschrift',
'hero.title' => 'Titelbereich: Überschrift',
'hero.text' => 'Titelbereich: Text',
@@ -67,12 +64,10 @@ public function site(): BelongsTo
*/
public static function names(): array
{
// once() keys its cache by the closure's bound variables, so each landlord gets its own entry.
$tenantId = app(TenantContext::class)->id();
return once(function (): array {
return self::query()->pluck('name', 'id')->all();
});
// once() keys its cache by the variables the closure uses, so each landlord gets its own entry.
return once(fn (): array => self::query()->when($tenantId, fn ($query) => $query->where('tenant_id', $tenantId))->pluck('name', 'id')->all());
}
/**
@@ -0,0 +1,48 @@
<?php
namespace App\Models\Concerns;
use App\Models\Appearance;
/**
* For models with an "appearance_ids" list (photos, banners): none = all year, otherwise only while one of
* these appearances (summer, winter, Christmas …) is in effect.
*/
trait BelongsToAppearances
{
/**
* Appearance ids as integers (the form may deliver strings).
*
* @return list<int>
*/
public function appearanceIds(): array
{
return array_values(array_unique(array_map('intval', array_filter((array) $this->appearance_ids))));
}
/**
* Whether the record may be shown while this appearance is in effect: all-year ones always, seasonal ones in their seasons.
*/
public function fitsSeason(?Appearance $appearance): bool
{
return $this->appearanceIds() === [] || $this->isMadeFor($appearance);
}
/**
* Whether the record was chosen for this appearance.
*/
public function isMadeFor(?Appearance $appearance): bool
{
return $appearance !== null && in_array($appearance->id, $this->appearanceIds(), true);
}
/**
* Names of the appearances the record is made for (empty = all year).
*
* @return list<string>
*/
public function appearanceNames(): array
{
return array_values(array_intersect_key(Appearance::names(), array_flip($this->appearanceIds())));
}
}
+25 -3
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\NoticeTone;
use App\Models\Concerns\BelongsToAppearances;
use App\Models\Concerns\BelongsToTenant;
use Database\Factories\NoticeFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
@@ -10,15 +11,18 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* A banner shown on the website, optionally limited to a date range.
* A banner at the top of the website: for one website or all, optionally only in some appearances (seasons)
* and within a date range. It may advertise a special offer – then text, dates and link come from the offer
* and the banner only shows while the website advertises that offer. The highest priority wins (BannerResolver).
*/
#[Fillable(['text', 'tone', 'link_url', 'link_label', 'starts_on', 'ends_on', 'is_active'])]
#[Fillable(['site_id', 'special_offer_id', 'appearance_ids', 'priority', 'text', 'tone', 'link_url', 'link_label', 'starts_on', 'ends_on', 'is_active'])]
class Notice extends Model
{
/** @use HasFactory<NoticeFactory> */
use BelongsToTenant, HasFactory;
use BelongsToAppearances, BelongsToTenant, HasFactory;
/**
* Get the attributes that should be cast.
@@ -29,12 +33,30 @@ protected function casts(): array
{
return [
'tone' => NoticeTone::class,
'appearance_ids' => 'array',
'priority' => 'integer',
'starts_on' => 'immutable_date',
'ends_on' => 'immutable_date',
'is_active' => 'boolean',
];
}
/**
* @return BelongsTo<Site, $this>
*/
public function site(): BelongsTo
{
return $this->belongsTo(Site::class);
}
/**
* @return BelongsTo<SpecialOffer, $this>
*/
public function specialOffer(): BelongsTo
{
return $this->belongsTo(SpecialOffer::class);
}
/**
* Active notices whose date range includes today.
*
+2 -37
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\PhotoCategory;
use App\Models\Concerns\BelongsToAppearances;
use App\Models\Concerns\BelongsToTenant;
use Database\Factories\PhotoFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
@@ -26,7 +27,7 @@
class Photo extends Model implements HasMedia
{
/** @use HasFactory<PhotoFactory> */
use BelongsToTenant, HasFactory, InteractsWithMedia;
use BelongsToAppearances, BelongsToTenant, HasFactory, InteractsWithMedia;
public const COLLECTION = 'image';
@@ -127,42 +128,6 @@ public static function automatic(?Property $property, ?Appearance $appearance, ?
->values();
}
/**
* Appearance ids as integers (the form may deliver strings).
*
* @return list<int>
*/
public function appearanceIds(): array
{
return array_values(array_unique(array_map('intval', array_filter((array) $this->appearance_ids))));
}
/**
* Whether the photo may be shown while this appearance is in effect: all-year photos always, seasonal ones in their seasons.
*/
public function fitsSeason(?Appearance $appearance): bool
{
return $this->appearanceIds() === [] || $this->isMadeFor($appearance);
}
/**
* Whether the photo was chosen for this appearance (seasonal photos come first while it is in effect).
*/
public function isMadeFor(?Appearance $appearance): bool
{
return $appearance !== null && in_array($appearance->id, $this->appearanceIds(), true);
}
/**
* Names of the appearances the photo is made for (empty = all year).
*
* @return list<string>
*/
public function appearanceNames(): array
{
return array_values(array_intersect_key(Appearance::names(), array_flip($this->appearanceIds())));
}
public function url(string $size = 'md'): string
{
return $this->getFirstMediaUrl(self::COLLECTION, $size);
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Themes;
use App\Enums\NoticeTone;
use App\Models\Notice;
/**
* The banner the website shows right now (BannerResolver): text, optional link, tone.
*/
final readonly class Banner
{
public function __construct(
public Notice $notice,
public string $text,
public ?string $linkLabel,
public ?string $linkUrl,
public NoticeTone $tone,
) {}
}
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace App\Themes;
use App\Models\Appearance;
use App\Models\Notice;
use App\Models\Site;
use App\Pricing\AdvertisedOffer;
use App\Pricing\OfferShowcase;
use Illuminate\Support\Collection;
/**
* Picks the banner of a website: among the visible notices for this website (or all websites) that fit the
* appearance in effect, the highest priority wins, then the newest. A notice advertising a special offer only
* counts while the website advertises that offer; text, dates and link then come from the offer unless the
* notice sets its own.
*/
class BannerResolver
{
public function __construct(private OfferShowcase $showcase) {}
public function for(Site $site, ?Appearance $appearance): ?Banner
{
foreach ($this->candidates($site, $appearance) as $notice) {
$banner = $this->banner($notice);
if ($banner !== null) {
return $banner;
}
}
return null;
}
/**
* Visible notices for the website and the appearance, in the order they compete.
*
* @return Collection<int, Notice>
*/
public function candidates(Site $site, ?Appearance $appearance): Collection
{
return Notice::query()->visible()
->where(fn ($query) => $query->whereNull('site_id')->when($site->exists, fn ($query) => $query->orWhere('site_id', $site->id)))
->with('specialOffer.property')
->orderByDesc('priority')
->latest()
->orderByDesc('id')
->get()
->filter(fn (Notice $notice): bool => $notice->fitsSeason($appearance))
->values();
}
private function banner(Notice $notice): ?Banner
{
if ($notice->special_offer_id === null) {
return filled($notice->text)
? new Banner($notice, (string) $notice->text, $notice->link_label, $notice->link_label ? ($notice->link_url ?: route('booking.create')) : null, $notice->tone)
: null;
}
$offer = $notice->specialOffer;
$advertised = $offer?->property
? $this->showcase->current($offer->property)->first(fn (AdvertisedOffer $advertised): bool => $advertised->offer->is($offer))
: null;
if ($advertised === null) {
return null;
}
return new Banner(
$notice,
filled($notice->text) ? (string) $notice->text : self::offerText($advertised),
$notice->link_label ?: 'Zum Angebot',
$notice->link_url ?: $advertised->bookingUrl(),
$notice->tone,
);
}
/**
* "Kurzfristig frei: 12.11.–15.11. · 15 % günstiger".
*/
public static function offerText(AdvertisedOffer $advertised): string
{
$dates = $advertised->arrival && $advertised->departure
? ': '.$advertised->arrival->format('d.m.').'–'.$advertised->departure->format('d.m.')
: '';
return $advertised->title.$dates.' · '.$advertised->advantage;
}
}
+17
View File
@@ -23,6 +23,10 @@ class Theme
private bool $propertyResolved = false;
private ?Banner $banner = null;
private bool $bannerResolved = false;
/** @var array<string, Collection<int, Page>> */
private array $menus = [];
@@ -115,6 +119,19 @@ public function sharePhoto(array $sections = []): ?Photo
return $first ?? Photo::automatic($this->property(), $this->appearance)->first();
}
/**
* The banner at the top of the website right now (Admin › Webseite › Banner & Hinweise), or null.
*/
public function banner(): ?Banner
{
if (! $this->bannerResolved) {
$this->banner = app(BannerResolver::class)->for($this->site, $this->appearance);
$this->bannerResolved = true;
}
return $this->banner;
}
public function appearanceKey(): string
{
return $this->appearance ? str($this->appearance->name)->slug()->toString() : 'standard';