From 8c3d759754ef6ca2976803adad7e3a0430db5712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 7 Feb 2020 16:49:46 +0100 Subject: [PATCH] Reset availability chart on update --- .../Classes/Service/GroupsSwissService.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php index 13b6531c..292858e5 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php @@ -26,6 +26,7 @@ namespace EP\EpProducts\Service; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use CalendR\Period\Range; use Doctrine\DBAL\DBALException; use EP\EpProducts\Domain\Model\Contingent; use EP\EpProducts\Domain\Model\Hotel; @@ -119,6 +120,8 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface $events = []; } + $this->resetChart($range, $config['key'], $config['number']); + // $this->generateAvailabilityChart( // $events, // $config['key'], @@ -172,6 +175,21 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface $this->logger->info(sprintf('Published %d dates.', $itemCount)); } + /** + * @param Period $range + * @param string $apiKey + * @param string $houseNumber + */ + protected function resetChart(Period $range, $apiKey, $houseNumber): void + { + $item = [ + 'from' => $range->getStartDate()->format('Y-m-d'), + 'to' => $range->getEndDate()->format('Y-m-d'), + ]; + + $this->addItem($item, 0, $apiKey, $houseNumber); + } + /** * @param array $events * @param string $apiKey @@ -210,10 +228,6 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface */ protected function addItem(array $item, $status, $apiKey, $houseNumber): void { - if (0 === $item['occupancy']) { - return; - } - $url = sprintf( 'http://www.groups.swiss/api/1.0/json.php?apiKey=%s&method=setAvailabilityChart&house=%d&from=%s&till=%s&state=%d', $apiKey,