45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repository\Blog;
|
|
|
|
use App\Core\Repository\RepositoryQuery;
|
|
use Knp\Component\Pager\PaginatorInterface;
|
|
|
|
/**
|
|
* class CommentRepositoryQuery.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class CommentRepositoryQuery extends RepositoryQuery
|
|
{
|
|
public function __construct(CommentRepository $repository, PaginatorInterface $paginator)
|
|
{
|
|
parent::__construct($repository, 'c', $paginator);
|
|
}
|
|
|
|
public function useFilters(array $filters)
|
|
{
|
|
foreach ($filters as $name => $value) {
|
|
if (null === $value) {
|
|
continue;
|
|
}
|
|
|
|
if (is_int($value)) {
|
|
$this->andWhere('.'.$name.' = :'.$name);
|
|
$this->setParameter(':'.$name, $value);
|
|
} elseif (is_string($value)) {
|
|
$this->andWhere('.'.$name.' LIKE :'.$name);
|
|
$this->setParameter(':'.$name, '%'.$value.'%');
|
|
} else {
|
|
if ('post' === $name) {
|
|
$this
|
|
->andWhere('.post = :postId')
|
|
->setParameter(':postId', $value->getId());
|
|
}
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|