<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\Program\Program;
use Doctrine\ORM\NonUniqueResultException;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
class ProgramRepository extends EntityRepository
{
/** @return Program[] */
public function findByNamePart(string $phrase, string $locale, int|null $limit = null): array
{
return $this /** @phpstan-ignore-line */
->createQueryBuilder('o')
->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->andWhere('translation.name LIKE :name')
->setParameter('name', '%' . $phrase . '%')
->setParameter('locale', $locale)
->setMaxResults($limit)
->orderBy('translation.name')
->getQuery()
->getResult();
}
/** @throws NonUniqueResultException */
public function findByNameAndLocale(string $name, string $locale): Program|null
{
return $this /** @phpstan-ignore-line */
->createQueryBuilder('o')
->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->andWhere('translation.name LIKE :name')
->setParameter('name', $name)
->setParameter('locale', $locale)
->getQuery()
->getOneOrNullResult();
}
/** @return Program[] */
public function findByNames(array $names): array
{
return $this /** @phpstan-ignore-line */
->createQueryBuilder('o')
->innerJoin('o.translations', 'translation')
->andWhere('translation.name IN (:names)')
->setParameter('names', $names)
->getQuery()
->getResult();
}
}