From 308833679282e6637a6dfecbea2c40bfe2cc06e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Thu, 19 Dec 2019 17:48:24 +0100 Subject: [PATCH] Include pax data --- .ddev/config.yaml | 2 +- .../Classes/Domain/Model/Contingent.php | 8 + .../Repository/ContingentRepository.php | 1 + .../Classes/Service/ContingentDataService.php | 1 + .../Service/ContingentImportService.php | 9 +- .../Classes/Service/IcalService.php | 141 +++++++++++------- .../TCA/tx_epproducts_domain_model_hotel.php | 11 +- .../typo3conf/ext/ep_products/ext_tables.sql | 1 - 8 files changed, 105 insertions(+), 69 deletions(-) diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 97e5975a..c57385ea 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -6,7 +6,7 @@ php_version: "7.3" webserver_type: apache-cgi router_http_port: "80" router_https_port: "443" -xdebug_enabled: false +xdebug_enabled: true additional_hostnames: - ep-events - ski-boarderweek diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Contingent.php b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Contingent.php index cccb8668..a6a681a5 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Contingent.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Contingent.php @@ -342,4 +342,12 @@ class Contingent extends AbstractEntity implements EventInterface { return $this->getBegin() >= $period->getBegin() && $this->getEnd() < $period->getEnd(); } + + /** + * @return int + */ + public function getOccupancy() + { + return $this->getPax() - $this->getAvailable(); + } } diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php index df6eccab..95322d4d 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php @@ -125,6 +125,7 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa $qb ->select('c.date as date', 'c.min_nights as minNights') ->addSelectLiteral('SUM(c.available) as total') + ->addSelectLiteral('SUM(c.pax) as capacity') ->from('tx_epproducts_domain_model_contingent', 'c') ->innerJoin('c', 'tx_epproducts_domain_model_date', 'd', 'c.date = d.date_start AND c.hotel_code = d.hotel_code') ->where('c.hotel = :hotelUid') diff --git a/public/typo3conf/ext/ep_products/Classes/Service/ContingentDataService.php b/public/typo3conf/ext/ep_products/Classes/Service/ContingentDataService.php index b4bb26cb..ecb713a0 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/ContingentDataService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/ContingentDataService.php @@ -65,6 +65,7 @@ class ContingentDataService 'date' => $row['date'], 'minNights' => $row['minNights'], 'total' => $row['total'], + 'capacity' => $row['capacity'], ]; } diff --git a/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php b/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php index 6e22a50d..679d8697 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/ContingentImportService.php @@ -167,7 +167,7 @@ class ContingentImportService implements SingletonInterface protected function parseContingent(\SimpleXMLElement $xmlContingent) { $hotelCode = (string) $xmlContingent['code']; - $sql = 'SELECT h.uid uid, h.groupsch_id groupsch_id + $sql = 'SELECT h.uid uid FROM tx_epproducts_domain_model_hotel h LEFT JOIN tx_epproducts_domain_model_matchcode m ON (h.uid = m.entity AND m.entity_type = "hotel") WHERE h.deleted = 0 AND h.hidden = 0 AND h.code = :code OR m.code = :code @@ -241,12 +241,12 @@ class ContingentImportService implements SingletonInterface $status = Contingent::STATUS_BLOCKED; } } else { - $pax = $roomType['pax'] * (int) $xmlRoom['kontingent']; + $capacity = (int) $xmlRoom['kontingent'] * $roomType['pax']; $availableRooms = (int) $xmlRoom['frei'] > 0 ? (int) $xmlRoom['frei'] : 0; $availablePax = $availableRooms * $roomType['pax']; } if ($availablePax === 0 && $roomType['ctrl'] === false) { - continue; + //continue; } $minPrice = (int) $xmlRoom['abpreis']; $minNights = (int) $xmlRoom['abpreis_naechte']; @@ -262,8 +262,7 @@ class ContingentImportService implements SingletonInterface 'hotel_bus_pro_id' => $hotelData['busProId'], 'room_code' => $roomCode, 'room_label' => $roomLabel, - 'groupsch_id' => $hotelData['groupsch_id'], - 'pax' => $pax, + 'pax' => $capacity, 'available' => $availablePax, 'status' => $status, 'date' => $date->format('Y-m-d'), diff --git a/public/typo3conf/ext/ep_products/Classes/Service/IcalService.php b/public/typo3conf/ext/ep_products/Classes/Service/IcalService.php index e8f2ac48..144fb232 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/IcalService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/IcalService.php @@ -5,7 +5,7 @@ namespace EP\EpProducts\Service; * * Copyright notice * - * (c) 2019 Björn Fromme , dreipunktnull + * (c) 2020 Björn Fromme , dreipunktnull * * All rights reserved * @@ -36,13 +36,16 @@ use TYPO3\CMS\Core\SingletonInterface; class IcalService implements SingletonInterface { - const THRESHOLD = 75; - /** * @var ContingentRepository */ protected $contingentRepository; + /** + * @var Vcalendar + */ + protected $vcalendar; + /** * @param ContingentRepository $contingentRepository */ @@ -69,43 +72,13 @@ class IcalService implements SingletonInterface $events = []; } - $vcalendar = $this->createCalendarInstance(); + $this->createCalendarInstance(); - $paxOccupiedCurrent = $dateStart = $dateEnd = null; - - foreach ($events as $event) { - /** @var Contingent $event */ - $paxTotal = $event->getPax(); - $paxAvailable = $event->getAvailable(); - - if (Contingent::STATUS_BLOCKED === $event->getStatus()) { - $paxOccupied = $paxTotal; - } else { - $paxOccupied = $paxTotal - $paxAvailable; - } - - if ($paxOccupied !== $paxOccupiedCurrent) { - if (null === $dateStart) { - $dateStart = $event->getBegin(); - } else { - $dateEnd = $event->getEnd(); - if ($paxOccupiedCurrent > 0) { - $this->addCalendarItem( - $vcalendar, - $dateStart, - $dateEnd, - $paxOccupiedCurrent - ); - } - $dateStart = $dateEnd = null; - } - } - - $paxOccupiedCurrent = $paxOccupied; - } + $this->generateOccupancyItems($events); + $this->generateBlockedItems($events); try { - $feed = $vcalendar->vtimezonePopulate()->createCalendar(); + $feed = $this->vcalendar->vtimezonePopulate()->createCalendar(); } catch (\Exception $e) { $feed = ''; @@ -115,19 +88,69 @@ class IcalService implements SingletonInterface } /** - * @param Vcalendar $vcalendar - * @param \DateTime $dateStart - * @param \DateTime $dateEnd - * @param int $pax + * @param array $events */ - protected function addCalendarItem(Vcalendar $vcalendar, \DateTime $dateStart, \DateTime $dateEnd, int $pax): void + protected function generateOccupancyItems(array $events): void + { + $occupancy = null; + + foreach ($events as $event) { + /** @var Contingent $event */ + if (null === $occupancy) { + $item = [ + 'from' => $event->getBegin(), + 'occupancy' => $event->getOccupancy(), + ]; + } elseif ($occupancy !== $event->getOccupancy()) { + $item['to'] = $event->getEnd(); + $this->addOccupancyItem($item); + $item = [ + 'from' => $event->getBegin(), + 'occupancy' => $event->getOccupancy(), + ]; + } + + $occupancy = $event->getOccupancy(); + } + + if (!isset($item['to'])) { + $item['to'] = $event->getEnd(); + $this->addOccupancyItem($item); + } + } + + /** + * @param array $events + */ + protected function generateBlockedItems(array $events): void + { + $item = null; + + foreach ($events as $event) { + /** @var Contingent $event */ + if (null === $item && Contingent::STATUS_BLOCKED === $event->getStatus()) { + $item = [ + 'from' => $event->getBegin(), + ]; + } elseif (true === is_array($item) && Contingent::STATUS_OK === $event->getStatus()) { + $item['to'] = $event->getEnd(); + $this->addBlockedItem($item); + $item = null; + } + } + } + + /** + * @param array $item + */ + protected function addBlockedItem(array $item): void { try { - $vcalendar + $this->vcalendar ->newVevent() - ->setDtstart($dateStart) - ->setDtend($dateEnd) - ->setDescription(sprintf('Part-occupied:%d', $pax)) + ->setDtstart($item['from']) + ->setDtend($item['to']) + ->setSummary('Unavailable') ; } catch (\Exception $e) { @@ -135,16 +158,30 @@ class IcalService implements SingletonInterface } /** - * @return Vcalendar + * @param array $item */ - protected function createCalendarInstance(): Vcalendar + protected function addOccupancyItem( array $item): void { - $vcalendar = Vcalendar::factory([ Vcalendar::UNIQUE_ID => 'www.ep-reisen.de' ]); - $vcalendar->setXprop( + $summary = sprintf('Part-occupied:%d', $item['occupancy']); + + try { + $this->vcalendar + ->newVevent() + ->setDtstart($item['from']) + ->setDtend($item['to']) + ->setSummary($summary) + ; + } + catch (\Exception $e) { + } + } + + protected function createCalendarInstance(): void + { + $this->vcalendar = Vcalendar::factory([ Vcalendar::UNIQUE_ID => 'www.ep-reisen.de' ]); + $this->vcalendar->setXprop( Vcalendar::X_WR_TIMEZONE, 'Europe/Berlin' ); - - return $vcalendar; } } diff --git a/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_hotel.php b/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_hotel.php index 48bd6326..2cfa8d6c 100644 --- a/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_hotel.php +++ b/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_hotel.php @@ -42,7 +42,7 @@ return [ ], 'palettes' => [ 'top' => ['showitem' => 'hidden,earlybird,new,low_contingent,show_as_teaser, - --linebreak--,code,groupsch_id,detail_page,--linebreak--,external_link,path_segment'], + --linebreak--,code,detail_page,--linebreak--,external_link,path_segment'], 'geolocation' => ['showitem' => 'address, longitude, latitude'], 'destinations' => ['showitem' => 'country,region,city'], 'name' => ['showitem' => 'name,short_name,--linebreak--,header_title,header_subtitle,--linebreak--,headline'], @@ -446,15 +446,6 @@ return [ 'eval' => 'trim' ], ], - 'groupsch_id' => [ - 'exclude' => 0, - 'label' => 'groups.ch ID', - 'config' => [ - 'type' => 'input', - 'size' => 8, - 'eval' => 'trim,int' - ], - ], 'external_link' => [ 'exclude' => 0, 'label' => 'Externer Link (Google MyBusiness)', diff --git a/public/typo3conf/ext/ep_products/ext_tables.sql b/public/typo3conf/ext/ep_products/ext_tables.sql index 3b927f41..807e71db 100644 --- a/public/typo3conf/ext/ep_products/ext_tables.sql +++ b/public/typo3conf/ext/ep_products/ext_tables.sql @@ -222,7 +222,6 @@ CREATE TABLE tx_epproducts_domain_model_hotel images int(11) unsigned NOT NULL default '0', reseller_images int(11) unsigned NOT NULL default '0', code varchar(255) DEFAULT '' NOT NULL, - groupsch_id varchar(8) DEFAULT '' NOT NULL, external_link varchar(255) DEFAULT '' NOT NULL, path_segment varchar(255) DEFAULT '' NOT NULL, type varchar(255) DEFAULT '' NOT NULL,