Offers by their own rules, seasonal photos per section, theme authoring tooling

- 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>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 18:51:38 +02:00
1 parent bc77b64ea7
commit 7d0bc93abc
50 files changed
+2805 -259

No files matched your search

+4 -10
View File
@@ -11,10 +11,11 @@
/**
* A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, hero photo,
* texts and banner change – the page structure does not. The period recurs every year ("MM-DD" to "MM-DD",
* 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', 'featured_offer_id'])]
#[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> */
@@ -46,6 +47,7 @@ protected function casts(): array
'is_active' => 'boolean',
'tokens' => 'array',
'overrides' => 'array',
'section_photos' => 'array',
];
}
@@ -65,14 +67,6 @@ public function heroPhoto(): BelongsTo
return $this->belongsTo(Photo::class, 'hero_photo_id');
}
/**
* @return BelongsTo<SpecialOffer, $this>
*/
public function featuredOffer(): BelongsTo
{
return $this->belongsTo(SpecialOffer::class, 'featured_offer_id');
}
public function covers(CarbonInterface $date): bool
{
if ($this->starts_md === null || $this->ends_md === null) {
+31
View File
@@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
/**
* A page of a site, composed of sections from the catalogue (App\Themes\Sections).
@@ -59,4 +60,34 @@ public function label(): string
{
return $this->menu_label ?: $this->title;
}
protected static function booted(): void
{
static::saving(function (Page $page): void {
$page->sections = self::assignSectionIds($page->sections ?? []);
});
}
/**
* Gives every placed section a stable id (data.id) – new and duplicated sections get a fresh one –
* so appearances can address sections independently of their order.
*
* @param list<array{type: string, data?: array<string, mixed>}> $sections
* @return list<array{type: string, data: array<string, mixed>}>
*/
public static function assignSectionIds(array $sections): array
{
$seen = [];
return array_values(array_map(function (array $section) use (&$seen): array {
$data = $section['data'] ?? [];
$id = $data['id'] ?? null;
if (! is_string($id) || $id === '' || isset($seen[$id])) {
$id = (string) Str::uuid();
}
$seen[$id] = true;
return [...$section, 'data' => [...$data, 'id' => $id]];
}, $sections));
}
}
+67 -3
View File
@@ -3,7 +3,9 @@
namespace App\Models;
use App\Enums\DiscountType;
use App\Enums\OfferKind;
use App\Pricing\StayRequest;
use App\Support\Money;
use Carbon\CarbonImmutable;
use Database\Factories\SpecialOfferFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
@@ -14,16 +16,19 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* A discount rule such as last minute, early bird, long stay, special weekends or a code for regular guests.
* Every condition left empty means "no restriction".
* A discount rule such as last minute, early bird, long stay, special weekends or a code for regular guests,
* a fixed date package or a gap filler (see OfferKind). Every condition left empty means "no restriction".
*/
#[Fillable([
'property_id',
'name',
'kind',
'public_description',
'is_active',
'is_public',
'is_combinable',
'priority',
'is_featured',
'code',
'discount_type',
'discount_value',
@@ -35,6 +40,8 @@
'max_days_before_arrival',
'min_nights',
'max_nights',
'max_gap_nights',
'waives_min_stay',
'arrival_weekdays',
'season_names',
])]
@@ -54,6 +61,9 @@ protected function casts(): array
'is_active' => 'boolean',
'is_public' => 'boolean',
'is_combinable' => 'boolean',
'is_featured' => 'boolean',
'waives_min_stay' => 'boolean',
'kind' => OfferKind::class,
'discount_type' => DiscountType::class,
'stay_from' => 'immutable_date',
'stay_until' => 'immutable_date',
@@ -84,13 +94,23 @@ protected function active(Builder $query): Builder
/**
* Whether all conditions are met. Offers with a code only apply when the guest entered that code.
* $gapNights is the length of the calendar gap containing the stay (null = not inside a gap); it only
* matters for gap fillers.
*/
public function appliesTo(StayRequest $stay, string $arrivalSeasonName, CarbonImmutable $bookedAt): bool
public function appliesTo(StayRequest $stay, string $arrivalSeasonName, CarbonImmutable $bookedAt, ?int $gapNights = null): bool
{
$nights = $stay->nights();
$daysBeforeArrival = (int) $bookedAt->startOfDay()->diffInDays($stay->arrival, false);
$kindMatches = match ($this->kind ?? OfferKind::Rule) {
OfferKind::Rule => true,
OfferKind::FixedDates => $this->stay_from !== null && $this->stay_until !== null
&& $stay->arrival->isSameDay($this->stay_from) && $stay->departure->isSameDay($this->stay_until),
OfferKind::GapFiller => $gapNights !== null && ($this->max_gap_nights === null || $gapNights <= $this->max_gap_nights),
};
return $this->is_active
&& $kindMatches
&& ($this->code === null || strcasecmp($this->code, (string) $stay->promoCode) === 0)
&& ($this->stay_from === null || $stay->arrival->greaterThanOrEqualTo($this->stay_from))
&& ($this->stay_until === null || $stay->departure->lessThanOrEqualTo($this->stay_until))
@@ -118,11 +138,55 @@ public function discountFor(array $nightlyRates): int
DiscountType::AmountPerStay => $this->discount_value,
DiscountType::NightlyRate => array_sum(array_map(fn (int $rate): int => max(0, $rate - $this->discount_value), $nightlyRates)),
DiscountType::FreeNights => array_sum(array_slice($this->sortedAscending($nightlyRates), 0, $this->discount_value)),
DiscountType::FixedStayPrice => max(0, $accommodation - $this->discount_value),
};
return min($discount, $accommodation);
}
/**
* Short label of the advantage, e.g. "−10 %", "59,00 € / Nacht" or "Pauschal 560,00 €".
*/
public function advantageLabel(): string
{
return match ($this->discount_type) {
DiscountType::Percent => "−{$this->discount_value} %",
DiscountType::AmountPerStay => '−'.Money::format($this->discount_value),
DiscountType::NightlyRate => Money::format($this->discount_value).' / Nacht',
DiscountType::FreeNights => $this->discount_value === 1 ? '1 Nacht gratis' : "{$this->discount_value} Nächte gratis",
DiscountType::FixedStayPrice => 'Pauschal '.Money::format($this->discount_value),
};
}
/**
* The conditions in plain German for guests, e.g. ["ab 3 Nächten", "Anreise freitags", "bis 14 Tage vor Anreise"].
*
* @return list<string>
*/
public function conditionSummary(): array
{
$weekdays = [1 => 'montags', 2 => 'dienstags', 3 => 'mittwochs', 4 => 'donnerstags', 5 => 'freitags', 6 => 'samstags', 7 => 'sonntags'];
return array_values(array_filter([
match (true) {
$this->kind === OfferKind::FixedDates => null,
$this->min_nights !== null && $this->max_nights !== null && $this->min_nights === $this->max_nights => "genau {$this->min_nights} Nächte",
$this->min_nights !== null && $this->max_nights !== null => "{$this->min_nights} bis {$this->max_nights} Nächte",
$this->min_nights !== null => "ab {$this->min_nights} Nächten",
$this->max_nights !== null => "bis {$this->max_nights} Nächte",
default => null,
},
empty($this->arrival_weekdays) ? null : 'Anreise '.collect($this->arrival_weekdays)->map(fn ($day): string => $weekdays[(int) $day] ?? '')->implode(' oder '),
$this->max_days_before_arrival !== null ? "Buchung bis {$this->max_days_before_arrival} Tage vor Anreise" : null,
$this->min_days_before_arrival !== null ? "Buchung mindestens {$this->min_days_before_arrival} Tage vor Anreise" : null,
empty($this->season_names) ? null : 'Anreise in: '.implode(', ', $this->season_names),
$this->kind !== OfferKind::FixedDates && ($this->stay_from || $this->stay_until)
? 'Reisezeitraum '.($this->stay_from?->format('d.m.Y') ?? 'ab sofort').' – '.($this->stay_until?->format('d.m.Y') ?? 'offen')
: null,
$this->bookable_until !== null ? 'buchbar bis '.$this->bookable_until->format('d.m.Y') : null,
]));
}
/**
* @param list<int> $rates
* @return list<int>