*/ class PostRepositoryQuery extends RepositoryQuery { public function __construct(PostRepository $repository, PaginatorInterface $paginator) { parent::__construct($repository, 'p', $paginator); } public function inCategory(Category $category) { $c = 'c'.mt_rand(); $this ->innerJoin('p.categories', $c) ->andWhere($c.'.id = :category') ->setParameter(':category', $category->getId()) ; return $this; } public function published() { return $this ->andWhere('.status = 1') ->andWhere('.publishedAt <= :now') ->setParameter(':now', (new \DateTime('now'))->format('Y-m-d H:i:s')); } public function useFilters(array $filters) { foreach ($filters as $name => $value) { if ($value === null) { 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 ($name === 'category') { $this->inCategory($value); } } } return $this; } }