wip: skipass-duration based rentals filtering
This commit is contained in:
1 parent
ed7c889c4f
commit
1e48e107fc
8 files changed
+288
-17
No files matched your search
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates whether a skipass is selected for a participant.
|
||||
*
|
||||
* This condition checks if a participant has selected a skipass from the
|
||||
* available travel services. When a skipass is selected, rental equipment
|
||||
* fields should become visible and filtered by the skipass duration.
|
||||
*
|
||||
* The condition examines the participant's skiPass property to determine if
|
||||
* a skipass service has been selected, triggering rental field visibility
|
||||
* and duration-based filtering.
|
||||
*/
|
||||
class SkiPassSelectionCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates whether the participant has selected a skipass.
|
||||
*
|
||||
* Checks if the participant's skiPass property contains a Service object,
|
||||
* which would indicate a skipass has been selected and rental services
|
||||
* should be made available with duration filtering applied.
|
||||
*
|
||||
* @param BookingDtoInterface $bookingDto The current booking data (create or edit)
|
||||
* @param int $participantIndex The index of the participant being evaluated
|
||||
* @param array<string, mixed> $formData Current form data for condition evaluation
|
||||
*
|
||||
* @return bool True if a skipass is selected, false otherwise
|
||||
*/
|
||||
public function evaluate(BookingDtoInterface $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
// First check submitted form data for skipass selection
|
||||
if (isset($formData['participants'][$participantIndex]['skiPass'])) {
|
||||
$selectedSkiPass = $formData['participants'][$participantIndex]['skiPass'];
|
||||
if (null !== $selectedSkiPass && '' !== $selectedSkiPass) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then check participant DTO data for existing skipass selection
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
if (null !== $participant && null !== $participant->skiPass) {
|
||||
// Check if skipass is actually a Service object
|
||||
if ($participant->skiPass instanceof Service) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that trigger re-evaluation of this condition.
|
||||
*
|
||||
* This condition depends on the skiPass field, so any changes to skipass
|
||||
* selections should trigger re-evaluation of rental field states.
|
||||
*
|
||||
* @return string[] Array containing the field names that affect this condition
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return ['skiPass'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable description of this condition.
|
||||
*
|
||||
* Provides a clear description of the condition logic for debugging,
|
||||
* logging, and developer documentation purposes.
|
||||
*
|
||||
* @return string A brief description of the condition logic
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Rentals visible and filtered by duration when skipass is selected';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user