From 4aeef31fe559f1e0beeb359fa235aa2baa31d42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Mon, 11 Oct 2021 09:58:42 +0200 Subject: [PATCH] Adjust date import to changed xml structure --- .../Classes/Service/DateImportService.php | 111 ++++++++---------- 1 file changed, 47 insertions(+), 64 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php index 8767d272..fa23c414 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php @@ -262,8 +262,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface $this->logger->warning('product not found or daytrip', ['code' => $code]); return 0; } - foreach ($products as $product) - { + foreach ($products as $product) { $this->db->update( 'tx_epproducts_domain_model_product', ['bus_pro_id' => $busProId], @@ -289,8 +288,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface protected function parseDates(\SimpleXMLElement $xmlDate, array $product) { $dateCount = 0; - foreach ($xmlDate->hotel as $xmlHotel) - { + foreach ($xmlDate->hotel as $xmlHotel) { $hotelCode = (string) $xmlHotel->attributes()['code']; $date = $this->createDateRecord($product, $xmlDate); $key = $hotelCode . $date['date_start']; @@ -378,18 +376,34 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface 'important' => $product['important'], ]; - $servicesBoard = $this->parseSelectionGroup($xmlDate, 'Leistungen Verpflegung'); - $skiPass = $this->parseSelectionGroup($xmlDate, 'Leistungen Skipass'); - $servicesIncluded = $this->parseSelectionGroup($xmlDate, 'Leistungen Sonstige'); + $includedAccommodation = $this->parseSelectionGroup($xmlDate, 'Leistungen Übernachtung'); + $includedSkiPass = $this->parseSelectionGroup($xmlDate, 'Leistungen Skipass'); + $includedBoard = $this->parseSelectionGroup($xmlDate, 'Leistungen Verpflegung'); + $includedTransportation = $this->parseSelectionGroup($xmlDate, 'Leistungen Transport'); + $includedProgramme = $this->parseSelectionGroup($xmlDate, 'Leistungen Programm'); + $includedPersonnel = $this->parseSelectionGroup($xmlDate, 'Leistungen Personal'); + $includedEvents = $this->parseSelectionGroup($xmlDate, 'Leistungen Events'); + $includedOther = $this->parseSelectionGroup($xmlDate, 'Leistungen Sonstige'); - $date['services_included'] = serialize($this->combineServices($skiPass, $servicesBoard, $servicesIncluded)); + $includedServices = [ + ...$includedAccommodation, + ...$includedSkiPass, + ...$includedTransportation, + ...$includedBoard, + ...$includedProgramme, + ...$includedEvents, + ...$includedPersonnel, + ...$includedOther, + ]; - if ($servicesBoard) { - $date['board'] = reset($servicesBoard); - $date['board_bus_pro_id'] = key($servicesBoard); + $date['services_included'] = serialize($includedServices); + + if ($includedBoard) { + $date['board'] = reset($includedBoard); + $date['board_bus_pro_id'] = key($includedBoard); } - $skiPassIncluded = (int) (count($skiPass) > 0); + $skiPassIncluded = (int) (count($includedSkiPass) > 0); $date['skipass_included'] = $skiPassIncluded; $servicesTransportation = $this->parseService($xmlDate, 'lei_befoerderung'); @@ -440,9 +454,11 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface $date['services_general'] = serialize($combinedServices); $pickups = []; - foreach ($xmlDate->xpath('zustiege/zustieg') as $pickup) - { + foreach ($xmlDate->xpath('zustiege/zustieg') as $pickup) { $attributes = $pickup->attributes(); + if (null === $attributes) { + continue; + } $busProId = (int) $attributes['idbuspro']; if ($busProId === 0) { continue; @@ -459,34 +475,6 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface return $date; } - /** - * @param array $skiPass - * @param array $servicesBoard - * @param array $servicesIncluded - * @return array - */ - protected function combineServices(array $skiPass, array $servicesBoard, array $servicesIncluded) - { - $combinedServices = []; - if ($servicesIncluded) { - foreach ($servicesIncluded as $service) { - $combinedServices[] = $service; - } - } - if ($skiPass) { - foreach ($skiPass as $service) { - $combinedServices[] = $service; - } - } - if ($servicesBoard) { - foreach ($servicesBoard as $service) { - $combinedServices[] = $service; - } - } - - return $combinedServices; - } - /** * @param \SimpleXMLElement $xmlHotel * @param array $date @@ -510,8 +498,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface $hotelServices = $this->parseService($xmlHotel, 'lei_sonstiges', true); $this->addServices($generalServices, $services); $this->addServices($hotelServices, $services); - foreach ($services as $key => $list) - { + foreach ($services as $key => $list) { uasort($list, function ($a, $b) { return strcmp($a['label'], $b['label']); }); @@ -550,8 +537,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface $boardCode = ''; $count = 0; - foreach ($xmlHotel->xpath('zimmer/preis') as $roomXml) - { + foreach ($xmlHotel->xpath('zimmer/preis') as $roomXml) { $code = (string) $roomXml->attributes()['zimmercode']; if ($code === static::CODE_PSEUDOPRICE) { @@ -639,10 +625,8 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface */ protected function determineDiscount(array $services) { - foreach ($services as $key => $section) - { - foreach ($section as $service) - { + foreach ($services as $key => $section) { + foreach ($section as $service) { if ($service['price'] < 0) { return (int) $service['price']; } @@ -662,8 +646,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface { $data = []; $services = $xmlData->xpath($serviceLabel . '/leistung'); - foreach ($services as $service) - { + foreach ($services as $service) { // Skip transportation service direction 'back' if ($service->richtung && (string) $service->richtung === 'RUECK') { continue; @@ -724,9 +707,11 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface { $data = []; $selectionGroup = $xmlDate->xpath('selektiongruppe[@bezeichnung="' . $label . '"]/selektion'); - foreach ($selectionGroup as $selection) - { + foreach ($selectionGroup as $selection) { $attributes = $selection->attributes(); + if (null === $attributes) { + continue; + } $id = (int) $attributes['idbuspro']; $data[$id] = (string) $attributes['bezeichnung']; } @@ -746,8 +731,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface return; } - foreach ($services['BUS'] as $service) - { + foreach ($services['BUS'] as $service) { $date['bus_available'] = 1; $date['bus_price'] = (int) $service['price']; $date['bus_included'] = (int) ((int) $service['price'] === 0); @@ -758,8 +742,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface { $sql = 'SELECT code, type FROM tx_epproducts_domain_model_roommapping'; $roomMappings = $this->db->fetchAllAssociative($sql); - foreach ($roomMappings as $mapping) - { + foreach ($roomMappings as $mapping) { $this->roomMappings[mb_strtolower($mapping['code'])] = $mapping['type']; } } @@ -783,8 +766,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface LEFT JOIN tx_epproducts_domain_model_hotel h ON u.uid = h.uid '; $rows = $this->db->fetchAllAssociative($sql); - foreach ($rows as $row) - { + foreach ($rows as $row) { $this->hotelMappings[$row['code']] = [ 'uid' => $row['uid'], 'code' => $row['code'], @@ -827,8 +809,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface */ protected function addServices(array $services, array &$list) { - foreach ($services as $key => $section) - { + foreach ($services as $key => $section) { if (!array_key_exists($key, $list)) { $list[$key] = []; } @@ -845,9 +826,11 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface return; } - foreach ($xmlData->zustieg as $entry) - { + foreach ($xmlData->zustieg as $entry) { $attributes = $entry->attributes(); + if (null === $attributes) { + continue; + } $idBusPro = (int) $attributes['idbuspro']; $this->pickups[$idBusPro] = [ 'city' => (string) $entry->ort,