diff --git a/.ddev/config.yaml b/.ddev/config.yaml index facaca0d..29c74fa1 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -20,7 +20,10 @@ provider: default omit_containers: [dba] use_dns_when_possible: true timezone: Europe/Berlin - +hooks: + post-start: + - exec: bash -c "sudo chown -R ${DDEV_UID}:${DDEV_GID} /var/www/html/vendor" + - exec: bash -c "sudo chown -R ${DDEV_UID}:${DDEV_GID} /var/www/html/var" # This config.yaml was created with ddev version v1.13.1 # webimage: drud/ddev-webserver:v1.13.1 diff --git a/.ddev/docker-compose.env.yaml b/.ddev/docker-compose.env.yaml index 06dca63f..229443d3 100644 --- a/.ddev/docker-compose.env.yaml +++ b/.ddev/docker-compose.env.yaml @@ -3,4 +3,22 @@ version: '3.6' services: web: environment: - - TYPO3_CONTEXT=Development/Ddev \ No newline at end of file + - TYPO3_CONTEXT=Development/Ddev + - DDEV_UID + - DDEV_GID + volumes: + - type: volume + source: var + target: /var/www/html/var + volume: + nocopy: true + - type: volume + source: vendor + target: /var/www/html/vendor + volume: + nocopy: true +volumes: + vendor: + driver: local + var: + driver: local diff --git a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php index b3727066..b818314c 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php @@ -121,12 +121,6 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface $this->resetChart($range, $config['key'], $config['number']); -// $this->generateAvailabilityChart( -// $events, -// $config['key'], -// $config['number'] -// ); - $this->generateChart( $events, $config['key'], @@ -135,45 +129,6 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface } } - /** - * @param array $events - * @param string $apiKey - * @param int $houseNumber - */ - protected function generateAvailabilityChart(array $events, $apiKey, $houseNumber): void - { - $itemCount = 0; - $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->addItem($item, 1, $apiKey, $houseNumber); - $item = [ - 'from' => $event->getBegin(), - 'occupancy' => $event->getOccupancy(), - ]; - $itemCount++; - } - - $occupancy = $event->getOccupancy(); - } - - if (!isset($item['to'])) { - $item['to'] = $event->getEnd(); - $this->addItem($item, 1, $apiKey, $houseNumber); - $itemCount++; - } - - $this->logger->info(sprintf('Published %d dates.', $itemCount)); - } - /** * @param Period $range * @param string $apiKey @@ -202,12 +157,13 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface foreach ($events as $event) { /** @var Contingent $event */ - if (null === $item && Contingent::STATUS_OK !== $event->getStatus()) { - $status = $event->getStatus(); + $contingentStatus = $this->getContingentStatus($event); + if (null === $item && Contingent::STATUS_OK !== $contingentStatus) { + $status = $contingentStatus; $item = [ 'from' => $event->getBegin(), ]; - } elseif (true === is_array($item) && $status !== $event->getStatus()) { + } elseif (true === is_array($item) && $status !== $contingentStatus) { $item['to'] = $event->getEnd(); $statusCode = Contingent::STATUS_ONREQUEST === $status ? 1 : 2; $this->addItem($item, $statusCode, $apiKey, $houseNumber); @@ -216,7 +172,30 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface } } - $this->logger->info(sprintf('Published %d blocked dates.', $itemCount)); + $this->logger->info(sprintf('Published %d dates.', $itemCount)); + } + + /** + * @param Contingent $contingent + * @return int + */ + protected function getContingentStatus(Contingent $contingent) + { + if (in_array($contingent->getStatus(), [Contingent::STATUS_BLOCKED, Contingent::STATUS_ONREQUEST], true)) { + return $contingent->getStatus(); + } + + $percentageAvailable = $contingent->getPercentageAvailable(); + + if ($percentageAvailable <= 20) { + return Contingent::STATUS_BLOCKED; + } + + if ($percentageAvailable > 20 && $percentageAvailable <= 80) { + return $contingent::STATUS_ONREQUEST; + } + + return Contingent::STATUS_OK; } /**