feat(map): allow backend-selected organization tags

This commit is contained in:
Jürgen Mummert
2026-02-26 18:36:35 +01:00
parent 621ce8dc8b
commit cc4e7fc9ca
3 changed files with 32 additions and 5 deletions
+1 -1
View File
@@ -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_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']['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']['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']['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'; $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';
@@ -8,6 +8,7 @@ use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController
use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule; use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule;
use Contao\CoreBundle\Twig\FragmentTemplate; use Contao\CoreBundle\Twig\FragmentTemplate;
use Contao\ModuleModel; use Contao\ModuleModel;
use Contao\StringUtil;
use MummertMedia\EventManagerBundle\Service\MapModuleDataProvider; use MummertMedia\EventManagerBundle\Service\MapModuleDataProvider;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -33,6 +34,10 @@ class EventMapController extends AbstractFrontendModuleController
$showOrganizations = '1' === (string) ($model->mapShowOrganizations ?? ''); $showOrganizations = '1' === (string) ($model->mapShowOrganizations ?? '');
$showExternalOrganizations = '1' === (string) ($model->mapShowExternalOrganizations ?? ''); $showExternalOrganizations = '1' === (string) ($model->mapShowExternalOrganizations ?? '');
$showEvents = '1' === (string) ($model->mapShowEvents ?? ''); $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); $centerMode = (string) ($model->mapCenterMode ?? self::DEFAULT_CENTER_MODE);
$eventColor = $this->normalizeHexColor((string) ($model->mapEventColor ?? self::DEFAULT_EVENT_COLOR)); $eventColor = $this->normalizeHexColor((string) ($model->mapEventColor ?? self::DEFAULT_EVENT_COLOR));
$organizationColor = $this->normalizeHexColor((string) ($model->mapOrganizationColor ?? $eventColor), $eventColor); $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('mapCenterLng', trim((string) ($model->mapCenterLng ?? '')));
$template->set('mapCenterZoom', (int) ($model->mapCenterZoom ?? 12)); $template->set('mapCenterZoom', (int) ($model->mapCenterZoom ?? 12));
$template->set('mapItemsJson', json_encode( $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, \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(); return $template->getResponse();
} }
+24 -2
View File
@@ -26,12 +26,17 @@ class MapModuleDataProvider
/** /**
* @return list<array{type:string,markerType:string,id:int,title:string,latitude:float,longitude:float,extra:array<string,mixed>}> * @return list<array{type:string,markerType:string,id:int,title:string,latitude:float,longitude:float,extra:array<string,mixed>}>
*/ */
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) { if (!$includeOrganizations && !$includeEvents) {
return []; 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']); $locationTable = $this->resolveExistingTable(['tl_location']);
$organizationTable = $this->resolveExistingTable(['tl_organization', 'tl_organisation']); $organizationTable = $this->resolveExistingTable(['tl_organization', 'tl_organisation']);
$locationGeoColumns = null !== $locationTable ? $this->resolveGeoColumns($locationTable) : null; $locationGeoColumns = null !== $locationTable ? $this->resolveGeoColumns($locationTable) : null;
@@ -76,6 +81,12 @@ class MapModuleDataProvider
$seen['organisation'][$id] = true; $seen['organisation'][$id] = true;
$tagData = $organizationTagMap[$id] ?? ['ids' => [], 'labels' => []]; $tagData = $organizationTagMap[$id] ?? ['ids' => [], 'labels' => []];
if ([] !== $selectedOrganizationTagIds
&& [] === array_intersect($selectedOrganizationTagIds, $tagData['ids'] ?? [])) {
continue;
}
$items[] = [ $items[] = [
'type' => 'organisation', 'type' => 'organisation',
'markerType' => $this->buildOrganizationMarkerType($tagData['ids']), 'markerType' => $this->buildOrganizationMarkerType($tagData['ids']),
@@ -152,12 +163,17 @@ class MapModuleDataProvider
/** /**
* @return list<array{id:int,label:string}> * @return list<array{id:int,label:string}>
*/ */
public function getOrganizationTags(): array public function getOrganizationTags(array $selectedTagIds = []): array
{ {
if (!$this->tableExists('tl_tags')) { if (!$this->tableExists('tl_tags')) {
return []; return [];
} }
$selectedTagIds = array_values(array_unique(array_filter(
array_map('intval', $selectedTagIds),
static fn (int $tagId): bool => $tagId > 0,
)));
$columns = $this->getColumnMap('tl_tags'); $columns = $this->getColumnMap('tl_tags');
$labelColumn = isset($columns['title']) ? 'title' : (isset($columns['tag']) ? 'tag' : null); $labelColumn = isset($columns['title']) ? 'title' : (isset($columns['tag']) ? 'tag' : null);
@@ -171,6 +187,12 @@ class MapModuleDataProvider
->from('tl_tags', 't') ->from('tl_tags', 't')
->orderBy(sprintf('t.%s', $labelColumn), 'ASC'); ->orderBy(sprintf('t.%s', $labelColumn), 'ASC');
if ([] !== $selectedTagIds) {
$qb
->andWhere('t.id IN (:selectedTagIds)')
->setParameter('selectedTagIds', $selectedTagIds, ArrayParameterType::INTEGER);
}
if (isset($columns['invisible'])) { if (isset($columns['invisible'])) {
$qb->andWhere("(t.invisible IS NULL OR t.invisible = '' OR t.invisible = '0')"); $qb->andWhere("(t.invisible IS NULL OR t.invisible = '' OR t.invisible = '0')");
} }