src/Repository/ArtistRepository.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Artist;
  4. use App\Entity\Event;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\ORM\OptimisticLockException;
  7. use Doctrine\ORM\ORMException;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. /**
  10.  * @method Artist|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method Artist|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method Artist[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class ArtistRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryArtist::class);
  19.     }
  20.     /**
  21.      * @throws ORMException
  22.      * @throws OptimisticLockException
  23.      */
  24.     public function add(Artist $entitybool $flush true): void
  25.     {
  26.         $this->_em->persist($entity);
  27.         if ($flush) {
  28.             $this->_em->flush();
  29.         }
  30.     }
  31.     /**
  32.      * @throws ORMException
  33.      * @throws OptimisticLockException
  34.      */
  35.     public function remove(Artist $entitybool $flush true): void
  36.     {
  37.         $this->_em->remove($entity);
  38.         if ($flush) {
  39.             $this->_em->flush();
  40.         }
  41.     }
  42.     public function getRandom(int $count 1, ?Event $event null)
  43.     {
  44.         $q $this->createQueryBuilder('a')
  45.             ->orderBy('RAND()')
  46.             ->setMaxResults($count);
  47.         if ($event) {
  48.             $q->join('a.lineups','l')
  49.                 ->join('l.stage''s')
  50.                 ->join('s.event','e')
  51.                 ->where('e.id=:event')
  52.                 ->setParameter('event'$event->getId()->toBinary());
  53.         }
  54.         return $q->getQuery()
  55.             ->getResult();
  56.     }
  57.     public function findAll()
  58.     {
  59.         return $this->findBy([], array('position' => 'ASC'));
  60.     }
  61.     public function findByEvent(Event $event)
  62.     {
  63.         return $this->createQueryBuilder('a')
  64.             ->join('a.lineups','l')
  65.             ->join('l.stage''s')
  66.             ->where('s.event=:event')
  67.             ->setParameter('event'$event->getId()->toBinary())
  68.             ->orderBy('a.position''ASC')
  69.             ->getQuery()
  70.             ->getResult();
  71.     }
  72. }