suivi/src/Repository/ProjectRepositoryQuery.php

52 lines
1.2 KiB
PHP

<?php
namespace App\Repository;
use App\Core\Repository\RepositoryQuery;
use App\Entity\Establishment;
use App\Repository\ProjectRepository as Repository;
use Knp\Component\Pager\PaginatorInterface;
class ProjectRepositoryQuery extends RepositoryQuery
{
public function __construct(Repository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'p', $paginator);
}
public function withIds(?array $ids)
{
if (null === $ids) {
return $this;
}
return $this
->andWhere('.id IN (:ids)')
->setParameter('ids', $ids)
;
}
public function withEstablishment(?Establishment $establishment): self
{
if (!$establishment) {
return $this;
}
$keyEstablishment = 'k'.mt_rand();
$keyId = 'id'.mt_rand();
return $this
->innerJoin('.establishments', $keyEstablishment)
->andWhere($keyEstablishment.'.id = :'.$keyId)
->setParameter($keyId, $establishment->getId())
;
}
protected function filterHandler(string $name, $value)
{
if ('establishment' === $name) {
return $this->withEstablishment($value);
}
}
}