/**
  * Get the previous page permalink in the menu
  *
  * @param Page $activePage
  *
  * @return string|null
  * @throws Exception
  */
 public function previousPermalinkInMenuFunction(Page $activePage)
 {
     if (!$activePage instanceof Page) {
         throw new Exception('Not a Page entity');
     }
     if ($activePage->getParent() instanceof Page) {
         return $activePage->getParent()->getPermalink();
     }
     $previousPermalinkInMenu = $this->getPageRepository()->getPreviousPermalinkInMenu($activePage);
     if (null === $previousPermalinkInMenu && $activePage->getParent() instanceof Page) {
         $previousPermalinkInMenu = $this->getPageRepository()->getPreviousPermalinkInMenu($activePage);
     }
     return $previousPermalinkInMenu;
 }
 /**
  * Get the next page permalink from the parent page
  *
  * @param Page $page
  *
  * @return string|null
  */
 public function getPreviousPermalinkFromParentPage(Page $page)
 {
     $parentPage = $page->getParent();
     if (!$parentPage instanceof Page) {
         return null;
     }
     $qb = $this->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'];
 }