Files
LarsandCursor 8ebc1a3878 Assign the existing site to one landlord so stommer.info can run tenancy.
Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-23 12:00:11 +02:00

91 lines
2.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
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 BelongsToTenant, 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;
}
}