Fix org listing data-tags and keep template project-specific
This commit is contained in:
@@ -32,6 +32,7 @@ class OrganizationListingTemplateDataListener
|
||||
}
|
||||
|
||||
$rowToOrganizationIdMap = [];
|
||||
$rowToTitleMap = [];
|
||||
|
||||
foreach ($tbody as $rowIndex => $row) {
|
||||
if (!\is_array($row)) {
|
||||
@@ -42,6 +43,29 @@ class OrganizationListingTemplateDataListener
|
||||
|
||||
if ($organizationId > 0) {
|
||||
$rowToOrganizationIdMap[(int) $rowIndex] = $organizationId;
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $this->extractRowFieldContent($row, 'title');
|
||||
|
||||
if ('' !== $title) {
|
||||
$rowToTitleMap[(int) $rowIndex] = $this->normalizeTitle($title);
|
||||
}
|
||||
}
|
||||
|
||||
if ([] !== $rowToTitleMap) {
|
||||
$titleToOrganizationIdMap = $this->resolveOrganizationIdsByTitle(array_values(array_unique(array_filter($rowToTitleMap))));
|
||||
|
||||
foreach ($rowToTitleMap as $rowIndex => $title) {
|
||||
if (isset($rowToOrganizationIdMap[$rowIndex])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$organizationId = $titleToOrganizationIdMap[$title] ?? 0;
|
||||
|
||||
if ($organizationId > 0) {
|
||||
$rowToOrganizationIdMap[$rowIndex] = $organizationId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +175,55 @@ class OrganizationListingTemplateDataListener
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @param list<string> $titles
|
||||
* @return array<string, int>
|
||||
*/
|
||||
private function resolveOrganizationIdsByTitle(array $titles): array
|
||||
{
|
||||
if ([] === $titles) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $this->connection->executeQuery(
|
||||
'SELECT o.id, o.title FROM tl_organization o WHERE o.title IN (?)',
|
||||
[$titles],
|
||||
[ArrayParameterType::STRING],
|
||||
)->fetchAllAssociative();
|
||||
|
||||
$titleToIdsMap = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$organizationId = (int) ($row['id'] ?? 0);
|
||||
$title = $this->normalizeTitle((string) ($row['title'] ?? ''));
|
||||
|
||||
if ($organizationId <= 0 || '' === $title) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$titleToIdsMap[$title][] = $organizationId;
|
||||
}
|
||||
|
||||
$titleToOrganizationIdMap = [];
|
||||
|
||||
foreach ($titleToIdsMap as $title => $organizationIds) {
|
||||
$organizationIds = array_values(array_unique(array_map('intval', $organizationIds)));
|
||||
|
||||
if (1 === \count($organizationIds)) {
|
||||
$titleToOrganizationIdMap[$title] = $organizationIds[0];
|
||||
}
|
||||
}
|
||||
|
||||
return $titleToOrganizationIdMap;
|
||||
}
|
||||
|
||||
private function normalizeTitle(string $title): string
|
||||
{
|
||||
$title = html_entity_decode($title, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$title = trim(strip_tags($title));
|
||||
|
||||
return preg_replace('/\s+/u', ' ', $title) ?? '';
|
||||
}
|
||||
|
||||
/** @param list<int> $organizationIds
|
||||
* @return array<int, array{labels: list<string>, slugs: list<string>}>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user