wip: improved insurance selection
This commit is contained in:
@@ -34,15 +34,16 @@ class InsuranceParser extends AbstractParser
|
||||
$xmlContent->filterXPath('//versicherungen/versicherung')
|
||||
->each(function (Crawler $node) use (&$individualInsurances, &$insurances, $referencedIds) {
|
||||
$id = (int) $node->attr('idbuspro'); // Individual insurances have int IDs
|
||||
$isAdditional = $this->getBoolAttributeValue($node->attr('zusatzversicherung'));
|
||||
$isComplementary = $this->getBoolAttributeValue($node->attr('zusatzversicherung'));
|
||||
|
||||
// Parse all individual insurances for reference lookup
|
||||
$insurance = $this->parseInsuranceNode($node, false);
|
||||
if (null !== $insurance && null !== $insurance->id) {
|
||||
$individualInsurances[$insurance->id] = $insurance;
|
||||
|
||||
// Include if: not additional insurance OR referenced by package
|
||||
if (!$isAdditional || in_array($id, $referencedIds, true)) {
|
||||
// Include only if it's NOT a complementary insurance (zusatzversicherung)
|
||||
// Complementary insurances are only available as part of packages, never standalone
|
||||
if (!$isComplementary) {
|
||||
$insurances[$insurance->id] = $insurance;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +102,7 @@ class InsuranceParser extends AbstractParser
|
||||
$idValue = $node->attr('idbuspro');
|
||||
$insurance->id = $isPackage ? $idValue : (int) $idValue;
|
||||
$insurance->code = $node->attr('code');
|
||||
$insurance->label = $node->attr('bezeichnung');
|
||||
$insurance->label = $this->normalizeInsuranceLabel($node->attr('bezeichnung'));
|
||||
$insurance->subType = $node->attr('unterart');
|
||||
$insurance->price = $node->attr('preis') ?
|
||||
$this->stringToFloat($node->attr('preis')) : null;
|
||||
@@ -183,6 +184,36 @@ class InsuranceParser extends AbstractParser
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes insurance labels by removing redundant phrases and replacing abbreviations.
|
||||
*
|
||||
* Transformations:
|
||||
* - Removes "Auto/Bahn/Bus (Europa)" - redundant travel mode specification
|
||||
* - Replaces "FAM" with "Familie" - clearer German terminology
|
||||
*
|
||||
* @param string|null $label The original insurance label from XML
|
||||
*
|
||||
* @return string|null The normalized label, or null if input was null
|
||||
*/
|
||||
private function normalizeInsuranceLabel(?string $label): ?string
|
||||
{
|
||||
if (null === $label) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Remove redundant travel mode specification
|
||||
$label = str_replace('Auto/Bahn/Bus (Europa)', '', $label);
|
||||
|
||||
// Replace abbreviation with full German word
|
||||
$label = str_replace('FAM', 'Familie', $label);
|
||||
|
||||
// Clean up extra spaces that may result from removals
|
||||
$label = preg_replace('/\s+/', ' ', $label);
|
||||
$label = trim($label);
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
private function getBoolAttributeValue(?string $value): bool
|
||||
{
|
||||
return !empty($value) && $this->stringToBool($value);
|
||||
|
||||
Reference in New Issue
Block a user