add parent category in category, fix pager
This commit is contained in:
parent
655f9c9690
commit
b839f4df0b
8 changed files with 114 additions and 11 deletions
|
|
@ -18,15 +18,29 @@ class PostRepositoryQuery extends RepositoryQuery
|
|||
parent::__construct($repository, 'p', $paginator);
|
||||
}
|
||||
|
||||
public function inCategory(Category $category)
|
||||
public function inCategory(Category $category, bool $strict = true)
|
||||
{
|
||||
$c = 'c'.mt_rand();
|
||||
|
||||
$this
|
||||
->innerJoin('p.categories', $c)
|
||||
->andWhere($c.'.id = :category')
|
||||
->setParameter(':category', $category->getId())
|
||||
;
|
||||
if ($strict) {
|
||||
$this
|
||||
->innerJoin('p.categories', $c)
|
||||
->andWhere($c.'.id = :category')
|
||||
->setParameter(':category', $category->getId())
|
||||
;
|
||||
} else {
|
||||
$ids = [$category->getId()];
|
||||
|
||||
foreach ($category->getCategories() as $childCategory) {
|
||||
$ids[] = $childCategory->getId();
|
||||
}
|
||||
|
||||
$this
|
||||
->innerJoin('p.categories', $c)
|
||||
->andWhere($c.'.id IN (:categories)')
|
||||
->setParameter(':categories', $ids)
|
||||
;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue