Consider occupancy level in groups.swiss data export
This commit is contained in:
@@ -121,12 +121,6 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface
|
|||||||
|
|
||||||
$this->resetChart($range, $config['key'], $config['number']);
|
$this->resetChart($range, $config['key'], $config['number']);
|
||||||
|
|
||||||
// $this->generateAvailabilityChart(
|
|
||||||
// $events,
|
|
||||||
// $config['key'],
|
|
||||||
// $config['number']
|
|
||||||
// );
|
|
||||||
|
|
||||||
$this->generateChart(
|
$this->generateChart(
|
||||||
$events,
|
$events,
|
||||||
$config['key'],
|
$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 Period $range
|
||||||
* @param string $apiKey
|
* @param string $apiKey
|
||||||
@@ -202,12 +157,13 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface
|
|||||||
|
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
/** @var Contingent $event */
|
/** @var Contingent $event */
|
||||||
if (null === $item && Contingent::STATUS_OK !== $event->getStatus()) {
|
$contingentStatus = $this->getContingentStatus($event);
|
||||||
$status = $event->getStatus();
|
if (null === $item && Contingent::STATUS_OK !== $contingentStatus) {
|
||||||
|
$status = $contingentStatus;
|
||||||
$item = [
|
$item = [
|
||||||
'from' => $event->getBegin(),
|
'from' => $event->getBegin(),
|
||||||
];
|
];
|
||||||
} elseif (true === is_array($item) && $status !== $event->getStatus()) {
|
} elseif (true === is_array($item) && $status !== $contingentStatus) {
|
||||||
$item['to'] = $event->getEnd();
|
$item['to'] = $event->getEnd();
|
||||||
$statusCode = Contingent::STATUS_ONREQUEST === $status ? 1 : 2;
|
$statusCode = Contingent::STATUS_ONREQUEST === $status ? 1 : 2;
|
||||||
$this->addItem($item, $statusCode, $apiKey, $houseNumber);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user