feat: simplify xml parsing, add 'mutable' property for personal data

This commit is contained in:
Björn Fromme
2025-01-30 10:40:38 +01:00
parent c75f069ce0
commit eae9879519
8 changed files with 47 additions and 32 deletions
+1
View File
@@ -8,6 +8,7 @@ class PersonalData
{ {
public ?int $addressId = null; public ?int $addressId = null;
public ?int $personId = null; public ?int $personId = null;
public bool $mutable = false;
#[Assert\NotBlank(message: 'Bitte angeben')] #[Assert\NotBlank(message: 'Bitte angeben')]
public ?string $name = null; public ?string $name = null;
@@ -18,4 +18,33 @@ abstract class AbstractParser
{ {
return 0 < $node->count() ? (int) $node->text() : null; return 0 < $node->count() ? (int) $node->text() : null;
} }
protected function getFloatOrNullValue(Crawler $node): ?float
{
return 0 < $node->count() ? $this->stringToFloat($node->text()) : null;
}
protected function getDateOrNullValue(Crawler $node): ?\DateTimeImmutable
{
return 0 < $node->count() ? $this->stringToDate($node->text()) : null;
}
protected function getDateTimeOrNullValue(Crawler $node): ?\DateTimeImmutable
{
return 0 < $node->count() ? $this->stringToDateTime($node->text()) : null;
}
protected function getBoolValue(Crawler $node): bool
{
return 0 < $node->count() && $this->stringToBool($node->text());
}
protected function getArrayValue(Crawler $node, string $separator = ','): array
{
if (0 === $node->count()) {
return [];
}
return $this->stringToArray($node->text(), $separator);
}
} }
+4 -6
View File
@@ -32,8 +32,7 @@ class BookingParser extends AbstractParser
$booking->agencyId = $this->getIntOrNullValue($node->filterXPath('//idagentur')); $booking->agencyId = $this->getIntOrNullValue($node->filterXPath('//idagentur'));
$booking->bookingNumber = $this->getIntOrNullValue($node->filterXPath('//vorgang')); $booking->bookingNumber = $this->getIntOrNullValue($node->filterXPath('//vorgang'));
$booking->invoiceNumber = $this->getIntOrNullValue($node->filterXPath('//zahlungsdaten/rechnung')); $booking->invoiceNumber = $this->getIntOrNullValue($node->filterXPath('//zahlungsdaten/rechnung'));
$booking->totalPrice = $this $booking->totalPrice = $this->getFloatOrNullValue($node->filterXPath('//zahlungsdaten/gesamtbetrag'));
->stringToFloat($this->getStringOrNullValue($node->filterXPath('//zahlungsdaten/gesamtbetrag')));
$booking->status = $this->getStringOrNullValue($node->filterXPath('//status')); $booking->status = $this->getStringOrNullValue($node->filterXPath('//status'));
$travelData = $node->filterXPath('//reise'); $travelData = $node->filterXPath('//reise');
@@ -48,8 +47,7 @@ class BookingParser extends AbstractParser
$booking->applicant = $this->parsePersonalData($node->filterXPath('//anmelder')); $booking->applicant = $this->parsePersonalData($node->filterXPath('//anmelder'));
$participantsStatus = $this $participantsStatus = $this->getArrayValue($node->filterXPath('//status_teilnehmer'), '/');
->stringToArray($this->getStringOrNullValue($node->filterXPath('//status_teilnehmer')), '/');
$booking->participantsStatus = array_combine(range(1, count($participantsStatus)), $participantsStatus); $booking->participantsStatus = array_combine(range(1, count($participantsStatus)), $participantsStatus);
$booking->participants = $this->parseParticipants($node->filterXPath('//teilnehmerliste/teilnehmer')); $booking->participants = $this->parseParticipants($node->filterXPath('//teilnehmerliste/teilnehmer'));
@@ -109,6 +107,7 @@ class BookingParser extends AbstractParser
$personalData->addressId = $this->getIntOrNullValue($node->filterXPath('//idadresse')); $personalData->addressId = $this->getIntOrNullValue($node->filterXPath('//idadresse'));
$personalData->personId = $this->getIntOrNullValue($node->filterXPath('//idadresseperson')); $personalData->personId = $this->getIntOrNullValue($node->filterXPath('//idadresseperson'));
$personalData->mutable = $this->getBoolValue($node->filterXPath('//aenderungmoeglich'));
$dateString = $this->getStringOrNullValue($node->filterXPath('//geburtsdatum')); $dateString = $this->getStringOrNullValue($node->filterXPath('//geburtsdatum'));
$personalData->dateOfBirth = null !== $dateString $personalData->dateOfBirth = null !== $dateString
@@ -145,8 +144,7 @@ class BookingParser extends AbstractParser
$communication->phone = $this->getStringOrNullValue($contactNode->filterXPath('//telefonprivat')); $communication->phone = $this->getStringOrNullValue($contactNode->filterXPath('//telefonprivat'));
$communication->mobile = $this->getStringOrNullValue($contactNode->filterXPath('//telefonmobil')); $communication->mobile = $this->getStringOrNullValue($contactNode->filterXPath('//telefonmobil'));
$communication->email = $this->getStringOrNullValue($contactNode->filterXPath('//email')); $communication->email = $this->getStringOrNullValue($contactNode->filterXPath('//email'));
$communication->newsletter = $this $communication->newsletter = $this->getBoolValue($contactNode->filterXPath('//newsletter'));
->stringToBool($contactNode->filterXPath('//newsletter')->text('False'));
$personalData->communication = $communication; $personalData->communication = $communication;
} }
@@ -11,7 +11,7 @@ class BookingUpdateParser extends AbstractParser
{ {
$bookingUpdate = new BookingUpdate(); $bookingUpdate = new BookingUpdate();
$bookingUpdate->valid = 'möglich' === $node->filterXPath('//aenderung')->text(); $bookingUpdate->valid = 'möglich' === $node->filterXPath('//aenderung')->text();
$bookingUpdate->totalPrice = $this->stringToFloat($node->filterXPath('//gesamtpreis')->text()); $bookingUpdate->totalPrice = $this->getFloatOrNullValue($node->filterXPath('//gesamtpreis'));
return $bookingUpdate; return $bookingUpdate;
} }
+6 -11
View File
@@ -24,19 +24,14 @@ class BookingsParser extends AbstractParser
$booking->bookingNumber = $this->getIntOrNullValue($node->filterXPath('//vorgangsnummer')); $booking->bookingNumber = $this->getIntOrNullValue($node->filterXPath('//vorgangsnummer'));
$booking->status = $this->getStringOrNullValue($node->filterXPath('//status')); $booking->status = $this->getStringOrNullValue($node->filterXPath('//status'));
$booking->participantCount = $this->getIntOrNullValue($node->filterXPath('//personen')); $booking->participantCount = $this->getIntOrNullValue($node->filterXPath('//personen'));
$booking->price = $this->stringToFloat($this->getStringOrNullValue($node->filterXPath('//preis'))); $booking->price = $this->getFloatOrNullValue($node->filterXPath('//preis'));
$booking->bookingDate = $this $booking->bookingDate = $this->getDateTimeOrNullValue($node->filterXPath('//buchungsdatum'));
->stringToDateTime($this->getStringOrNullValue($node->filterXPath('//buchungsdatum')));
$booking->travel = $this->getStringOrNullValue($node->filterXPath('//reise')); $booking->travel = $this->getStringOrNullValue($node->filterXPath('//reise'));
$booking->travelId = $this->getIntOrNullValue($node->filterXPath('//idreise')); $booking->travelId = $this->getIntOrNullValue($node->filterXPath('//idreise'));
$booking->travelDate = $this $booking->travelDate = $this->getDateOrNullValue($node->filterXPath('//reisedatum'));
->stringToDate($this->getStringOrNullValue($node->filterXPath('//reisedatum'))); $booking->hasDocuments = $this->getBoolValue($node->filterXPath('//reisedokument'));
$booking->hasDocuments = $this $booking->payment = $this->getFloatOrNullValue($node->filterXPath('//zahlung'));
->stringToBool($this->getStringOrNullValue($node->filterXPath('//reisedokument'))); $booking->hasDocuments = $this->getBoolValue($node->filterXPath('//reisedokument'));
$booking->payment = $this
->stringToFloat($this->getStringOrNullValue($node->filterXPath('//zahlung')));
$booking->hasDocuments = $this
->stringToBool($this->getStringOrNullValue($node->filterXPath('//reisedokument')));
$bookings[] = $booking; $bookings[] = $booking;
}); });
@@ -19,10 +19,7 @@ class PersonalDataParser extends AbstractParser
$addressDataNode = $node->filterXPath('//adressdaten'); $addressDataNode = $node->filterXPath('//adressdaten');
$dateString = $this->getStringOrNullValue($addressDataNode->filterXPath('//geburtsdatum')); $personalData->dateOfBirth = $this->getDateOrNullValue($addressDataNode->filterXPath('//geburtsdatum'));
$personalData->dateOfBirth = null !== $dateString ?
\DateTimeImmutable::createFromFormat('d.m.Y', $dateString) : null;
$personalData->firstName = $this->getStringOrNullValue($addressDataNode->filterXPath('//vorname')); $personalData->firstName = $this->getStringOrNullValue($addressDataNode->filterXPath('//vorname'));
$personalData->name = $this->getStringOrNullValue($addressDataNode->filterXPath('//name')); $personalData->name = $this->getStringOrNullValue($addressDataNode->filterXPath('//name'));
$personalData->salutation = $this->getStringOrNullValue($addressDataNode->filterXPath('//anrede')); $personalData->salutation = $this->getStringOrNullValue($addressDataNode->filterXPath('//anrede'));
@@ -52,8 +49,7 @@ class PersonalDataParser extends AbstractParser
$communication->phone = $this->getStringOrNullValue($contactDataNode->filterXPath('//telefonprivat')); $communication->phone = $this->getStringOrNullValue($contactDataNode->filterXPath('//telefonprivat'));
$communication->mobile = $this->getStringOrNullValue($contactDataNode->filterXPath('//telefonmobil')); $communication->mobile = $this->getStringOrNullValue($contactDataNode->filterXPath('//telefonmobil'));
$communication->email = $this->getStringOrNullValue($contactDataNode->filterXPath('//email')); $communication->email = $this->getStringOrNullValue($contactDataNode->filterXPath('//email'));
$communication->newsletter = $this $communication->newsletter = $this->getBoolValue($contactDataNode->filterXPath('//newsletter'));
->stringToBool($this->getStringOrNullValue($contactDataNode->filterXPath('//newsletter')));
$personalData->communication = $communication; $personalData->communication = $communication;
} }
+2 -4
View File
@@ -17,10 +17,8 @@ class RoomsParser extends AbstractParser
$room->label = $node->attr('zimmer'); $room->label = $node->attr('zimmer');
$room->category = $node->attr('kategorie'); $room->category = $node->attr('kategorie');
$room->boardId = (int) $node->attr('idverpflegung'); $room->boardId = (int) $node->attr('idverpflegung');
$room->dateFrom = $node->attr('anreise') ? $room->dateFrom = $this->stringToDate($node->attr('anreise'));
$this->stringToDate($node->attr('anreise')) : null; $room->dateTo = $this->stringToDate($node->attr('abreise'));
$room->dateTo = $node->attr('abreise') ?
$this->stringToDate($node->attr('abreise')) : null;
$room->totalCount = (int) $node->attr('anzahl'); $room->totalCount = (int) $node->attr('anzahl');
$room->minPax = (int) $node->attr('minpax'); $room->minPax = (int) $node->attr('minpax');
$room->maxPax = (int) $node->attr('maxpax'); $room->maxPax = (int) $node->attr('maxpax');
+2 -4
View File
@@ -17,10 +17,8 @@ class ServicesParser extends AbstractParser
$service->category = $category; $service->category = $category;
$service->source = $source; $service->source = $source;
$service->label = $node->attr('leistung'); $service->label = $node->attr('leistung');
$service->dateFrom = $node->attr('termin') ? $service->dateFrom = $this->stringToDate($node->attr('termin'));
$this->stringToDate($node->attr('termin')) : null; $service->dateTo = $this->stringToDate($node->attr('terminbis'));
$service->dateTo = $node->attr('terminbis') ?
$this->stringToDate($node->attr('terminbis')) : null;
$service->subType = $node->attr('unterart'); $service->subType = $node->attr('unterart');
$service->totalCount = $node->attr('anzahl') ? (int) $node->attr('anzahl') : null; $service->totalCount = $node->attr('anzahl') ? (int) $node->attr('anzahl') : null;
$mapping = $this->stringToArray($node->attr('zuordnung')); $mapping = $this->stringToArray($node->attr('zuordnung'));