thirdPartyRepository->createQueryBuilder('tp'); $qb->leftJoin('tp.parent', 'parent') ->andWhere($qb->expr()->andX( 'tp.active = \'TRUE\'', $qb->expr()->orX($qb->expr()->isNull('parent'), 'parent.active = \'TRUE\'') )); if (null !== $filterString) { $qb->andWhere($qb->expr()->like('tp.canonicalized', 'LOWER(UNACCENT(:filterString))')) ->setParameter('filterString', '%'.$filterString.'%'); } return $qb; } public function countThirdParties( string $role, ?string $filterString, ): int { $qb = $this->buildQuery($filterString); $qb->select('count(tp)'); return $qb->getQuery()->getSingleScalarResult(); } public function listThirdParties( string $role, ?string $filterString, ?array $orderBy = [], ?int $limit = null, ?int $offset = null, ): array { $qb = $this->buildQuery($filterString); foreach ($orderBy as $sort => $direction) { $qb->addOrderBy('tp.'.$sort, $direction); } $qb->setFirstResult($offset) ->setMaxResults($limit); return $qb->getQuery()->getResult(); } }