wip: insurance booking in edit flow
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
/**
|
||||
* Parses insurance data from booking XML responses.
|
||||
*
|
||||
* This parser handles the simplified insurance structure found in booking data,
|
||||
* which includes participant mappings and individual pricing.
|
||||
*/
|
||||
class BookingInsurancesParser extends AbstractParser
|
||||
{
|
||||
public function parse(Crawler $result): array
|
||||
{
|
||||
$insurances = [];
|
||||
|
||||
$result->each(function (Crawler $node) use (&$insurances) {
|
||||
$insurance = new Insurance();
|
||||
$insurance->id = (int) $node->attr('idversicherung');
|
||||
$insurance->label = $node->attr('bezeichnung');
|
||||
$insurance->price = $this->stringToFloat($node->attr('gesamtpreis'));
|
||||
|
||||
// Parse participant mapping (zuordnung attribute)
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$insurance->mapping = array_map(function ($index) {
|
||||
return (int) $index - 1;
|
||||
}, $mapping);
|
||||
|
||||
// Parse individual prices per participant
|
||||
$individualPrices = array_map(
|
||||
function ($price) {
|
||||
return $this->stringToFloat($price);
|
||||
},
|
||||
$this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$insurance->individualPrice = array_combine($insurance->mapping, $individualPrices);
|
||||
|
||||
$insurances[$insurance->id] = $insurance;
|
||||
});
|
||||
|
||||
return $insurances;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ class BookingParser extends AbstractParser
|
||||
private readonly RoomsParser $roomsParser;
|
||||
private readonly PickupsParser $pickupsParser;
|
||||
private readonly SurchargesParser $surchargesParser;
|
||||
private readonly BookingInsurancesParser $insurancesParser;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -23,6 +24,7 @@ class BookingParser extends AbstractParser
|
||||
$this->roomsParser = new RoomsParser();
|
||||
$this->pickupsParser = new PickupsParser();
|
||||
$this->surchargesParser = new SurchargesParser();
|
||||
$this->insurancesParser = new BookingInsurancesParser();
|
||||
}
|
||||
|
||||
public function parse(Crawler $node): Booking
|
||||
@@ -101,6 +103,11 @@ class BookingParser extends AbstractParser
|
||||
$booking->surcharges = $this->surchargesParser->parse($surchargesData);
|
||||
}
|
||||
|
||||
$insurancesData = $node->filterXPath('//versicherungen/versicherung');
|
||||
if (0 < $insurancesData->count()) {
|
||||
$booking->insurances = $this->insurancesParser->parse($insurancesData);
|
||||
}
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user