- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
colours, external resources, WCAG contrast), themes:preview (signed links per page and
appearance), signed ?theme= preview and preview action in the site form, inherited colour
tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Availability;
|
|
|
|
use App\Models\Property;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
/**
|
|
* Free gaps in the calendar: runs of free nights with an occupied night (booking or block) directly
|
|
* before and after. Open-ended free periods (nothing booked behind them yet) are not gaps.
|
|
*/
|
|
class GapFinder
|
|
{
|
|
/** How far around a stay we look for the neighbouring occupations. */
|
|
private const LOOKAROUND_NIGHTS = 60;
|
|
|
|
public function __construct(private AvailabilityChecker $availability = new AvailabilityChecker) {}
|
|
|
|
/**
|
|
* Length in nights of the gap that contains the whole stay, or null if the stay is not inside a gap
|
|
* (because a night is occupied or the free period is not closed on both sides).
|
|
*/
|
|
public function gapContaining(Property $property, CarbonImmutable $arrival, CarbonImmutable $departure): ?int
|
|
{
|
|
$from = $arrival->subDays(self::LOOKAROUND_NIGHTS);
|
|
$until = $departure->addDays(self::LOOKAROUND_NIGHTS);
|
|
$occupied = $this->availability->occupiedNights($property, $from, $until);
|
|
|
|
for ($night = $arrival; $night->lessThan($departure); $night = $night->addDay()) {
|
|
if (isset($occupied[$night->toDateString()])) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
$start = $arrival;
|
|
while (! isset($occupied[$start->subDay()->toDateString()])) {
|
|
$start = $start->subDay();
|
|
if ($start->lessThanOrEqualTo($from)) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
$end = $departure;
|
|
while (! isset($occupied[$end->toDateString()])) {
|
|
$end = $end->addDay();
|
|
if ($end->greaterThanOrEqualTo($until)) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return (int) $start->diffInDays($end);
|
|
}
|
|
|
|
/**
|
|
* Gaps of 1 … $maxNights nights starting within [$from, $until), as [arrival, departure] pairs.
|
|
*
|
|
* @return list<array{0: CarbonImmutable, 1: CarbonImmutable}>
|
|
*/
|
|
public function gaps(Property $property, CarbonImmutable $from, CarbonImmutable $until, int $maxNights): array
|
|
{
|
|
$occupied = $this->availability->occupiedNights($property, $from->subDay(), $until->addDays($maxNights + 1));
|
|
|
|
$gaps = [];
|
|
$night = $from;
|
|
while ($night->lessThan($until)) {
|
|
$isGapStart = ! isset($occupied[$night->toDateString()]) && isset($occupied[$night->subDay()->toDateString()]);
|
|
if (! $isGapStart) {
|
|
$night = $night->addDay();
|
|
|
|
continue;
|
|
}
|
|
|
|
$end = $night;
|
|
while (! isset($occupied[$end->toDateString()]) && $night->diffInDays($end) <= $maxNights) {
|
|
$end = $end->addDay();
|
|
}
|
|
|
|
if (isset($occupied[$end->toDateString()]) && $night->diffInDays($end) <= $maxNights) {
|
|
$gaps[] = [$night, $end];
|
|
}
|
|
|
|
$night = $end->addDay();
|
|
}
|
|
|
|
return $gaps;
|
|
}
|
|
}
|