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>
This commit is contained in:
1 parent
791786ed3e
commit
d2b1a853dc
21 files changed
+618
-106
No files matched your search
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Themes;
|
||||
|
||||
use App\Models\Appearance;
|
||||
use App\Models\Notice;
|
||||
use App\Models\Site;
|
||||
use App\Pricing\AdvertisedOffer;
|
||||
use App\Pricing\OfferShowcase;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Picks the banner of a website: among the visible notices for this website (or all websites) that fit the
|
||||
* appearance in effect, the highest priority wins, then the newest. A notice advertising a special offer only
|
||||
* counts while the website advertises that offer; text, dates and link then come from the offer unless the
|
||||
* notice sets its own.
|
||||
*/
|
||||
class BannerResolver
|
||||
{
|
||||
public function __construct(private OfferShowcase $showcase) {}
|
||||
|
||||
public function for(Site $site, ?Appearance $appearance): ?Banner
|
||||
{
|
||||
foreach ($this->candidates($site, $appearance) as $notice) {
|
||||
$banner = $this->banner($notice);
|
||||
if ($banner !== null) {
|
||||
return $banner;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visible notices for the website and the appearance, in the order they compete.
|
||||
*
|
||||
* @return Collection<int, Notice>
|
||||
*/
|
||||
public function candidates(Site $site, ?Appearance $appearance): Collection
|
||||
{
|
||||
return Notice::query()->visible()
|
||||
->where(fn ($query) => $query->whereNull('site_id')->when($site->exists, fn ($query) => $query->orWhere('site_id', $site->id)))
|
||||
->with('specialOffer.property')
|
||||
->orderByDesc('priority')
|
||||
->latest()
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->filter(fn (Notice $notice): bool => $notice->fitsSeason($appearance))
|
||||
->values();
|
||||
}
|
||||
|
||||
private function banner(Notice $notice): ?Banner
|
||||
{
|
||||
if ($notice->special_offer_id === null) {
|
||||
return filled($notice->text)
|
||||
? new Banner($notice, (string) $notice->text, $notice->link_label, $notice->link_label ? ($notice->link_url ?: route('booking.create')) : null, $notice->tone)
|
||||
: null;
|
||||
}
|
||||
|
||||
$offer = $notice->specialOffer;
|
||||
$advertised = $offer?->property
|
||||
? $this->showcase->current($offer->property)->first(fn (AdvertisedOffer $advertised): bool => $advertised->offer->is($offer))
|
||||
: null;
|
||||
if ($advertised === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Banner(
|
||||
$notice,
|
||||
filled($notice->text) ? (string) $notice->text : self::offerText($advertised),
|
||||
$notice->link_label ?: 'Zum Angebot',
|
||||
$notice->link_url ?: $advertised->bookingUrl(),
|
||||
$notice->tone,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Kurzfristig frei: 12.11.–15.11. · 15 % günstiger".
|
||||
*/
|
||||
public static function offerText(AdvertisedOffer $advertised): string
|
||||
{
|
||||
$dates = $advertised->arrival && $advertised->departure
|
||||
? ': '.$advertised->arrival->format('d.m.').'–'.$advertised->departure->format('d.m.')
|
||||
: '';
|
||||
|
||||
return $advertised->title.$dates.' · '.$advertised->advantage;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user