<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* @method User|null find($id, $lockMode = null, $lockVersion = null)
* @method User|null findOneBy(array $criteria, array $orderBy = null)
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
public function getListImprimeurByPagination($params) : array
{
$qb = $this->createQueryBuilder('u');
if($params['search'] != '') {
$qb->andWhere('u.firstname = :search OR u.lastname = :search OR u.email = :search OR u.name = :search')->setParameter('search', '%'.$params['search'].'%');
}
$qb->andWhere('u.roles Like :role or u.roles Like :role2')
->setParameter('role', '%'.'ROLE_IMPRIMEUR_ADMIN'.'%')
->setParameter('role2', '%'.'ROLE_IMPRIMEUR'.'%')
->andWhere('u.idImprimeur = :idImprimeur')
->setParameter('idImprimeur',$params['idImprimeur'])
;
$qb->orderBy('u.id', 'DESC')
->setMaxResults($params['per_page'])
->setFirstResult($params['offset']);
return $qb->getQuery()->getResult();
}
public function getUsers($maxResult,$offset)
{
return $this->createQueryBuilder('u')
->orderBy('u.id','DESC')
->setMaxResults($maxResult)
->setFirstResult($offset)
->getQuery()
->getResult()
;
}
public function getTotalResultImprimeur($params) : int
{
$qb = $this->createQueryBuilder('u')->select('count(u.id)');
if($params['search'] != '') {
$qb->andWhere('u.firstname = :search OR u.lastname = :search OR u.email = :search OR u.name = :search')->setParameter('search', '%'.$params['search'].'%');
}
$qb->andWhere('u.roles Like :role or u.roles Like :role2')
->setParameter('role', '%'.'ROLE_IMPRIMEUR_ADMIN'.'%')
->setParameter('role2', '%'.'ROLE_IMPRIMEUR'.'%')
->andWhere('u.idImprimeur = :idImprimeur')
->setParameter('idImprimeur',$params['idImprimeur'])
;
return $qb->getQuery()->getSingleScalarResult();
}
public function getUserSmsEtap1(){
$dateInitial = new \DateTime('2022-09-15');
$dateCreated = new \DateTime('now');
$dateCreated->modify('-5 minutes');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.isSendSms = 1')
->andWhere('c.etapSms = 1');
$qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
->setParameter('dateInitial',$dateInitial)
->setParameter('dateCreated',$dateCreated);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserSmsEtap2(){
$dateInitial = new \DateTime('2022-09-15');
$dateCreated = new \DateTime('now');
$dateCreated->modify('-7 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.isSendSms = 1')
->andWhere('c.etapSms = 2');
$qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
->setParameter('dateInitial',$dateInitial)
->setParameter('dateCreated',$dateCreated);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserSmsEtap3(){
$dateInitial = new \DateTime('2022-09-15');
$dateCreated = new \DateTime('now');
$dateCreated->modify('-3 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.isSendSms = 1')
->andWhere('c.etapSms = 3');
$qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
->setParameter('dateInitial',$dateInitial)
->setParameter('dateCreated',$dateCreated);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserSmsEtap4(){
$dateInitial = new \DateTime('2022-09-15');
$dateCreated = new \DateTime('now');
$dateCreated->modify('-4 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.isSendSms = 1')
->andWhere('c.etapSms = 4');
$qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
->setParameter('dateInitial',$dateInitial)
->setParameter('dateCreated',$dateCreated);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserSmsEtap5(){
$dateInitial = new \DateTime('2022-09-15');
$dateCreated = new \DateTime('now');
$dateCreated->modify('-7 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.isSendSms = 1')
->andWhere('c.etapSms = 5');
$qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
->setParameter('dateInitial',$dateInitial)
->setParameter('dateCreated',$dateCreated);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserSmsEtap6(){
$dateInitial = new \DateTime('2022-09-15');
$dateCreated = new \DateTime('now');
$dateCreated->modify('-7 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.isSendSms = 1')
->andWhere('c.etapSms = 6');
$qb->andWhere('c.dateSendSms <= :dateCreated and c.dateSendSms > :dateInitial')
->setParameter('dateInitial',$dateInitial)
->setParameter('dateCreated',$dateCreated);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function findFromGoogleOauth($id,$email){
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.idGoogle = :idGoogle or c.email = :email')
->setParameter('idGoogle',$id)
->setParameter('email',$email);
return $qb->getQuery()->getOneOrNullResult();
}
public function findFromAppleOauth($id,$email){
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.idApple = :idApple or c.email = :email')
->setParameter('idApple',$id)
->setParameter('email',$email);
return $qb->getQuery()->getOneOrNullResult();
}
public function findFromMicrosoftOauth($id,$email){
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.idMicrosoft = :idMicrosoft or c.email = :email')
->setParameter('idMicrosoft',$id)
->setParameter('email',$email);
return $qb->getQuery()->getOneOrNullResult();
}
public function getUserEtap1_2RoutineMail(){
$date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
$date->modify('-2 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.etapRoutineMail1 = 1')
->andWhere('c.etapRoutineMail1_2 = 0 or c.etapRoutineMail1_2 is null');
$qb->andWhere('c.dateEtapRoutineMail1 <= :date')
->setParameter('date',$date);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserEtap2_2RoutineMail(){
$date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
$date->modify('-2 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.etapRoutineMail2 = 1')
->andWhere('c.etapRoutineMail2_2 = 0 or c.etapRoutineMail2_2 is null');
$qb->andWhere('c.dateEtapRoutineMail2 <= :date')
->setParameter('date',$date);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserEtap2_3RoutineMail(){
$date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
$date->modify('-4 days');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.etapRoutineMail2 = 1')
->andWhere('c.etapRoutineMail2_2 = 1')
->andWhere('c.etapRoutineMail2_3 = 0 or c.etapRoutineMail2_3 is null');
$qb->andWhere('c.dateEtapRoutineMail2 <= :date')
->setParameter('date',$date);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserEtap3_2RoutineMail(){
$date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
$date->modify('-2 hours');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.etapRoutineMail3 = 1')
->andWhere('c.etapRoutineMail3_2 = 0 or c.etapRoutineMail3_2 is null');
$qb->andWhere('c.dateEtapRoutineMail3 <= :date')
->setParameter('date',$date);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
public function getUserEtap3_3RoutineMail(){
$date = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
$date->modify('-26 hours');
$qb = $this->createQueryBuilder('c');
$qb->andWhere('c.etapRoutineMail3 = 1')
->andWhere('c.etapRoutineMail3_2 = 1')
->andWhere('c.etapRoutineMail3_3 = 0 or c.etapRoutineMail3_3 is null');
$qb->andWhere('c.dateEtapRoutineMail3 <= :date')
->setParameter('date',$date);
$qb->orderBy('c.id','desc');
return $qb->getQuery()->getResult();
}
}