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>
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
use App\Models\Appearance;
|
|
|
|
/**
|
|
* For models with an "appearance_ids" list (photos, banners): none = all year, otherwise only while one of
|
|
* these appearances (summer, winter, Christmas …) is in effect.
|
|
*/
|
|
trait BelongsToAppearances
|
|
{
|
|
/**
|
|
* Appearance ids as integers (the form may deliver strings).
|
|
*
|
|
* @return list<int>
|
|
*/
|
|
public function appearanceIds(): array
|
|
{
|
|
return array_values(array_unique(array_map('intval', array_filter((array) $this->appearance_ids))));
|
|
}
|
|
|
|
/**
|
|
* Whether the record may be shown while this appearance is in effect: all-year ones always, seasonal ones in their seasons.
|
|
*/
|
|
public function fitsSeason(?Appearance $appearance): bool
|
|
{
|
|
return $this->appearanceIds() === [] || $this->isMadeFor($appearance);
|
|
}
|
|
|
|
/**
|
|
* Whether the record was chosen for this appearance.
|
|
*/
|
|
public function isMadeFor(?Appearance $appearance): bool
|
|
{
|
|
return $appearance !== null && in_array($appearance->id, $this->appearanceIds(), true);
|
|
}
|
|
|
|
/**
|
|
* Names of the appearances the record is made for (empty = all year).
|
|
*
|
|
* @return list<string>
|
|
*/
|
|
public function appearanceNames(): array
|
|
{
|
|
return array_values(array_intersect_key(Appearance::names(), array_flip($this->appearanceIds())));
|
|
}
|
|
}
|