diff --git a/contao/dca/tl_module.php b/contao/dca/tl_module.php index b5a3abf..e5b05cc 100644 --- a/contao/dca/tl_module.php +++ b/contao/dca/tl_module.php @@ -9,7 +9,7 @@ use Contao\StringUtil; $GLOBALS['TL_DCA']['tl_module']['palettes']['member_organizations'] = '{title_legend},name,headline,type;{eventmanager_legend},editPage;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; $GLOBALS['TL_DCA']['tl_module']['palettes']['member_events'] = '{title_legend},name,headline,type;{eventmanager_legend},editPage;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; $GLOBALS['TL_DCA']['tl_module']['palettes']['event_filter'] = '{title_legend},name,headline,type;{eventmanager_legend},cal_calendar,eventListDomId;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; -$GLOBALS['TL_DCA']['tl_module']['palettes']['eventmanager_map'] = '{title_legend},name,headline,type;{eventmanager_legend},mapShowOrganizations,mapShowExternalOrganizations,mapShowEvents,mapEventColor,mapOrganizationColor,mapCenterMode;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; +$GLOBALS['TL_DCA']['tl_module']['palettes']['eventmanager_map'] = '{title_legend},name,headline,type;{eventmanager_legend},mapShowOrganizations,organizationTypeTags,mapShowExternalOrganizations,mapShowEvents,mapEventColor,mapOrganizationColor,mapCenterMode;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; $GLOBALS['TL_DCA']['tl_module']['palettes']['organization_edit'] = '{title_legend},name,headline,type;{eventmanager_legend},listPage,logoFolder,organizationTypeTags;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; $GLOBALS['TL_DCA']['tl_module']['palettes']['event_edit'] = '{title_legend},name,headline,type;{eventmanager_legend},listPage,eventFolder,termsPage,frontendAuthorId,frontendArchiveId,eventTypeTags;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID'; diff --git a/src/Controller/Frontend/EventMapController.php b/src/Controller/Frontend/EventMapController.php index 33bc5d6..faa5eb5 100644 --- a/src/Controller/Frontend/EventMapController.php +++ b/src/Controller/Frontend/EventMapController.php @@ -8,6 +8,7 @@ use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule; use Contao\CoreBundle\Twig\FragmentTemplate; use Contao\ModuleModel; +use Contao\StringUtil; use MummertMedia\EventManagerBundle\Service\MapModuleDataProvider; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -33,6 +34,10 @@ class EventMapController extends AbstractFrontendModuleController $showOrganizations = '1' === (string) ($model->mapShowOrganizations ?? ''); $showExternalOrganizations = '1' === (string) ($model->mapShowExternalOrganizations ?? ''); $showEvents = '1' === (string) ($model->mapShowEvents ?? ''); + $selectedOrganizationTagIds = array_values(array_unique(array_filter( + array_map('intval', StringUtil::deserialize($model->organizationTypeTags ?? null, true)), + static fn (int $tagId): bool => $tagId > 0, + ))); $centerMode = (string) ($model->mapCenterMode ?? self::DEFAULT_CENTER_MODE); $eventColor = $this->normalizeHexColor((string) ($model->mapEventColor ?? self::DEFAULT_EVENT_COLOR)); $organizationColor = $this->normalizeHexColor((string) ($model->mapOrganizationColor ?? $eventColor), $eventColor); @@ -53,10 +58,10 @@ class EventMapController extends AbstractFrontendModuleController $template->set('mapCenterLng', trim((string) ($model->mapCenterLng ?? ''))); $template->set('mapCenterZoom', (int) ($model->mapCenterZoom ?? 12)); $template->set('mapItemsJson', json_encode( - $this->mapModuleDataProvider->getMapItems($showOrganizations, $showEvents, $showExternalOrganizations), + $this->mapModuleDataProvider->getMapItems($showOrganizations, $showEvents, $showExternalOrganizations, $selectedOrganizationTagIds), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR, )); - $template->set('mapOrganizationTags', $this->mapModuleDataProvider->getOrganizationTags()); + $template->set('mapOrganizationTags', $this->mapModuleDataProvider->getOrganizationTags($selectedOrganizationTagIds)); return $template->getResponse(); } diff --git a/src/Service/MapModuleDataProvider.php b/src/Service/MapModuleDataProvider.php index a764dbb..06f8010 100644 --- a/src/Service/MapModuleDataProvider.php +++ b/src/Service/MapModuleDataProvider.php @@ -26,12 +26,17 @@ class MapModuleDataProvider /** * @return list}> */ - public function getMapItems(bool $includeOrganizations = true, bool $includeEvents = true, bool $includeExternalOrganizations = false): array + public function getMapItems(bool $includeOrganizations = true, bool $includeEvents = true, bool $includeExternalOrganizations = false, array $selectedOrganizationTagIds = []): array { if (!$includeOrganizations && !$includeEvents) { return []; } + $selectedOrganizationTagIds = array_values(array_unique(array_map( + static fn (int|string $tagId): string => (string) (int) $tagId, + array_filter($selectedOrganizationTagIds, static fn (int|string $tagId): bool => (int) $tagId > 0), + ))); + $locationTable = $this->resolveExistingTable(['tl_location']); $organizationTable = $this->resolveExistingTable(['tl_organization', 'tl_organisation']); $locationGeoColumns = null !== $locationTable ? $this->resolveGeoColumns($locationTable) : null; @@ -76,6 +81,12 @@ class MapModuleDataProvider $seen['organisation'][$id] = true; $tagData = $organizationTagMap[$id] ?? ['ids' => [], 'labels' => []]; + + if ([] !== $selectedOrganizationTagIds + && [] === array_intersect($selectedOrganizationTagIds, $tagData['ids'] ?? [])) { + continue; + } + $items[] = [ 'type' => 'organisation', 'markerType' => $this->buildOrganizationMarkerType($tagData['ids']), @@ -152,12 +163,17 @@ class MapModuleDataProvider /** * @return list */ - public function getOrganizationTags(): array + public function getOrganizationTags(array $selectedTagIds = []): array { if (!$this->tableExists('tl_tags')) { return []; } + $selectedTagIds = array_values(array_unique(array_filter( + array_map('intval', $selectedTagIds), + static fn (int $tagId): bool => $tagId > 0, + ))); + $columns = $this->getColumnMap('tl_tags'); $labelColumn = isset($columns['title']) ? 'title' : (isset($columns['tag']) ? 'tag' : null); @@ -171,6 +187,12 @@ class MapModuleDataProvider ->from('tl_tags', 't') ->orderBy(sprintf('t.%s', $labelColumn), 'ASC'); + if ([] !== $selectedTagIds) { + $qb + ->andWhere('t.id IN (:selectedTagIds)') + ->setParameter('selectedTagIds', $selectedTagIds, ArrayParameterType::INTEGER); + } + if (isset($columns['invisible'])) { $qb->andWhere("(t.invisible IS NULL OR t.invisible = '' OR t.invisible = '0')"); }