Disable the page relative menus if needed.

@param PageInterface $page

@return bool
198959
private function disablePageRelativeMenus(PageInterface $page)
    {
        $disabledMenus = false;
        if (!$page->isEnabled()) {

            // Disable menu children query
            $disableChildrenQuery = $this->em->createQuery(sprintf(
                'UPDATE %s m SET m.enabled = 0 WHERE m.root = :root AND m.left > :left AND m.right < :right',
                $this->menuClass
            ));

            // Disable pointing menus
            /** @var \Ekyna\Bundle\CmsBundle\Model\MenuInterface[] $menus */
            $menus = $this->em
                ->createQuery("SELECT m FROM {$this->menuClass} m WHERE m.route = :route")
                ->setParameter('route', $page->getRoute())
                ->getResult();
            if (!empty($menus)) {
                foreach ($menus as $menu) {
                    if ($menu->isEnabled()) {
                        $menu->setEnabled(false);
                        $this->em->persist($menu);
                        $disabledMenus = true;

                        $disableChildrenQuery->execute(array(
                            'root'  => $menu->getRoot(),
                            'left'  => $menu->getLeft(),
                            'right' => $menu->getRight(),
                        ));
                    }
                }
            }
        }
        return $disabledMenus;
    }
356165
public function findOrCreateFor(HasPageTemplateInterface $page)
    {
        $pageTemplateConfiguration = $this->repo->findFor($page);

        if (null === $pageTemplateConfiguration) {
            $pageTemplates = $this->reader->getPageTemplates($page);
            $names = array_keys($pageTemplates);
            $defaultPageTemplate = $pageTemplates[$names[0]];

            $pageTemplateConfiguration = new PageTemplateConfiguration();
            $pageTemplateConfiguration->setPageId($page->getId());
            $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
            $pageTemplateConfiguration->setPageTemplate($defaultPageTemplate->getName());
        }

        return $pageTemplateConfiguration;
    }
948376
public function setPage($page)
    {
        if (empty($page)) {
            return $this->clearPage();
        }

        session()->put($this->getSessionKey(static::TYPE_PAGE), $page);

        return $this;
    }
884846
public function setPage($page)
    {
        $this->offset = (max(1, (int) $page) - 1) * $this->perPage;

        return $this;
    }
185433
public function clearCacheCascade(Page $page, $depth = -1){
        if ($depth == 0) return;
        $depth--;
        foreach($page->getSubpages() as $p){
            $this->clearPage($p);
            $this->clearCacheCascade($p, $depth);
        }
    }
305295
public function needTranslatedPages(Page $page)
    {
       // Route page
       if (!$page->getParent() || !is_null($page->getSourceId()))
       {
            return FALSE;
       }
       if ($this->container->hasParameter('fulgurio_light_cms.languages'))
       {
            $availableLangs = $this->container->getParameter('fulgurio_light_cms.languages');
            $nbAvailableLangs = count($availableLangs);
            $availableTranslatedPages = $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->findBy(array('source_id' => $page->getId()), array('lang' => 'ASC'));
            $nbAvailableTranslatedPages = count($availableTranslatedPages);
            $availableTranslatedParents = $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->findBy(array('source_id' => $page->getParent()->getId()), array('lang' => 'ASC'));
            $nbAvailableTranslatedParents = count($availableTranslatedParents);
            // If we create a new page
            if ($page->getParent()->getMetaValue('is_home') == '1' && $nbAvailableLangs != $availableTranslatedPages)
            {
                $langs = array_flip($availableLangs);
                foreach ($availableTranslatedPages as $availableTranslatedPage)
                {
                    unset($langs[$availableTranslatedPage->getLang()]);
                }
                foreach ($langs as $lang => $value)
                {
                    if ($lang == $page->getLang())
                    {
                        unset($langs[$lang]);
                    }
                    else
                    {
                        $langs[$lang] = $page->getParent()->getId();
                    }
                }
                return $langs;
            }
            // Normal children page
            else if ($nbAvailableTranslatedPages != $nbAvailableTranslatedParents && $nbAvailableTranslatedParents < $nbAvailableLangs)
            {
                $langs = array_flip($availableLangs);
                foreach ($availableTranslatedPages as $availableTranslatedPage)
                {
                    unset($langs[$availableTranslatedPage->getLang()]);
                }
                foreach ($availableTranslatedParents as $availableTranslatedParent)
                {
                    if (isset($langs[$availableTranslatedParent->getLang()]))
                    {
                        $langs[$availableTranslatedParent->getLang()] = $availableTranslatedParent->getId();
                    }
                }
                foreach ($langs as $lang => $value)
                {
                    if (is_null($value) || $lang == $page->getLang())
                    {
                        unset($langs[$lang]);
                    }
                }
                return $langs;
            }
        }
        return FALSE;
    }
237053
private function softDelete(Page $page)
    {
        if ($page->isRoot()) {
            throw new BadRequestHttpException('Cannot remove root page of a site.');
        }

        $this->granted('DELETE', $page);
        $this->granted('EDIT', $page->getParent()); // user must have edit permission on parent

        if ($page->isOnline(true)) {
            $this->granted('PUBLISH', $page); // user must have publish permission on the page
        }

        $this->getPageRepository()->toTrash($page);
    }
737202
public function page(int $page)
    {
        $this->query = array_merge($this->query ?? [], ['page' => $page]);

        return $this;
    }
1145366
public function page($page)
    {
        $page = (int)$page;

        if($page<0){
            throw new \RuntimeException('Invalid page specified', ResourceException::INVALID_PAGE);
        }

        $this->page = $page;

        return $this;
    }
1068080
private function createMenus(PageInterface $page, array $menus)
    {
        if (!empty($menus)) {
            foreach ($menus as $parentName => $config) {
                if (null === $parent = $this->menuRepository->findOneByName($parentName)) {
                    $this->output->writeln(sprintf(
                        '<error>Parent menu "%s" not found for route "%s".</error>',
                        $parentName,
                        $page->getRoute()
                    ));

                    return false;
                }

                $name = $page->getRoute();
                if (null === $this->menuRepository->findOneBy(['name' => $name, 'parent' => $parent])) {
                    /** @var \Ekyna\Bundle\CmsBundle\Model\MenuInterface $menu */
                    $menu = $this->menuRepository->createNew();
                    $menu
                        ->setParent($parent)
                        ->setName($name)
                        ->setRoute($name);

                    if (isset($config['options'])) {
                        $menu->setOptions((array)$config['options']);
                    }
                    if (isset($config['attributes'])) {
                        $menu->setAttributes((array)$config['attributes']);
                    }

                    foreach ($this->locales as $locale) {
                        $menuTranslation = $menu->translate($locale, true);
                        $menuTranslation
                            ->setTitle($page->translate($locale)->getTitle());
                    }

                    if (!$this->validate($menu)) {
                        return false;
                    }

                    $this->menuOperator->persist($menu);
                }
            }
        }

        return true;
    }
818944
public function deletePage(Page $page)
    {
        if ($page->hasMainSection()) {
            $this->getEntityManager()
                    ->getRepository('BackBee\NestedNode\Section')
                    ->deleteSection($page->getSection());
        }

        if (null !== $page->getContentSet()) {
            $this->getEntityManager()
                    ->createQueryBuilder()
                    ->update('BackBee\NestedNode\\Page', 'p')
                    ->set('p._contentset', ':null')
                    ->where('p._contentset = :uid')
                    ->setParameter('uid', $page->getContentSet()->getUid())
                    ->setParameter('null', null)
                    ->getQuery()
                    ->execute();

            $this->getEntityManager()
                    ->getRepository('BackBee\ClassContent\AbstractClassContent')
                    ->deleteContent($page->getContentSet());
        }

        $this->getEntityManager()
                ->createQueryBuilder()
                ->update('BackBee\ClassContent\AbstractClassContent', 'c')
                ->set('c._mainnode', ':null')
                ->where('c._mainnode = :uid')
                ->setParameter('uid', $page->getUid())
                ->setParameter('null', null)
                ->getQuery()
                ->execute();

        $this->getEntityManager()->remove($page);
    }
55006
public function removePage(Page $page): Category
    {
        $this->children->removeElement($page);

        $page->setCategory(null);

        return $this;
    }
979862
public function render(PageInterface $page)
    {
        foreach ($this->renderers as $renderer) {
            if (!$renderer->supports($page)) {
                continue;
            }

            return $renderer->render($page);
        }

        return $page->getContent();
    }
1334517
public function isPageAllowed($page)
    {
        if ($this->hook('isPageAllowed', array($page)) === true) {
            return true;
        }

        return in_array($page, $this->allowed_pages) || in_array(str_replace('_', '/', $page), $this->allowed_pages);
    }
468763
public function setPosition(BasePage $page)
    {
        if ($page->getParent()) {
            $pageNb = count($page->getParent()->getChildren());
        } else {
            $pageNb = count($this->entityManager->getRepository('VictoirePageBundle:BasePage')->findByParent(null));
        }

        // + 1 because position start at 1, not 0
        $page->setPosition($pageNb + 1);

        return $page;
    }
495889
public function render(PageInterface $page)
    {
        $templateName = $this->locateTemplate();

        return $this
            ->engine
            ->render(
                $templateName, [
                    'page' => $page,
                ]
            );
    }
671814
protected function updateSeoPage(PageInterface $page)
    {
        if (!$this->seoPage) {
            return;
        }

        /*
         * Always prefer the page title, if set.
         * Do not use the (internal) page name as a fallback
         */
        if ($page->getTitle()) {
            $this->seoPage->setTitle($page->getTitle());
        }

        if ($page->getMetaDescription()) {
            $this->seoPage->addMeta('name', 'description', $page->getMetaDescription());
        }

        if ($page->getMetaKeyword()) {
            $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword());
        }

        $this->seoPage->addMeta('property', 'og:type', 'article');
        $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#');
    }