Include pax data

This commit is contained in:
Björn Fromme
2020-02-05 10:56:06 +01:00
parent 832a98df56
commit 3088336792
8 changed files with 105 additions and 69 deletions
+1 -1
View File
@@ -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
@@ -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();
}
}
@@ -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')
@@ -65,6 +65,7 @@ class ContingentDataService
'date' => $row['date'],
'minNights' => $row['minNights'],
'total' => $row['total'],
'capacity' => $row['capacity'],
];
}
@@ -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'),
@@ -5,7 +5,7 @@ namespace EP\EpProducts\Service;
*
* Copyright notice
*
* (c) 2019 Björn Fromme <[email protected]>, dreipunktnull
* (c) 2020 Björn Fromme <[email protected]>, 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;
}
}
@@ -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)',
@@ -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,