src/Repository/ClientRepository.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Client;
  4. use App\Entity\Commercial;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use function Doctrine\ORM\QueryBuilder;
  8. /**
  9.  * @extends ServiceEntityRepository<Client>
  10.  *
  11.  * @method Client|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method Client|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method Client[]    findAll()
  14.  * @method Client[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class ClientRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryClient::class);
  21.     }
  22.     public function add(Client $entitybool $flush false): void
  23.     {
  24.         $this->getEntityManager()->persist($entity);
  25.         if ($flush) {
  26.             $this->getEntityManager()->flush();
  27.         }
  28.     }
  29.     public function remove(Client $entitybool $flush false): void
  30.     {
  31.         $this->getEntityManager()->remove($entity);
  32.         if ($flush) {
  33.             $this->getEntityManager()->flush();
  34.         }
  35.     }
  36.     /**
  37.      * @return Client[] Returns an array of Client objects
  38.      */
  39.     public function findAllClientNotIn($listeIdClients): array
  40.     {
  41.         if(sizeof($listeIdClients) != 0){
  42.             return $this->createQueryBuilder('c')
  43.                 ->andWhere('c.actif = true')
  44.                 ->andWhere('c.atelier = false')
  45.                 ->andWhere('c.id NOT IN(:liste)')
  46.                 ->setParameter(':liste'$listeIdClients)
  47.                 ->orderBy('c.id''DESC')
  48.                 ->getQuery()
  49.                 ->getResult();
  50.         } else {
  51.             return $this->createQueryBuilder('c')
  52.                 ->andWhere('c.actif = true')
  53.                 ->getQuery()
  54.                 ->getResult();
  55.         }
  56.     }
  57.     public function findProspectsWithoutAtelier(): array
  58.     {
  59.         return $this->createQueryBuilder('c')
  60.             ->where('c.atelier IS NULL OR c.atelier = false'// Inclure les null et false pour atelier
  61.             ->andWhere('c.prospect IS NULL OR c.prospect IN (:prospectValues)'// Inclure prospects true, false et null
  62.             ->setParameter('prospectValues', [truefalse]) // Facultatif mais explicite
  63.             ->orderBy('c.actif''DESC'// Les inactifs (false) à la fin
  64.             ->addOrderBy('c.codeClient''ASC'// Puis tri par code client ASC
  65.             ->getQuery()
  66.             ->getResult();
  67.     }
  68. //    public function findOneBySomeField($value): ?Client
  69. //    {
  70. //        return $this->createQueryBuilder('c')
  71. //            ->andWhere('c.exampleField = :val')
  72. //            ->setParameter('val', $value)
  73. //            ->getQuery()
  74. //            ->getOneOrNullResult()
  75. //        ;
  76. //    }
  77. }