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