44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Form\Service\Condition;
|
|
|
|
use App\Form\Model\BookingDto;
|
|
use App\Form\Service\Contract\FieldConditionInterface;
|
|
|
|
/**
|
|
* Condition that evaluates based on the booking workflow mode.
|
|
*
|
|
* Used to apply field states that should only be active in a specific mode
|
|
* (create or edit), such as making room assignments readonly in edit mode.
|
|
*/
|
|
class BookingModeCondition implements FieldConditionInterface
|
|
{
|
|
/**
|
|
* @param string $mode The mode to check against (BookingDto::MODE_CREATE or BookingDto::MODE_EDIT)
|
|
*/
|
|
public function __construct(
|
|
private readonly string $mode,
|
|
) {
|
|
if (BookingDto::MODE_CREATE !== $mode && BookingDto::MODE_EDIT !== $mode) {
|
|
throw new \InvalidArgumentException(sprintf('Invalid mode "%s". Must be one of: %s, %s', $mode, BookingDto::MODE_CREATE, BookingDto::MODE_EDIT));
|
|
}
|
|
}
|
|
|
|
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
|
{
|
|
return $this->mode === $bookingDto->getMode();
|
|
}
|
|
|
|
public function getDependentFields(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getDescription(): string
|
|
{
|
|
return sprintf('Returns true when booking is in %s mode', $this->mode);
|
|
}
|
|
}
|