Skip to content

Commit

Permalink
Merge branch 'hotfix/fix_trans_search' into 'release/2.3.0'
Browse files Browse the repository at this point in the history
Fix orderby for sorting at translated attributes

See merge request metamodels/core!325
  • Loading branch information
zonky2 committed Aug 29, 2024
2 parents 91a1b70 + 03c6d08 commit d4ba6fc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Attribute/TranslatedReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ abstract protected function getValueTable();
/**
* Build a where clause for the given id(s) and language code.
*
* @param QueryBuilder $queryBuilder The query builder for the query being build.
* @param list<string>|string|null $mixIds One, none or many ids to use.
* @param list<non-empty-string> $mixLangCode The language code/s to use, optional.
* @param QueryBuilder $queryBuilder The query builder for the query being build.
* @param list<string>|string|null $mixIds One, none or many ids to use.
* @param list<non-empty-string> $mixLangCode The language code/s to use, optional.
*
* @return void
*/
Expand Down Expand Up @@ -318,7 +318,7 @@ public function searchForInLanguages($strPattern, $arrLanguages = [])
$statement = $queryBuilder->executeQuery();

// Return value list as list<mixed>, parent function wants a list<string> so we make a cast.
return \array_map(static fn (mixed $value) => (string) $value, $statement->fetchFirstColumn());
return \array_map(static fn(mixed $value) => (string) $value, $statement->fetchFirstColumn());
}

/**
Expand All @@ -329,7 +329,10 @@ public function sortIds($idList, $strDirection)
$queryBuilder = $this->connection->createQueryBuilder();
$expr = $queryBuilder->expr();
$queryBuilder
->select('IF(t2.item_id IS NOT NULL, t2.item_id, t1.item_id)')
->select(
'IF(t2.item_id IS NOT NULL, t2.item_id, t1.item_id),
IF(t2.item_id IS NOT NULL, t2.value, t1.value) AS item_value'
)
->from($this->getValueTable(), 't1')
->leftJoin(
't1',
Expand All @@ -348,7 +351,7 @@ public function sortIds($idList, $strDirection)
->setParameter('langfallbackcode', $this->getFallbackLanguage())
->setParameter('att_id', $this->get('id'))
->setParameter('id_list', \array_unique($idList), ArrayParameterType::STRING)
->orderBy('t1.value ', $strDirection);
->orderBy('item_value', $strDirection);

$statement = $queryBuilder->executeQuery();

Expand Down

0 comments on commit d4ba6fc

Please sign in to comment.