mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-01-01 15:01:24 +00:00
Add repository methods for filtering
This commit is contained in:
@@ -18,12 +18,13 @@ use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
final readonly class EvaluationRepository implements EvaluationRepositoryInterface
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
public function __construct(private EntityManagerInterface $entityManager)
|
||||
public function __construct(private EntityManagerInterface $entityManager, private RequestStack $requestStack)
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(Evaluation::class);
|
||||
}
|
||||
@@ -70,6 +71,11 @@ final readonly class EvaluationRepository implements EvaluationRepositoryInterfa
|
||||
return Evaluation::class;
|
||||
}
|
||||
|
||||
private function getLang(): string
|
||||
{
|
||||
return $this->requestStack->getCurrentRequest()?->getLocale() ?? 'fr';
|
||||
}
|
||||
|
||||
public function getResult(
|
||||
QueryBuilder $qb,
|
||||
?int $start = 0,
|
||||
@@ -93,9 +99,11 @@ final readonly class EvaluationRepository implements EvaluationRepositoryInterfa
|
||||
{
|
||||
$qb = $this->entityManager->createQueryBuilder()->from(Evaluation::class, 'e');
|
||||
|
||||
$qb->expr()->like('e.title', 'CONCAT(\'%\', LOWER(UNACCENT(:pattern)), \'%\')');
|
||||
|
||||
$qb->setParameter('pattern', $pattern);
|
||||
// Extract the current locale's value from the JSON `title` and search on it
|
||||
$qb
|
||||
->where($qb->expr()->like('LOWER(UNACCENT(JSON_EXTRACT(e.title, :lang)))', "CONCAT('%', LOWER(UNACCENT(:pattern)), '%')"))
|
||||
->setParameter('pattern', $pattern)
|
||||
->setParameter('lang', $this->getLang());
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user