wip: improved insurance selection

This commit is contained in:
Björn Fromme
2025-10-02 12:11:23 +02:00
parent 8a495346d6
commit d7929dd855
6 changed files with 91 additions and 17 deletions
+35 -4
View File
@@ -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);