src/Repository/ProgramRepository.php line 11

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repository;
  4. use App\Entity\Program\Program;
  5. use Doctrine\ORM\NonUniqueResultException;
  6. use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
  7. class ProgramRepository extends EntityRepository
  8. {
  9.     /** @return Program[] */
  10.     public function findByNamePart(string $phrasestring $localeint|null $limit null): array
  11.     {
  12.         return $this /** @phpstan-ignore-line */
  13.             ->createQueryBuilder('o')
  14.             ->innerJoin('o.translations''translation''WITH''translation.locale = :locale')
  15.             ->andWhere('translation.name LIKE :name')
  16.             ->setParameter('name''%' $phrase '%')
  17.             ->setParameter('locale'$locale)
  18.             ->setMaxResults($limit)
  19.             ->orderBy('translation.name')
  20.             ->getQuery()
  21.             ->getResult();
  22.     }
  23.     /** @throws NonUniqueResultException */
  24.     public function findByNameAndLocale(string $namestring $locale): Program|null
  25.     {
  26.         return $this /** @phpstan-ignore-line */
  27.             ->createQueryBuilder('o')
  28.             ->innerJoin('o.translations''translation''WITH''translation.locale = :locale')
  29.             ->andWhere('translation.name LIKE :name')
  30.             ->setParameter('name'$name)
  31.             ->setParameter('locale'$locale)
  32.             ->getQuery()
  33.             ->getOneOrNullResult();
  34.     }
  35.     /** @return Program[] */
  36.     public function findByNames(array $names): array
  37.     {
  38.         return $this /** @phpstan-ignore-line */
  39.         ->createQueryBuilder('o')
  40.             ->innerJoin('o.translations''translation')
  41.             ->andWhere('translation.name IN (:names)')
  42.             ->setParameter('names'$names)
  43.             ->getQuery()
  44.             ->getResult();
  45.     }
  46. }