- 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>
63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?php
|
||
|
||
namespace App\Themes;
|
||
|
||
use App\Models\Appearance;
|
||
use App\Models\Site;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Schema;
|
||
|
||
/**
|
||
* Builds the theme context: the site by host name (else the default site), the appearance in effect today –
|
||
* or the one named in a signed preview link (?vorschau=<id>).
|
||
*/
|
||
class ThemeFactory
|
||
{
|
||
public function __construct(private ThemeRegistry $registry) {}
|
||
|
||
public function forRequest(Request $request): Theme
|
||
{
|
||
$site = $this->site($request->getHost());
|
||
$isSigned = ($request->query('vorschau') || $request->query('theme')) && $request->hasValidSignature();
|
||
|
||
$preview = $isSigned && $request->query('vorschau') ? $site->appearances()->find($request->query('vorschau')) : null;
|
||
|
||
// Theme preview: the site is shown with another installed theme without changing it (not saved).
|
||
$previewTheme = $isSigned ? (string) $request->query('theme') : '';
|
||
if ($previewTheme !== '' && isset($this->registry->all()[$previewTheme])) {
|
||
$site = (clone $site)->setAttribute('theme', $previewTheme);
|
||
|
||
return $this->forSite($site, $preview, isPreview: true);
|
||
}
|
||
|
||
return $this->forSite($site, $preview);
|
||
}
|
||
|
||
public function forSite(Site $site, ?Appearance $preview = null, bool $isPreview = false): Theme
|
||
{
|
||
return new Theme(
|
||
$this->registry,
|
||
$site,
|
||
$preview ?? ($site->exists ? $site->appearanceOn(today()) : null),
|
||
isPreview: $isPreview || $preview !== null,
|
||
);
|
||
}
|
||
|
||
public function site(?string $host = null): Site
|
||
{
|
||
if (! Schema::hasTable('sites')) {
|
||
return $this->fallbackSite();
|
||
}
|
||
|
||
return ($host ? Site::query()->where('domain', $host)->first() : null)
|
||
?? Site::query()->where('is_default', true)->first()
|
||
?? Site::query()->orderBy('id')->first()
|
||
?? $this->fallbackSite();
|
||
}
|
||
|
||
private function fallbackSite(): Site
|
||
{
|
||
return new Site(['name' => config('app.name'), 'theme' => config('themes.base')]);
|
||
}
|
||
}
|