Skip to content

Commit

Permalink
feat: Improved classicLikeComparison for Node and NodesSources to s…
Browse files Browse the repository at this point in the history
…earch in attribute-values translations
  • Loading branch information
ambroisemaupate committed Dec 12, 2023
1 parent e534f11 commit d10dbbc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/RoadizCoreBundle/src/Repository/NodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,20 @@ public function findOneWithoutSecurity(array $criteria): ?Node
}
return $this->findOneBy($criteria);
}

protected function classicLikeComparison(
string $pattern,
QueryBuilder $qb,
string $alias = EntityRepository::DEFAULT_ALIAS
): QueryBuilder {
$qb = parent::classicLikeComparison($pattern, $qb, $alias);
$qb
->leftJoin($alias . '.attributeValues', 'av')
->leftJoin('av.attributeValueTranslations', 'avt')
;
$value = '%' . strip_tags(\mb_strtolower($pattern)) . '%';
$qb->orWhere($qb->expr()->like('LOWER(avt.value)', $qb->expr()->literal($value)));
$qb->orWhere($qb->expr()->like('LOWER(' . $alias . '.nodeName)', $qb->expr()->literal($value)));
return $qb;
}
}
17 changes: 17 additions & 0 deletions lib/RoadizCoreBundle/src/Repository/NodesSourcesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,4 +747,21 @@ public function findByNode(Node $node): array

return $qb->getQuery()->getResult();
}

protected function classicLikeComparison(
string $pattern,
QueryBuilder $qb,
string $alias = EntityRepository::DEFAULT_ALIAS
): QueryBuilder {
$qb = parent::classicLikeComparison($pattern, $qb, $alias);
$qb
->innerJoin($alias . '.node', static::NODE_ALIAS)
->leftJoin(static::NODE_ALIAS . '.attributeValues', 'av')
->leftJoin('av.attributeValueTranslations', 'avt')
;
$value = '%' . strip_tags(\mb_strtolower($pattern)) . '%';
$qb->orWhere($qb->expr()->like('LOWER(avt.value)', $qb->expr()->literal($value)));
$qb->orWhere($qb->expr()->like('LOWER(' . static::NODE_ALIAS . '.nodeName)', $qb->expr()->literal($value)));
return $qb;
}
}

0 comments on commit d10dbbc

Please sign in to comment.