GenreRepository.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Genre;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7. * @method Genre|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method Genre|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method Genre[] findAll()
  10. * @method Genre[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. /**
  13. * GenreRepository
  14. *
  15. * This class was generated by the Doctrine ORM. Add your own custom
  16. * repository methods below.
  17. */
  18. class GenreRepository extends ServiceEntityRepository
  19. {
  20. public function __construct(ManagerRegistry $registry)
  21. {
  22. parent::__construct($registry, Genre::class);
  23. }
  24. public function findGenres (): array
  25. {
  26. $qb = $this->createQueryBuilder('g');
  27. $query = $qb
  28. ->select('g.name')
  29. ->getQuery();
  30. return $query->getArrayResult();
  31. }
  32. public function findGenreLike(?string $query = null): ?array
  33. {
  34. $qb = $this->createQueryBuilder('g');
  35. $qb
  36. ->where($qb->expr()->like('g.name', ':genreName'))
  37. ->setParameter('genreName', '%'.$query.'%')
  38. ;
  39. return $qb->getQuery()->getResult();
  40. }
  41. }