/**
  * @param int|null  $parentId             The parent node id
  * @param string    $lang                 The locale
  * @param string    $permission           The permission (read, write, ...)
  * @param AclHelper $aclHelper            The acl helper
  * @param bool      $includeHiddenFromNav Include nodes hidden from navigation or not
  *
  * @return Node[]
  */
 public function getChildNodes($parentId, $lang, $permission, AclHelper $aclHelper, $includeHiddenFromNav = false)
 {
     $qb = $this->createQueryBuilder('b')->select('b', 't', 'v')->leftJoin('b.nodeTranslations', 't', 'WITH', 't.lang = :lang')->leftJoin('t.publicNodeVersion', 'v', 'WITH', 't.publicNodeVersion = v.id')->where('b.deleted = 0')->setParameter('lang', $lang)->addOrderBy('t.weight', 'ASC')->addOrderBy('t.title', 'ASC');
     if (!$includeHiddenFromNav) {
         $qb->andWhere('b.hiddenFromNav != true');
     }
     if (is_null($parentId)) {
         $qb->andWhere('b.parent is NULL');
     } elseif ($parentId !== false) {
         $qb->andWhere('b.parent = :parent')->setParameter('parent', $parentId);
     }
     $query = $aclHelper->apply($qb, new PermissionDefinition(array($permission)));
     return $query->getResult();
 }
 /**
  * @return Query|null
  */
 public function getQuery()
 {
     if (is_null($this->query)) {
         $queryBuilder = $this->getQueryBuilder();
         $this->adaptQueryBuilder($queryBuilder);
         // Apply filters
         $filters = $this->getFilterBuilder()->getCurrentFilters();
         /* @var Filter $filter */
         foreach ($filters as $filter) {
             /* @var AbstractORMFilterType $type */
             $type = $filter->getType();
             $type->setQueryBuilder($queryBuilder);
             $filter->apply();
         }
         // Apply sorting
         if (!empty($this->orderBy)) {
             $orderBy = $this->orderBy;
             if (!strpos($orderBy, '.')) {
                 $orderBy = 'b.' . $orderBy;
             }
             $queryBuilder->orderBy($orderBy, $this->orderDirection == 'DESC' ? 'DESC' : 'ASC');
         }
         // Apply ACL restrictions (if applicable)
         if (!is_null($this->permissionDef) && !is_null($this->aclHelper)) {
             $this->query = $this->aclHelper->apply($queryBuilder, $this->permissionDef);
         } else {
             $this->query = $queryBuilder->getQuery();
         }
     }
     return $this->query;
 }
 /**
  * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getTokenStorage
  */
 public function testGetTokenStorage()
 {
     $this->assertSame($this->tokenStorage, $this->object->getTokenStorage());
 }
 /**
  * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getSecurityContext
  */
 public function testGetSecurityContext()
 {
     $this->assertSame($this->sc, $this->object->getSecurityContext());
 }