/**
* @param $locale
* @param null $id
* @param bool $showHome
* @param bool $showChildren
* @return \Doctrine\ORM\QueryBuilder|mixed
*/
public function getParentPagesQuery($locale, $id = null, $showHome = false, $showChildren = false)
{
$qb = $this->createQueryBuilder('p');
if (!$showHome) {
$qb->where($qb->expr()->isNull('p.isHome') . ' OR p.isHome <> 1');
}
if ($id) {
if (!$showChildren) {
/** @var $page PageInterface */
$page = $this->find($id);
$collection = new ArrayCollection($page->getAllChildren());
$childrenIds = $collection->map(function (PageInterface $p) {
return $p->getId();
});
if ($childrenIds->count()) {
$qb->andWhere($qb->expr()->notIn('p.id', $childrenIds->toArray()));
}
}
$qb->andWhere($qb->expr()->neq('p.id', $id));
}
$qb->andWhere('p.locale = :locale');
$qb->orderBy('p.path', 'ASC');
$qb->setParameter(':locale', $locale);
return $qb;
}