src/Repository/ReglesRepository.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use DateTime;
  4. use App\Entity\Regles;
  5. use App\Entity\ReglesVerification;
  6. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  7. use Doctrine\ORM\Query\Expr\Join;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. /**
  10.  * @extends ServiceEntityRepository<Regles>
  11.  *
  12.  * @method Regles|null find($id, $lockMode = null, $lockVersion = null)
  13.  * @method Regles|null findOneBy(array $criteria, array $orderBy = null)
  14.  * @method Regles[]    findAll()
  15.  * @method Regles[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  16.  */
  17. class ReglesRepository extends ServiceEntityRepository
  18. {
  19.     public function __construct(ManagerRegistry $registry)
  20.     {
  21.         parent::__construct($registryRegles::class);
  22.     }
  23.     public function add(Regles $entitybool $flush false): void
  24.     {
  25.         $this->getEntityManager()->persist($entity);
  26.         if ($flush) {
  27.             $this->getEntityManager()->flush();
  28.         }
  29.     }
  30.     public function remove(Regles $entitybool $flush false): void
  31.     {
  32.         $this->getEntityManager()->remove($entity);
  33.         if ($flush) {
  34.             $this->getEntityManager()->flush();
  35.         }
  36.     }
  37.     /**
  38.      * @return Regles[] Returns an array of Regles objects
  39.      */
  40.     public function findAllActive(): array
  41.     {
  42.         return $this->createQueryBuilder('r')
  43.             ->andWhere('r.disabled = :val')->orWhere('r.disabled IS NULL')
  44.             ->setParameter('val'false)
  45.             ->getQuery()
  46.             ->getResult();
  47.     }
  48.     /**
  49.      * @return Regles[] Returns an array of Regles objects
  50.      */
  51.     public function findByDate(DateTime $date): array
  52.     {
  53.         $today = new DateTime($date->format('Y-m-d H:i:s'));
  54.         $yesterday = new DateTime($date->format('Y-m-d H:i:s'));
  55.         return $this->createQueryBuilder('r')
  56.             ->leftJoin(ReglesVerification::class, 'rv'Join::WITH'r.id = rv.ruleId')
  57.             ->andWhere('rv.date < :today')
  58.             ->andWhere('rv.date >= :yesterday')
  59.             ->setParameter('today'$today->setTime(12000))
  60.             ->setParameter('yesterday'$yesterday->setTime(12000)->modify("-1 day"))
  61.             ->getQuery()
  62.             ->getResult();
  63.     }
  64.     //    public function findOneBySomeField($value): ?Regles
  65.     //    {
  66.     //        return $this->createQueryBuilder('r')
  67.     //            ->andWhere('r.exampleField = :val')
  68.     //            ->setParameter('val', $value)
  69.     //            ->getQuery()
  70.     //            ->getOneOrNullResult()
  71.     //        ;
  72.     //    }
  73. }