<?php
/**
* Created by PhpStorm.
* User: grego
* Date: 04/02/2025
* Time: 14:29
*/
namespace App\Repository;
use App\Entity\BatchFeedbackEmail;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Badge>
*
* @method BatchFeedbackEmail|null find($id, $lockMode = null, $lockVersion = null)
* @method BatchFeedbackEmail|null findOneBy(array $criteria, array $orderBy = null)
* @method BatchFeedbackEmail[] findAll()
* @method BatchFeedbackEmail[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BatchFeedbackEmailRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BatchFeedbackEmail::class);
}
public function add(BatchFeedbackEmail $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(BatchFeedbackEmail $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Badge[] Returns an array of Badge objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('b.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Badge
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
const STATUS_PENDING = 0;
const STATUS_TREATED = 1;
public function getPendingBatchFeedbacksPastFiveMinuts(){
$now = new Datetime();
$past5Minuts = new Datetime();
$past5Minuts = $past5Minuts->modify('-5 minutes');
$em = $this->_em;
$request = $em->createQueryBuilder();
$request->select('bfe');
$request->from('App\Entity\BatchFeedbackEmail', 'bfe');
$request->andWhere('bfe.status = :pending');
$request->andWhere('bfe.createdAt >= :pastFiveMinuts AND bfe.createdAt <= :now');
$request->setParameter('pending', self::STATUS_PENDING);
$request->setParameter('pastFiveMinuts', $past5Minuts);
$request->setParameter('now', $now);
$batchFeedbackEmails = $request->getQuery()->getResult();
return $batchFeedbackEmails;
}
}