mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-22 04:16:10 +01:00
Support canceled attribute during import of destination data
Destination data provides an attribute "DETAILS_ABGESAGT" to mark an event as canceled. We now fetch that info and mark all dates of that event as canceled. This also contains refactoring of creation of dates within import. All dates had the same info, and are now created at a single place. Relates: #9280
This commit is contained in:
parent
b8b11f3e19
commit
ebb668221e
2 changed files with 73 additions and 19 deletions
|
@ -158,4 +158,22 @@ class Date extends AbstractEntity
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function createFromDestinationData(
|
||||||
|
\DateTime $start,
|
||||||
|
\DateTime $end,
|
||||||
|
bool $canceled
|
||||||
|
): self {
|
||||||
|
$date = new Date();
|
||||||
|
$date->setLanguageUid(-1);
|
||||||
|
|
||||||
|
$date->setStart($start);
|
||||||
|
$date->setEnd($end);
|
||||||
|
|
||||||
|
if ($canceled) {
|
||||||
|
$date->setCanceled('canceled');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,7 +312,10 @@ class DestinationDataImportService
|
||||||
|
|
||||||
// Set Dates
|
// Set Dates
|
||||||
if ($event['timeIntervals']) {
|
if ($event['timeIntervals']) {
|
||||||
$this->setDates($event['timeIntervals']);
|
$this->setDates(
|
||||||
|
$event['timeIntervals'],
|
||||||
|
(bool) $this->getAttributeValue($event, 'DETAILS_ABGESAGT')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Assets
|
// Set Assets
|
||||||
|
@ -357,8 +360,10 @@ class DestinationDataImportService
|
||||||
* @param array $timeIntervals
|
* @param array $timeIntervals
|
||||||
* @TODO: split into functions
|
* @TODO: split into functions
|
||||||
*/
|
*/
|
||||||
protected function setDates(array $timeIntervals)
|
protected function setDates(
|
||||||
{
|
array $timeIntervals,
|
||||||
|
bool $canceled
|
||||||
|
) {
|
||||||
|
|
||||||
// @TODO: does not seem to work -->
|
// @TODO: does not seem to work -->
|
||||||
//$currentEventDates = $this->tmpCurrentEvent->getDates();
|
//$currentEventDates = $this->tmpCurrentEvent->getDates();
|
||||||
|
@ -381,16 +386,15 @@ class DestinationDataImportService
|
||||||
if (empty($date['interval'])) {
|
if (empty($date['interval'])) {
|
||||||
if (strtotime($date['start']) > $today) {
|
if (strtotime($date['start']) > $today) {
|
||||||
$this->logger->info('Setup single date');
|
$this->logger->info('Setup single date');
|
||||||
$dateObj = $this->objectManager->get(Date::class);
|
|
||||||
$start = new \DateTime($date['start'], new \DateTimeZone($date['tz']));
|
$start = new \DateTime($date['start'], new \DateTimeZone($date['tz']));
|
||||||
$end = new \DateTime($date['end'], new \DateTimeZone($date['tz']));
|
$end = new \DateTime($date['end'], new \DateTimeZone($date['tz']));
|
||||||
$this->logger->info('Start transformed ' . $start->format('Y-m-d H:i'));
|
$this->logger->info('Start transformed ' . $start->format('Y-m-d H:i'));
|
||||||
$this->logger->info('End transformed ' . $end->format('Y-m-d H:i'));
|
$this->logger->info('End transformed ' . $end->format('Y-m-d H:i'));
|
||||||
// Set language UID
|
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
|
||||||
$dateObj->setLanguageUid(-1);
|
$start,
|
||||||
$dateObj->setStart($start);
|
$end,
|
||||||
$dateObj->setEnd($end);
|
$canceled
|
||||||
$this->tmpCurrentEvent->addDate($dateObj);
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($date['freq'] == 'Daily' && empty($date['weekdays']) && !empty($date['repeatUntil'])) {
|
if ($date['freq'] == 'Daily' && empty($date['weekdays']) && !empty($date['repeatUntil'])) {
|
||||||
|
@ -408,11 +412,11 @@ class DestinationDataImportService
|
||||||
$eventEnd = new \DateTime();
|
$eventEnd = new \DateTime();
|
||||||
$eventEnd->setTimestamp($i);
|
$eventEnd->setTimestamp($i);
|
||||||
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
||||||
$dateObj = $this->objectManager->get(Date::class);
|
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
|
||||||
$dateObj->setLanguageUid(-1);
|
$eventStart,
|
||||||
$dateObj->setStart($eventStart);
|
$eventEnd,
|
||||||
$dateObj->setEnd($eventEnd);
|
$canceled
|
||||||
$this->tmpCurrentEvent->addDate($dateObj);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($date['freq'] == 'Weekly' && !empty($date['weekdays']) && !empty($date['repeatUntil'])) {
|
} elseif ($date['freq'] == 'Weekly' && !empty($date['weekdays']) && !empty($date['repeatUntil'])) {
|
||||||
|
@ -431,11 +435,11 @@ class DestinationDataImportService
|
||||||
$eventEnd = new \DateTime();
|
$eventEnd = new \DateTime();
|
||||||
$eventEnd->setTimestamp($i);
|
$eventEnd->setTimestamp($i);
|
||||||
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
||||||
$dateObj = $this->objectManager->get(Date::class);
|
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
|
||||||
$dateObj->setLanguageUid(-1);
|
$eventStart,
|
||||||
$dateObj->setStart($eventStart);
|
$eventEnd,
|
||||||
$dateObj->setEnd($eventEnd);
|
$canceled
|
||||||
$this->tmpCurrentEvent->addDate($dateObj);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -786,4 +790,36 @@ class DestinationDataImportService
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the value for requested attribute.
|
||||||
|
*
|
||||||
|
* Returns first if multiple attributes with same key exist.
|
||||||
|
* Casts "true" and "false" to true and false.
|
||||||
|
* Return null in case no attribute value could exists.
|
||||||
|
*/
|
||||||
|
private function getAttributeValue(
|
||||||
|
array $event,
|
||||||
|
string $attributeKey
|
||||||
|
) {
|
||||||
|
$attributes = array_filter($event['attributes'] ?? [], function (array $attribute) use ($attributeKey) {
|
||||||
|
$currentKey = $attribute['key'] ?? '';
|
||||||
|
return $currentKey === $attributeKey;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($attributes === []) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $attributes[0]['value'] ?? null;
|
||||||
|
|
||||||
|
if ($value === 'true') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($value === 'false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue