Add title-based tag enrichment fallback for listing rows
This commit is contained in:
@@ -75,6 +75,7 @@ class OrganizationListingTemplateDataListener
|
|||||||
|
|
||||||
$organizationTagMap = $this->fetchOrganizationTagMap(array_values(array_unique(array_values($rowToOrganizationIdMap))));
|
$organizationTagMap = $this->fetchOrganizationTagMap(array_values(array_unique(array_values($rowToOrganizationIdMap))));
|
||||||
$organizationLogoUuidMap = $this->fetchOrganizationLogoUuidMap(array_values(array_unique(array_values($rowToOrganizationIdMap))));
|
$organizationLogoUuidMap = $this->fetchOrganizationLogoUuidMap(array_values(array_unique(array_values($rowToOrganizationIdMap))));
|
||||||
|
$organizationTagMapByTitle = $this->fetchOrganizationTagMapByTitle(array_values(array_unique(array_filter($rowToTitleMap))));
|
||||||
|
|
||||||
foreach ($rowToOrganizationIdMap as $rowIndex => $organizationId) {
|
foreach ($rowToOrganizationIdMap as $rowIndex => $organizationId) {
|
||||||
$tagData = $organizationTagMap[$organizationId] ?? ['labels' => [], 'slugs' => []];
|
$tagData = $organizationTagMap[$organizationId] ?? ['labels' => [], 'slugs' => []];
|
||||||
@@ -93,6 +94,24 @@ class OrganizationListingTemplateDataListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($tbody as $rowIndex => $row) {
|
||||||
|
if (!\is_array($row) || isset($rowToOrganizationIdMap[$rowIndex])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = $this->normalizeTitle($this->extractRowFieldContent($row, 'title'));
|
||||||
|
|
||||||
|
if ('' === $title || !isset($organizationTagMapByTitle[$title])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tagData = $organizationTagMapByTitle[$title];
|
||||||
|
|
||||||
|
$tbody[$rowIndex]['tag_labels']['content'] = implode(', ', $tagData['labels']);
|
||||||
|
$tbody[$rowIndex]['tag_slugs']['content'] = implode(',', $tagData['slugs']);
|
||||||
|
$tbody[$rowIndex]['tags']['content'] = implode(', ', $tagData['labels']);
|
||||||
|
}
|
||||||
|
|
||||||
$template->tbody = $tbody;
|
$template->tbody = $tbody;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +300,55 @@ class OrganizationListingTemplateDataListener
|
|||||||
return $map;
|
return $map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param list<string> $titles
|
||||||
|
* @return array<string, array{labels: list<string>, slugs: list<string>}>
|
||||||
|
*/
|
||||||
|
private function fetchOrganizationTagMapByTitle(array $titles): array
|
||||||
|
{
|
||||||
|
if ([] === $titles) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $this->connection->executeQuery(
|
||||||
|
'SELECT o.title, r.tag_id, t.tag AS label FROM tl_organization o INNER JOIN tl_tags_rel r ON r.pid = o.id AND r.ptable = ? INNER JOIN tl_tags t ON t.id = r.tag_id WHERE o.title IN (?) ORDER BY o.title ASC, r.tag_id ASC',
|
||||||
|
['tl_organization', $titles],
|
||||||
|
[ParameterType::STRING, ArrayParameterType::STRING],
|
||||||
|
)->fetchAllAssociative();
|
||||||
|
|
||||||
|
$map = [];
|
||||||
|
$seen = [];
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$title = $this->normalizeTitle((string) ($row['title'] ?? ''));
|
||||||
|
$tagId = (int) ($row['tag_id'] ?? 0);
|
||||||
|
$label = trim((string) ($row['label'] ?? ''));
|
||||||
|
|
||||||
|
if ('' === $title || $tagId <= 0 || '' === $label) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($seen[$title][$tagId])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$seen[$title][$tagId] = true;
|
||||||
|
$map[$title]['labels'][] = $label;
|
||||||
|
|
||||||
|
$slug = $this->slugify($label);
|
||||||
|
|
||||||
|
if ('' !== $slug) {
|
||||||
|
$map[$title]['slugs'][] = $slug;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($map as $title => $tagData) {
|
||||||
|
$map[$title]['labels'] = array_values(array_unique($tagData['labels'] ?? []));
|
||||||
|
$map[$title]['slugs'] = array_values(array_unique($tagData['slugs'] ?? []));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
/** @param list<int> $organizationIds
|
/** @param list<int> $organizationIds
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user