- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
colours, external resources, WCAG contrast), themes:preview (signed links per page and
appearance), signed ?theme= preview and preview action in the site form, inherited colour
tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Carbon\CarbonInterface;
|
||
use Database\Factories\AppearanceFactory;
|
||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
||
/**
|
||
* A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, hero photo,
|
||
* photos per section, texts and banner change – 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.
|
||
*/
|
||
#[Fillable(['site_id', 'name', 'starts_md', 'ends_md', 'priority', 'is_default', 'is_active', 'tokens', 'overrides', 'hero_photo_id', 'section_photos'])]
|
||
class Appearance extends Model
|
||
{
|
||
/** @use HasFactory<AppearanceFactory> */
|
||
use HasFactory;
|
||
|
||
/**
|
||
* 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',
|
||
'cta.title' => 'Abschluss: Überschrift',
|
||
'cta.text' => 'Abschluss: Text',
|
||
];
|
||
|
||
/**
|
||
* Get the attributes that should be cast.
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
protected function casts(): array
|
||
{
|
||
return [
|
||
'is_default' => 'boolean',
|
||
'is_active' => 'boolean',
|
||
'tokens' => 'array',
|
||
'overrides' => 'array',
|
||
'section_photos' => 'array',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return BelongsTo<Site, $this>
|
||
*/
|
||
public function site(): BelongsTo
|
||
{
|
||
return $this->belongsTo(Site::class);
|
||
}
|
||
|
||
/**
|
||
* @return BelongsTo<Photo, $this>
|
||
*/
|
||
public function heroPhoto(): BelongsTo
|
||
{
|
||
return $this->belongsTo(Photo::class, 'hero_photo_id');
|
||
}
|
||
|
||
public function covers(CarbonInterface $date): bool
|
||
{
|
||
if ($this->starts_md === null || $this->ends_md === null) {
|
||
return false;
|
||
}
|
||
|
||
$day = $date->format('m-d');
|
||
|
||
return $this->starts_md <= $this->ends_md
|
||
? $day >= $this->starts_md && $day <= $this->ends_md
|
||
: $day >= $this->starts_md || $day <= $this->ends_md;
|
||
}
|
||
|
||
public function override(string $key): ?string
|
||
{
|
||
$value = data_get($this->overrides, $key);
|
||
|
||
return filled($value) ? (string) $value : null;
|
||
}
|
||
}
|