/**
  * {@inheritDoc}
  */
 public function getPreviousPermalinkFromParentPage(PageInterface $page)
 {
     $parentPage = $page->getParent();
     if (!$parentPage instanceof PageInterface) {
         return null;
     }
     $qb = $this->repository->createQueryBuilder('pages');
     $qb->select('pages.permalink');
     $qb->where('pages.parent = :parentPage');
     $qb->setParameter('parentPage', $parentPage);
     if (null !== $parentPage->getPageType()->getChildrenOrderDirection()) {
         $order = trim(strtolower($parentPage->getPageType()->getChildrenOrderDirection()));
         if ('asc' !== $order && 'desc' !== $order) {
             $order = 'asc';
         } elseif ($order === 'asc') {
             $order = 'desc';
         } elseif ($order === 'desc') {
             $order = 'asc';
         }
     } else {
         $order = 'asc';
     }
     switch ($parentPage->getPageType()->getChildrenOrderBy()) {
         case 'createdAt':
             $qb->andWhere('pages.createdAt > :createdAt');
             $qb->setParameter('createdAt', $page->getCreatedAt());
             $qb->orderBy('pages.createdAt', $order);
             break;
         case 'orderId':
         default:
             $qb->andWhere('pages.orderId < :orderId');
             $qb->setParameter('orderId', $page->getOrderId());
             $qb->orderBy('pages.orderId', $order);
             break;
     }
     $qb->setMaxResults(1);
     $result = $qb->getQuery()->getOneOrNullResult();
     if (null === $result) {
         return null;
     }
     return $result['permalink'];
 }
 /**
  * Get all childable pages except for the given page
  *
  * @param \KRSolutions\Bundle\KRCMSBundle\Entity\PageInterface $exceptThisPage
  *
  * @return QueryBuilder
  */
 public function getAllChildablePagesExceptThisPageQB(\KRSolutions\Bundle\KRCMSBundle\Entity\PageInterface $exceptThisPage = null)
 {
     $qb = $this->getAllChildablePagesQB();
     if (null !== $exceptThisPage && null !== $exceptThisPage->getId()) {
         $qb->where('pages <> :exceptThisPage');
         $qb->setParameter('exceptThisPage', $exceptThisPage);
     }
     if (null !== $exceptThisPage) {
         $qb->andWhere('pages.site = :site');
         $qb->setParameter('site', $exceptThisPage->getSite());
     }
     $qb->innerJoin('pages.pageType', 'parentPageType');
     $qb->innerJoin('parentPageType.pageTypeChildren', 'pageTypeChildren', Join::WITH, 'pageTypeChildren = :pageTypeChild');
     $qb->setParameter('pageTypeChild', $exceptThisPage->getPageType());
     return $qb;
 }