2025-04-23 18:55:51 +02:00

37 lines
1.0 KiB
PHP

<?php
namespace App\Infrastructure\Repository;
use App\Domain\Model\Event;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Event>
*/
class EventRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Event::class);
}
/**
* @return array<Event>
*/
public function findByDateRange(\DateTimeInterface $start, \DateTimeInterface $end): array
{
/** @var array<Event> $result */
$result = $this->createQueryBuilder('e')
->andWhere('e.from >= :start AND e.from <= :end')
->orWhere('e.to >= :start AND e.to <= :end')
->orWhere('e.from <= :start AND e.to >= :end')
->setParameter('start', $start)
->setParameter('end', $end)
->orderBy('e.from', 'ASC')
->getQuery()
->getResult();
return $result;
}
}