<?php
namespace App\Repository;
use App\Entity\AvisClient;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<AvisClient>
*
* @method AvisClient|null find($id, $lockMode = null, $lockVersion = null)
* @method AvisClient|null findOneBy(array $criteria, array $orderBy = null)
* @method AvisClient[] findAll()
* @method AvisClient[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class AvisClientRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, AvisClient::class);
}
public function add(AvisClient $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(AvisClient $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function findRandom(int $limit = 6): array
{
return $this->createQueryBuilder('a')
->orderBy('RAND()')
->setMaxResults($limit)
->getQuery()
->getResult();
}
public function findRandomExcluding(int $limit = 9, array $excludeIds = []): array
{
$qb = $this->createQueryBuilder('a')
->orderBy('RAND()')
->setMaxResults($limit);
if (!empty($excludeIds)) {
$qb->andWhere('a.id NOT IN (:excludeIds)')
->setParameter('excludeIds', $excludeIds);
}
return $qb->getQuery()->getResult();
}
public function countExcluding(array $excludeIds = []): int
{
$qb = $this->createQueryBuilder('a')
->select('COUNT(a.id)');
if (!empty($excludeIds)) {
$qb->andWhere('a.id NOT IN (:excludeIds)')
->setParameter('excludeIds', $excludeIds);
}
return (int) $qb->getQuery()->getSingleScalarResult();
}
// /**
// * @return AvisClient[] Returns an array of AvisClient objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('a')
// ->andWhere('a.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('a.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?AvisClient
// {
// return $this->createQueryBuilder('a')
// ->andWhere('a.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}