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

+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);