process review

This commit is contained in:
2023-11-13 14:06:05 +01:00
parent 5be516b14e
commit 09f823ac08
11 changed files with 43 additions and 133 deletions

View File

@@ -16,12 +16,13 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use Symfony\Component\Clock\ClockInterface;
class NewsItemRepository implements ObjectRepository
{
private readonly EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
public function __construct(EntityManagerInterface $entityManager, private ClockInterface $clock)
{
$this->repository = $entityManager->getRepository(NewsItem::class);
}
@@ -58,6 +59,9 @@ class NewsItemRepository implements ObjectRepository
public function findWithDateFilter()
{
dump($this->buildQueryWithDateFilter()
->getQuery()
->getResult());
return $this->buildQueryWithDateFilter()
->getQuery()
->getResult();
@@ -73,13 +77,13 @@ class NewsItemRepository implements ObjectRepository
public function buildQueryWithDateFilter(): QueryBuilder
{
$now = new \DateTime('now');
$now = $this->clock->now();
$qb = $this->createQueryBuilder('n');
$qb
->where(
$qb->expr()->andX(
$qb->expr()->gte('n.startDate', ':now'),
$qb->expr()->lte('n.startDate', ':now'),
$qb->expr()->orX(
$qb->expr()->lt('n.endDate', ':now'),
$qb->expr()->isNull('n.endDate')