diff --git a/src/EventListener/EventTeaserDataAttributesListener.php b/src/EventListener/EventTeaserDataAttributesListener.php index 16ef091..3a74e3c 100644 --- a/src/EventListener/EventTeaserDataAttributesListener.php +++ b/src/EventListener/EventTeaserDataAttributesListener.php @@ -25,12 +25,14 @@ class EventTeaserDataAttributesListener $tagMap = $this->fetchTagMap($eventIds); $organizationMap = $this->fetchOrganizationMap($eventIds); $locationMap = $this->fetchLocationMap($eventIds); + $locationTitleMap = $this->fetchLocationTitleMap($locationMap); foreach ($events as $dayKey => $eventsPerDay) { foreach ($eventsPerDay as $timeKey => $eventsPerTime) { foreach ($eventsPerTime as $index => $event) { if (!isset($event['id'])) { $events[$dayKey][$timeKey][$index]['location_id'] = null; + $events[$dayKey][$timeKey][$index]['location_title'] = ''; $events[$dayKey][$timeKey][$index]['event_tags'] = ''; $events[$dayKey][$timeKey][$index]['event_org'] = ''; @@ -45,6 +47,11 @@ class EventTeaserDataAttributesListener $events[$dayKey][$timeKey][$index]['location_id'] = $locationMap[$eventId] ?? null; } + $locationId = $events[$dayKey][$timeKey][$index]['location_id']; + $events[$dayKey][$timeKey][$index]['location_title'] = null !== $locationId + ? ($locationTitleMap[(int) $locationId] ?? '') + : ''; + $events[$dayKey][$timeKey][$index]['event_tags'] = implode(',', $tagMap[$eventId] ?? []); $events[$dayKey][$timeKey][$index]['event_org'] = implode(',', $organizationMap[$eventId] ?? []); } @@ -183,4 +190,36 @@ class EventTeaserDataAttributesListener return $map; } + + /** @param array $locationMap + * @return array + */ + private function fetchLocationTitleMap(array $locationMap): array + { + $locationIds = array_values(array_unique(array_filter(array_map('intval', $locationMap), static fn (int $id): bool => $id > 0))); + + if ([] === $locationIds) { + return []; + } + + $rows = $this->connection->executeQuery( + 'SELECT id, title FROM tl_location WHERE id IN (?)', + [$locationIds], + [ArrayParameterType::INTEGER], + )->fetchAllAssociative(); + + $map = []; + + foreach ($rows as $row) { + $locationId = (int) ($row['id'] ?? 0); + + if ($locationId <= 0) { + continue; + } + + $map[$locationId] = (string) ($row['title'] ?? ''); + } + + return $map; + } }