src/Repository/ClientsRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Clients;
  4. use App\Service\Securizer;
  5. use Doctrine\ORM\ORMException;
  6. use Doctrine\ORM\QueryBuilder;
  7. use Doctrine\ORM\OptimisticLockException;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  10. /**
  11.  * @method Clients|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method Clients|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method Clients[]    findAll()
  14.  * @method Clients[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class ClientsRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryClients::class);
  21.     }
  22.     /**
  23.      * @throws ORMException
  24.      * @throws OptimisticLockException
  25.      */
  26.     public function add(Clients $entitybool $flush true): void
  27.     {
  28.         $this->_em->persist($entity);
  29.         if ($flush) {
  30.             $this->_em->flush();
  31.         }
  32.     }
  33.     /**
  34.      * @throws ORMException
  35.      * @throws OptimisticLockException
  36.      */
  37.     public function remove(Clients $entitybool $flush true): void
  38.     {
  39.         $this->_em->remove($entity);
  40.         if ($flush) {
  41.             $this->_em->flush();
  42.         }
  43.     }
  44.     protected function genericRequestOrder(QueryBuilder $queryBuilder)
  45.     {
  46.         $response $queryBuilder->select('c')
  47.             ->getQuery()
  48.             ->getResult();
  49.         return $response;
  50.     }
  51.     public function findClientTous($userSecurizer $securizer): array
  52.     {
  53.         if ($securizer->isGranted($user"ROLE_TECH"))
  54.             $clients $this->findAll();
  55.         else
  56.             $clients $this->findby(['id' => $user->getIdClient()->getId()]);
  57.         return $clients;
  58.     }
  59.     //récupère la liste des client accessible a l'utilisateur et Actif
  60.     public function findClientActif($userSecurizer $securizer): array
  61.     {
  62.         if ($securizer->isGranted($user"ROLE_TECH"))
  63.             $clients $this->findby(['archiver' => false]);
  64.         else
  65.             $clients $this->findby(['id' => $user->getIdClient()->getId()]);
  66.         return $clients;
  67.     }
  68.     //récupère la liste des client accessible a l'utilisateur et Archiver
  69.     public function findClientArchiver($userSecurizer $securizer): array
  70.     {
  71.         if ($securizer->isGranted($user"ROLE_TECH"))
  72.             $clients $this->findby(['archiver' => true]);
  73.         else
  74.             $clients $this->findby(['id' => $user->getIdClient()->getId()]);
  75.         return $clients;
  76.     }
  77.     public function globalSearch(String $search$userSecurizer $securizer): array
  78.     {
  79.         if ($securizer->isGranted($user"ROLE_TECH")) {
  80.             $queryBuilder = ($this->createQueryBuilder('c')
  81.                 ->where('c.nom LIKE :search')
  82.                 ->andWhere('c.archiver = false')
  83.                 ->setParameter('search''%' $search '%')
  84.             );
  85.         }
  86.         return $this->genericRequestOrder($queryBuilder);
  87.     }
  88. }