suivi/src/Repository/EventRepositoryQuery.php

66 lines
1.6 KiB
PHP

<?php
namespace App\Repository;
use App\Core\Repository\RepositoryQuery;
use App\Repository\EventRepository as Repository;
use Knp\Component\Pager\PaginatorInterface;
class EventRepositoryQuery extends RepositoryQuery
{
public function __construct(Repository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'e', $paginator);
}
public function ofProjects(array $projects): self
{
if (empty($projects)) {
return $this;
}
return $this
->innerJoin('.projects', 'p')
->andWhere('p.id IN (:projectIds)')
->setParameter('projectIds', array_map(fn ($i) => $i->getId(), $projects))
;
}
public function ofSpeakers(array $speakers): self
{
if (empty($speakers)) {
return $this;
}
return $this
->innerJoin('.speakers', 's')
->andWhere('s.id IN (:speakerIds)')
->setParameter('speakerIds', array_map(fn ($i) => $i->getId(), $speakers))
;
}
public function ofMonth(int $month): self
{
return $this
->andWhere('.startAt LIKE :month')
->setParameter('month', '%-'.sprintf('%02d', $month).'-% %')
;
}
public function ofYear(int $year): self
{
return $this
->andWhere('.startAt LIKE :year')
->setParameter('year', $year.'-%-% %')
;
}
public function ofDay(int $day): self
{
return $this
->andWhere('.startAt LIKE :day')
->setParameter('day', '%-%-'.sprintf('%02d', $day).' %')
;
}
}