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>
75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
||
|
||
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;
|
||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||
use Illuminate\Database\Eloquent\Builder;
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
||
/**
|
||
* 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(['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 BelongsToAppearances, BelongsToTenant, HasFactory;
|
||
|
||
/**
|
||
* Get the attributes that should be cast.
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
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.
|
||
*
|
||
* @param Builder<Notice> $query
|
||
* @return Builder<Notice>
|
||
*/
|
||
#[Scope]
|
||
protected function visible(Builder $query): Builder
|
||
{
|
||
return $query
|
||
->where('is_active', true)
|
||
->where(fn (Builder $query) => $query->whereNull('starts_on')->orWhereDate('starts_on', '<=', today()))
|
||
->where(fn (Builder $query) => $query->whereNull('ends_on')->orWhereDate('ends_on', '>=', today()));
|
||
}
|
||
}
|