wip: age based filtering of options

This commit is contained in:
Björn Fromme
2025-08-27 12:42:02 +02:00
parent 803b10f981
commit 25bbf3d44f
11 changed files with 751 additions and 27 deletions
+64
View File
@@ -22,6 +22,12 @@ use Symfony\Component\DomCrawler\Crawler;
*/
class TravelParser extends AbstractParser
{
private AgeConstraintParserRegistry $ageConstraintRegistry;
public function __construct()
{
$this->ageConstraintRegistry = new AgeConstraintParserRegistry();
}
/**
* Parse XML node into a Travel object.
*
@@ -129,6 +135,9 @@ class TravelParser extends AbstractParser
->stringToFloat($this->getStringOrNullValue($serviceNode->filterXPath('//preis')));
$service->status = $this->getStringOrNullValue($serviceNode->filterXPath('//status'));
// Parse age constraints
$this->parseServiceAgeConstraints($serviceNode, $service);
$additionalServices[$serviceId] = $service;
});
@@ -302,4 +311,59 @@ class TravelParser extends AbstractParser
return $rooms;
}
/**
* Parse age constraints from service XML node and apply them to the service.
*
* Handles both absolute age constraints (altervon/alterbis) and extensible
* constraint data (hinweis_stamm) that may contain birth year ranges or
* future constraint types.
*
* @param Crawler $serviceNode The XML node containing service data
* @param Service $service The service object to populate with constraints
*/
private function parseServiceAgeConstraints(Crawler $serviceNode, Service $service): void
{
// Parse absolute age constraints (altervon/alterbis)
$ageFrom = $this->getIntOrNullValue($serviceNode->filterXPath('.//altervon'));
$ageTo = $this->getIntOrNullValue($serviceNode->filterXPath('.//alterbis'));
// Parse extensible constraint data (hinweis_stamm)
$constraintData = $this->getStringOrNullValue($serviceNode->filterXPath('.//hinweis_stamm'));
$constraintResult = null;
if (null !== $constraintData && '' !== trim($constraintData)) {
$constraintResult = $this->ageConstraintRegistry->parseConstraints($constraintData);
}
// Apply absolute age constraints
if (null !== $ageFrom || null !== $ageTo) {
$service->ageFrom = $ageFrom;
$service->ageTo = $ageTo;
if (null !== $constraintResult && false === $constraintResult->isEmpty()) {
// Mixed constraints scenario
$service->ageConstraintType = 'mixed';
$service->birthYearFrom = $constraintResult->birthYearFrom;
$service->birthYearTo = $constraintResult->birthYearTo;
$service->ageConstraintMetadata = array_merge(
$constraintResult->metadata,
['has_absolute_age' => true, 'has_birth_year' => true]
);
} else {
$service->ageConstraintType = 'absolute_age';
}
} elseif (null !== $constraintResult && false === $constraintResult->isEmpty()) {
// Only constraint data (birth year, etc.)
$service->ageConstraintType = $constraintResult->type;
$service->birthYearFrom = $constraintResult->birthYearFrom;
$service->birthYearTo = $constraintResult->birthYearTo;
$service->ageConstraintMetadata = $constraintResult->metadata;
}
// Always store raw data for debugging/future parsing
if (null !== $constraintData) {
$service->rawAgeConstraintData = $constraintData;
}
}
}