src/Repository/AvisClientRepository.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\AvisClient;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @extends ServiceEntityRepository<AvisClient>
  8.  *
  9.  * @method AvisClient|null find($id, $lockMode = null, $lockVersion = null)
  10.  * @method AvisClient|null findOneBy(array $criteria, array $orderBy = null)
  11.  * @method AvisClient[]    findAll()
  12.  * @method AvisClient[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class AvisClientRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryAvisClient::class);
  19.     }
  20.     public function add(AvisClient $entitybool $flush false): void
  21.     {
  22.         $this->getEntityManager()->persist($entity);
  23.         if ($flush) {
  24.             $this->getEntityManager()->flush();
  25.         }
  26.     }
  27.     public function remove(AvisClient $entitybool $flush false): void
  28.     {
  29.         $this->getEntityManager()->remove($entity);
  30.         if ($flush) {
  31.             $this->getEntityManager()->flush();
  32.         }
  33.     }
  34.     public function findRandom(int $limit 6): array
  35.     {
  36.         return $this->createQueryBuilder('a')
  37.             ->orderBy('RAND()')
  38.             ->setMaxResults($limit)
  39.             ->getQuery()
  40.             ->getResult();
  41.     }
  42.     public function findRandomExcluding(int $limit 9, array $excludeIds = []): array
  43.     {
  44.         $qb $this->createQueryBuilder('a')
  45.             ->orderBy('RAND()')
  46.             ->setMaxResults($limit);
  47.         if (!empty($excludeIds)) {
  48.             $qb->andWhere('a.id NOT IN (:excludeIds)')
  49.                ->setParameter('excludeIds'$excludeIds);
  50.         }
  51.         return $qb->getQuery()->getResult();
  52.     }
  53.     public function countExcluding(array $excludeIds = []): int
  54.     {
  55.         $qb $this->createQueryBuilder('a')
  56.             ->select('COUNT(a.id)');
  57.         if (!empty($excludeIds)) {
  58.             $qb->andWhere('a.id NOT IN (:excludeIds)')
  59.                ->setParameter('excludeIds'$excludeIds);
  60.         }
  61.         return (int) $qb->getQuery()->getSingleScalarResult();
  62.     }
  63. //    /**
  64. //     * @return AvisClient[] Returns an array of AvisClient objects
  65. //     */
  66. //    public function findByExampleField($value): array
  67. //    {
  68. //        return $this->createQueryBuilder('a')
  69. //            ->andWhere('a.exampleField = :val')
  70. //            ->setParameter('val', $value)
  71. //            ->orderBy('a.id', 'ASC')
  72. //            ->setMaxResults(10)
  73. //            ->getQuery()
  74. //            ->getResult()
  75. //        ;
  76. //    }
  77. //    public function findOneBySomeField($value): ?AvisClient
  78. //    {
  79. //        return $this->createQueryBuilder('a')
  80. //            ->andWhere('a.exampleField = :val')
  81. //            ->setParameter('val', $value)
  82. //            ->getQuery()
  83. //            ->getOneOrNullResult()
  84. //        ;
  85. //    }
  86. }