src/Repository/Distinctions/DistinctionsRepository.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Distinctions;
  3. use App\Entity\Distinctions\Distinctions;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Distinctions|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Distinctions|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Distinctions[]    findAll()
  10.  * @method Distinctions[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class DistinctionsRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryDistinctions::class);
  17.     }
  18.     public function getDistinctionsRandom(Distinctions $distinction$limit)
  19.     {
  20.         return $this->createQueryBuilder('d')
  21.             ->andWhere('d.id != :distinction')
  22.             ->setParameter('distinction'$distinction)
  23.             ->orderBy('RAND()')
  24.             ->setMaxResults($limit)
  25.             ->getQuery()
  26.             ->getResult()
  27.             ;
  28.     }
  29.     public function findSingleDistinction(int $id): ?Distinctions
  30.     {
  31.         return $this->createQueryBuilder('d')
  32.             ->andWhere('d.id = :id')
  33.             ->andWhere('d.online = 1')
  34.             ->setParameter('id'$id)
  35.             ->getQuery()
  36.             ->getOneOrNullResult()
  37.             ;
  38.     }
  39.     // /**
  40.     //  * @return Distinctions[] Returns an array of Distinctions objects
  41.     //  */
  42.     /*
  43.     public function findByExampleField($value)
  44.     {
  45.         return $this->createQueryBuilder('d')
  46.             ->andWhere('d.exampleField = :val')
  47.             ->setParameter('val', $value)
  48.             ->orderBy('d.id', 'ASC')
  49.             ->setMaxResults(10)
  50.             ->getQuery()
  51.             ->getResult()
  52.         ;
  53.     }
  54.     */
  55.     /*
  56.     public function findOneBySomeField($value): ?Distinctions
  57.     {
  58.         return $this->createQueryBuilder('d')
  59.             ->andWhere('d.exampleField = :val')
  60.             ->setParameter('val', $value)
  61.             ->getQuery()
  62.             ->getOneOrNullResult()
  63.         ;
  64.     }
  65.     */
  66. }