src/Repository/BatchFeedbackEmailRepository.php line 79

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: grego
  5.  * Date: 04/02/2025
  6.  * Time: 14:29
  7.  */
  8. namespace App\Repository;
  9. use App\Entity\BatchFeedbackEmail;
  10. use DateTime;
  11. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. /**
  14.  * @extends ServiceEntityRepository<Badge>
  15.  *
  16.  * @method BatchFeedbackEmail|null find($id, $lockMode = null, $lockVersion = null)
  17.  * @method BatchFeedbackEmail|null findOneBy(array $criteria, array $orderBy = null)
  18.  * @method BatchFeedbackEmail[]    findAll()
  19.  * @method BatchFeedbackEmail[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  20.  */
  21. class BatchFeedbackEmailRepository extends ServiceEntityRepository
  22. {
  23.     public function __construct(ManagerRegistry $registry)
  24.     {
  25.         parent::__construct($registry, BatchFeedbackEmail::class);
  26.     }
  27.     public function add(BatchFeedbackEmail $entity, bool $flush = false): void
  28.     {
  29.         $this->getEntityManager()->persist($entity);
  30.         if ($flush) {
  31.             $this->getEntityManager()->flush();
  32.         }
  33.     }
  34.     public function remove(BatchFeedbackEmail $entity, bool $flush = false): void
  35.     {
  36.         $this->getEntityManager()->remove($entity);
  37.         if ($flush) {
  38.             $this->getEntityManager()->flush();
  39.         }
  40.     }
  41. //    /**
  42. //     * @return Badge[] Returns an array of Badge objects
  43. //     */
  44. //    public function findByExampleField($value): array
  45. //    {
  46. //        return $this->createQueryBuilder('b')
  47. //            ->andWhere('b.exampleField = :val')
  48. //            ->setParameter('val', $value)
  49. //            ->orderBy('b.id', 'ASC')
  50. //            ->setMaxResults(10)
  51. //            ->getQuery()
  52. //            ->getResult()
  53. //        ;
  54. //    }
  55. //    public function findOneBySomeField($value): ?Badge
  56. //    {
  57. //        return $this->createQueryBuilder('b')
  58. //            ->andWhere('b.exampleField = :val')
  59. //            ->setParameter('val', $value)
  60. //            ->getQuery()
  61. //            ->getOneOrNullResult()
  62. //        ;
  63. //    }
  64.     const STATUS_PENDING = 0;
  65.     const STATUS_TREATED = 1;
  66.     public function getPendingBatchFeedbacksPastFiveMinuts(){
  67.         $now = new Datetime();
  68.         $past5Minuts = new Datetime();
  69.         $past5Minuts = $past5Minuts->modify('-5 minutes');
  70.         $em = $this->_em;
  71.         $request = $em->createQueryBuilder();
  72.         $request->select('bfe');
  73.         $request->from('App\Entity\BatchFeedbackEmail', 'bfe');
  74.         $request->andWhere('bfe.status = :pending');
  75.         $request->andWhere('bfe.createdAt >= :pastFiveMinuts AND bfe.createdAt <= :now');
  76.         $request->setParameter('pending', self::STATUS_PENDING);
  77.         $request->setParameter('pastFiveMinuts', $past5Minuts);
  78.         $request->setParameter('now', $now);
  79.         $batchFeedbackEmails = $request->getQuery()->getResult();
  80.         return $batchFeedbackEmails;
  81.     }
  82. }