Files
fewo-stommer/app/Models/Notice.php
LarsandClaude Opus 5.5 d2b1a853dc Banner zentral: je Website, Saison und Prioritaet, auch fuer Sonderangebote
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>
2026-10-29 19:01:48 +01:00

75 lines
2.3 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\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()));
}
}