servicesParser = new ServicesParser(); $this->roomsParser = new RoomsParser(); $this->pickupsParser = new PickupsParser(); $this->surchargesParser = new SurchargesParser(); } public function parse(Crawler $node): Booking { $booking = new Booking(); $booking->id = $this->getIntOrNullValue($node->filterXPath('//idbuchung')); $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->getFloatOrNullValue($node->filterXPath('//zahlungsdaten/gesamtbetrag')); $booking->status = $this->getStringOrNullValue($node->filterXPath('//status')); $travelData = $node->filterXPath('//reise'); $booking->travel = $travelData->attr('bezeichnung'); $booking->travelId = $this->getIntOrNullValue($node->filterXPath('//idreise')); $booking->travelCode = $travelData->attr('code'); $booking->travelDate = $this->stringToDate($travelData->attr('termin')); $booking->hotelId = $this->getIntOrNullValue($node->filterXPath('//idpartner')); $booking->hotelName = $this->getStringOrNullValue($node->filterXPath('//partner')); $booking->applicant = $this->parsePersonalData($node->filterXPath('//anmelder')); $participantsStatus = $this->getArrayValue($node->filterXPath('//status_teilnehmer'), '/'); $booking->participantsStatus = array_combine(range(1, count($participantsStatus)), $participantsStatus); $booking->participants = $this->parseParticipants($node->filterXPath('//teilnehmerliste/teilnehmer')); $paymentData = $node->filterXPath('//zahlung'); $booking->paymentId = (int) $paymentData->attr('idzahlungsart'); $booking->paymentLabel = $paymentData->attr('bezeichnung'); $booking->paymentType = $paymentData->attr('art'); $transportationData = $node->filterXPath('//beförderungen/beförderung'); if (0 < $transportationData->count()) { $booking->transportationServices = $this ->servicesParser ->parse($transportationData, Service::CATEGORY_TRANSPORTATION, Service::SOURCE_BOOKING); } $additionalServicesData = $node->filterXPath('//zusatzleistungen/zusatzleistung'); if (0 < $additionalServicesData->count()) { $booking->additionalServices = $this ->servicesParser ->parse($additionalServicesData, Service::CATEGORY_ADDITIONAL, Service::SOURCE_BOOKING); } $roomsData = $node->filterXPath('//ferienzielunterbringungen/ferienzielunterbringung'); if (0 < $roomsData->count()) { $booking->rooms = $this->roomsParser->parse($roomsData); } $pickupsData = $node->filterXPath('//zustiege/zustieg'); if (0 < $pickupsData->count()) { $booking->pickupsTo = $this->pickupsParser->parse($pickupsData); } $pickupsData = $node->filterXPath('//zustiege_rueck/zustieg_rueck'); if (0 < $pickupsData->count()) { $booking->pickupsFro = $this->pickupsParser->parse($pickupsData); } $surchargesData = $node->filterXPath('//zuschlaege/zuschlag'); if (0 < $surchargesData->count()) { $booking->surcharges = $this->surchargesParser->parse($surchargesData); } return $booking; } private function parseParticipants(Crawler $node): array { $participants = []; $node->each(function (Crawler $node) use (&$participants) { $id = (int) $node->attr('id'); $participants[$id] = $this->parsePersonalData($node); }); return $participants; } private function parsePersonalData(Crawler $node): PersonalData { $personalData = new PersonalData(); $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 ? \DateTimeImmutable::createFromFormat('d.m.Y', $dateString) : null; $personalData->firstName = $this->getStringOrNullValue($node->filterXPath('//vorname')); $personalData->name = $this->getStringOrNullValue($node->filterXPath('//name')); $personalData->salutation = $this->getStringOrNullValue($node->filterXPath('//anrede')); $personalData->title = $this->getStringOrNullValue($node->filterXPath('//titel')); $genderValue = $this->getStringOrNullValue($node->filterXPath('//geschlecht')); $personalData->gender = null !== $genderValue ? strtoupper($genderValue) : null; $personalData->nationality = $this->getStringOrNullValue($node->filterXPath('//nationalitaet')); $personalData->height = $this->getStringOrNullValue($node->filterXPath('//sonstiges1')); $personalData->weight = $this->getStringOrNullValue($node->filterXPath('//sonstiges2')); $personalData->shoeSize = $this->getStringOrNullValue($node->filterXPath('//sonstiges3')); $addressNode = $node->filterXPath('//anschrift'); if (0 < $addressNode->count()) { $address = new Address(); $address->street = $this->getStringOrNullValue($addressNode->filterXPath('//strasse')); $address->postCode = $this->getStringOrNullValue($addressNode->filterXPath('//plz')); $address->city = $this->getStringOrNullValue($addressNode->filterXPath('//ort')); $address->country = $this->getStringOrNullValue($addressNode->filterXPath('//land')); $personalData->address = $address; } $contactNode = $node->filterXPath('//kommunikation'); if (0 < $contactNode->count()) { $communication = new Communication(); $communication->phone = $this->getStringOrNullValue($contactNode->filterXPath('//telefonprivat')); $communication->mobile = $this->getStringOrNullValue($contactNode->filterXPath('//telefonmobil')); $communication->email = $this->getStringOrNullValue($contactNode->filterXPath('//email')); $communication->newsletter = $this->getBoolValue($contactNode->filterXPath('//newsletter')); $personalData->communication = $communication; } return $personalData; } }