feat: implement mutability cutoff for rentals

addresses #869cca42x
This commit is contained in:
Björn Fromme committed 2026-03-17 10:29:43 +01:00
1 parent 752e6752b4
commit cb56a4fe46
9 files changed
+253 -8

No files matched your search

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace App\Form\Service\Condition;
use App\Form\Model\BookingDto;
use App\Form\Service\Contract\FieldConditionInterface;
use Carbon\CarbonImmutable;
/**
* Condition that becomes true once a configurable day-based cutoff is reached.
*
* Cutoff semantics are inclusive and day-based:
* now(startOfDay) >= travelStart(startOfDay) - N days.
*/
class TravelStartCutoffReachedCondition implements FieldConditionInterface
{
public const int DEFAULT_DAYS_BEFORE_START = 4;
/**
* @param int $daysBeforeStart Number of days before travel start when the cutoff is reached
*/
public function __construct(
private readonly int $daysBeforeStart,
) {
if ($daysBeforeStart < 0) {
throw new \InvalidArgumentException('daysBeforeStart must be greater than or equal to 0.');
}
}
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
{
if (null === $bookingDto->travel->dateFrom) {
return false;
}
$travelStartDate = CarbonImmutable::instance($bookingDto->travel->dateFrom)->startOfDay();
$cutoffDate = $travelStartDate->subDays($this->daysBeforeStart);
$today = CarbonImmutable::now()->startOfDay();
return $today->greaterThanOrEqualTo($cutoffDate);
}
public function getDependentFields(): array
{
return [];
}
public function getDescription(): string
{
return sprintf(
'Cutoff reached from %d day(s) before travel start (inclusive)',
$this->daysBeforeStart
);
}
}