src/Repository/UserRepository.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\User;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\ORM\QueryBuilder;
  6. use Doctrine\Common\Persistence\ManagerRegistry;
  7. /**
  8.  * @method User|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method User|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method User[]    findAll()
  11.  * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class UserRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryUser::class);
  18.     }
  19.     public function getListImprimeurByPagination($params) : array
  20.     {
  21.         $qb $this->createQueryBuilder('u');
  22.         if($params['search'] != '') {
  23.             $qb->andWhere('u.firstname = :search OR u.lastname = :search OR u.email = :search OR  u.name = :search')->setParameter('search''%'.$params['search'].'%');
  24.         }
  25.         $qb->andWhere('u.roles Like :role or u.roles Like :role2')
  26.             ->setParameter('role''%'.'ROLE_IMPRIMEUR_ADMIN'.'%')
  27.             ->setParameter('role2''%'.'ROLE_IMPRIMEUR'.'%')
  28.             ->andWhere('u.idImprimeur = :idImprimeur')
  29.             ->setParameter('idImprimeur',$params['idImprimeur'])
  30.         ;
  31.         $qb->orderBy('u.id''DESC')
  32.             ->setMaxResults($params['per_page'])
  33.             ->setFirstResult($params['offset']);
  34.         return $qb->getQuery()->getResult();
  35.     }
  36.     public function getUsers($maxResult,$offset)
  37.     {
  38.         return $this->createQueryBuilder('u')
  39.             ->orderBy('u.id','DESC')
  40.             ->setMaxResults($maxResult)
  41.             ->setFirstResult($offset)
  42.             ->getQuery()
  43.             ->getResult()
  44.             ;
  45.     }
  46.     public function getTotalResultImprimeur($params) : int
  47.     {
  48.         $qb $this->createQueryBuilder('u')->select('count(u.id)');
  49.         if($params['search'] != '') {
  50.             $qb->andWhere('u.firstname = :search OR u.lastname = :search OR u.email = :search OR  u.name = :search')->setParameter('search''%'.$params['search'].'%');
  51.         }
  52.         $qb->andWhere('u.roles Like :role or u.roles Like :role2')
  53.             ->setParameter('role''%'.'ROLE_IMPRIMEUR_ADMIN'.'%')
  54.             ->setParameter('role2''%'.'ROLE_IMPRIMEUR'.'%')
  55.             ->andWhere('u.idImprimeur = :idImprimeur')
  56.             ->setParameter('idImprimeur',$params['idImprimeur'])
  57.         ;
  58.         return $qb->getQuery()->getSingleScalarResult();
  59.     }
  60.     public function getUserSmsEtap1(){
  61.         $dateInitial = new \DateTime('2022-09-15');
  62.         $dateCreated = new \DateTime('now');
  63.         $dateCreated->modify('-5 minutes');
  64.         $qb =  $this->createQueryBuilder('c');
  65.         $qb->andWhere('c.isSendSms = 1')
  66.             ->andWhere('c.etapSms = 1');
  67.         $qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
  68.             ->setParameter('dateInitial',$dateInitial)
  69.             ->setParameter('dateCreated',$dateCreated);
  70.         $qb->orderBy('c.id','desc');
  71.         return $qb->getQuery()->getResult();
  72.     }
  73.     public function getUserSmsEtap2(){
  74.         $dateInitial = new \DateTime('2022-09-15');
  75.         $dateCreated = new \DateTime('now');
  76.         $dateCreated->modify('-7 days');
  77.         $qb =  $this->createQueryBuilder('c');
  78.         $qb->andWhere('c.isSendSms = 1')
  79.             ->andWhere('c.etapSms = 2');
  80.         $qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
  81.             ->setParameter('dateInitial',$dateInitial)
  82.             ->setParameter('dateCreated',$dateCreated);
  83.         $qb->orderBy('c.id','desc');
  84.         return $qb->getQuery()->getResult();
  85.     }
  86.     public function getUserSmsEtap3(){
  87.         $dateInitial = new \DateTime('2022-09-15');
  88.         $dateCreated = new \DateTime('now');
  89.         $dateCreated->modify('-3 days');
  90.         $qb =  $this->createQueryBuilder('c');
  91.         $qb->andWhere('c.isSendSms = 1')
  92.             ->andWhere('c.etapSms = 3');
  93.         $qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
  94.             ->setParameter('dateInitial',$dateInitial)
  95.             ->setParameter('dateCreated',$dateCreated);
  96.         $qb->orderBy('c.id','desc');
  97.         return $qb->getQuery()->getResult();
  98.     }
  99.     public function getUserSmsEtap4(){
  100.         $dateInitial = new \DateTime('2022-09-15');
  101.         $dateCreated = new \DateTime('now');
  102.         $dateCreated->modify('-4 days');
  103.         $qb =  $this->createQueryBuilder('c');
  104.         $qb->andWhere('c.isSendSms = 1')
  105.             ->andWhere('c.etapSms = 4');
  106.         $qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
  107.             ->setParameter('dateInitial',$dateInitial)
  108.             ->setParameter('dateCreated',$dateCreated);
  109.         $qb->orderBy('c.id','desc');
  110.         return $qb->getQuery()->getResult();
  111.     }
  112.     public function getUserSmsEtap5(){
  113.         $dateInitial = new \DateTime('2022-09-15');
  114.         $dateCreated = new \DateTime('now');
  115.         $dateCreated->modify('-7 days');
  116.         $qb =  $this->createQueryBuilder('c');
  117.         $qb->andWhere('c.isSendSms = 1')
  118.             ->andWhere('c.etapSms = 5');
  119.         $qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
  120.             ->setParameter('dateInitial',$dateInitial)
  121.             ->setParameter('dateCreated',$dateCreated);
  122.         $qb->orderBy('c.id','desc');
  123.         return $qb->getQuery()->getResult();
  124.     }
  125.     public function getUserSmsEtap6(){
  126.         $dateInitial = new \DateTime('2022-09-15');
  127.         $dateCreated = new \DateTime('now');
  128.         $dateCreated->modify('-7 days');
  129.         $qb =  $this->createQueryBuilder('c');
  130.         $qb->andWhere('c.isSendSms = 1')
  131.             ->andWhere('c.etapSms = 6');
  132.         $qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
  133.             ->setParameter('dateInitial',$dateInitial)
  134.             ->setParameter('dateCreated',$dateCreated);
  135.         $qb->orderBy('c.id','desc');
  136.         return $qb->getQuery()->getResult();
  137.     }
  138.     public function findFromGoogleOauth($id,$email){
  139.         $qb =  $this->createQueryBuilder('c');
  140.         $qb->andWhere('c.idGoogle = :idGoogle or c.email = :email')
  141.             ->setParameter('idGoogle',$id)
  142.             ->setParameter('email',$email);
  143.         return $qb->getQuery()->getOneOrNullResult();
  144.     }
  145.     public function findFromAppleOauth($id,$email){
  146.         $qb =  $this->createQueryBuilder('c');
  147.         $qb->andWhere('c.idApple = :idApple or c.email = :email')
  148.             ->setParameter('idApple',$id)
  149.             ->setParameter('email',$email);
  150.         return $qb->getQuery()->getOneOrNullResult();
  151.     }
  152.     public function findFromMicrosoftOauth($id,$email){
  153.         $qb =  $this->createQueryBuilder('c');
  154.         $qb->andWhere('c.idMicrosoft = :idMicrosoft or c.email = :email')
  155.             ->setParameter('idMicrosoft',$id)
  156.             ->setParameter('email',$email);
  157.         return $qb->getQuery()->getOneOrNullResult();
  158.     }
  159.     public function getUserEtap1_2RoutineMail(){
  160.         $date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
  161.         $date->modify('-2 days');
  162.         $qb =  $this->createQueryBuilder('c');
  163.         $qb->andWhere('c.etapRoutineMail1 = 1')
  164.             ->andWhere('c.etapRoutineMail1_2 = 0 or c.etapRoutineMail1_2 is null');
  165.         $qb->andWhere('c.dateEtapRoutineMail1 <= :date')
  166.             ->setParameter('date',$date);
  167.         $qb->orderBy('c.id','desc');
  168.         return $qb->getQuery()->getResult();
  169.     }
  170.     public function getUserEtap2_2RoutineMail(){
  171.         $date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
  172.         $date->modify('-2 days');
  173.         $qb =  $this->createQueryBuilder('c');
  174.         $qb->andWhere('c.etapRoutineMail2 = 1')
  175.             ->andWhere('c.etapRoutineMail2_2 = 0 or c.etapRoutineMail2_2 is null');
  176.         $qb->andWhere('c.dateEtapRoutineMail2 <= :date')
  177.             ->setParameter('date',$date);
  178.         $qb->orderBy('c.id','desc');
  179.         return $qb->getQuery()->getResult();
  180.     }
  181.     public function getUserEtap2_3RoutineMail(){
  182.         $date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
  183.         $date->modify('-4 days');
  184.         $qb =  $this->createQueryBuilder('c');
  185.         $qb->andWhere('c.etapRoutineMail2 = 1')
  186.             ->andWhere('c.etapRoutineMail2_2 = 1')
  187.             ->andWhere('c.etapRoutineMail2_3 = 0 or c.etapRoutineMail2_3 is null');
  188.         $qb->andWhere('c.dateEtapRoutineMail2 <= :date')
  189.             ->setParameter('date',$date);
  190.         $qb->orderBy('c.id','desc');
  191.         return $qb->getQuery()->getResult();
  192.     }
  193.     public function getUserEtap3_2RoutineMail(){
  194.         $date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
  195.         $date->modify('-2 hours');
  196.         $qb =  $this->createQueryBuilder('c');
  197.         $qb->andWhere('c.etapRoutineMail3 = 1')
  198.             ->andWhere('c.etapRoutineMail3_2 = 0 or c.etapRoutineMail3_2 is null');
  199.         $qb->andWhere('c.dateEtapRoutineMail3 <= :date')
  200.             ->setParameter('date',$date);
  201.         $qb->orderBy('c.id','desc');
  202.         return $qb->getQuery()->getResult();
  203.     }
  204.     public function getUserEtap3_3RoutineMail(){
  205.         $date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
  206.         $date->modify('-26 hours');
  207.         $qb =  $this->createQueryBuilder('c');
  208.         $qb->andWhere('c.etapRoutineMail3 = 1')
  209.             ->andWhere('c.etapRoutineMail3_2 = 1')
  210.             ->andWhere('c.etapRoutineMail3_3 = 0 or c.etapRoutineMail3_3 is null');
  211.         $qb->andWhere('c.dateEtapRoutineMail3 <= :date')
  212.             ->setParameter('date',$date);
  213.         $qb->orderBy('c.id','desc');
  214.         return $qb->getQuery()->getResult();
  215.     }
  216. }