Moves $page as first child of $parent

@param Page      $page
@param Page|null $parent

@throws BadRequestHttpException Raises if $parent is null
14426
private function moveAsFirstChildOf(Page $page, Page $parent = null)
    {
        if (null === $parent) {
            throw new BadRequestHttpException('Parent uid doesn\'t exists');
        }

        $this->granted('EDIT', $parent);

        if (!$parent->hasMainSection()) {
            $this->getPageRepository()->saveWithSection($parent);
        }

        $this->getPageRepository()->moveAsFirstChildOf($page, $parent);
    }
1143363
public function setPage(Page $page)
    {
        $this->page = $page;
        $revision = $page->getCurrentRevision();
        if (empty($revision)) {
            $revision = $page->getPublishedRevision();
        }
        $revisionId = null;
        if (!empty($revision)) {
            $revisionId = $revision->getRevisionId();
        }
        $this->setRevisionId($revisionId);
        $this->setTitle($page->getPageTitle());
        $this->setPageId($page->getPageId());
    }
196745
public function checkPageValidity($page, $parameters = null)
    {
        $entity = null;
        $errorMessage = 'The page was not found';
        if ($parameters) {
            $errorMessage .= ' for parameters "'.implode('", "', $parameters).'"';
        }
        $isPageOwner = false;

        //there is no page
        if ($page === null) {
            throw new NotFoundHttpException($errorMessage);
        }

        if ($this->tokenStorage->getToken()) {
            $isPageOwner = $this->authorizationChecker->isGranted('PAGE_OWNER', $page);
        }

        //a page not published, not owned, nor granted throw an exception
        if (($page instanceof BasePage && !$page->isPublished()) && !$isPageOwner) {
            throw new NotFoundHttpException($errorMessage);
        }

        //if the page is a BusinessTemplate and the entity is not allowed for this page pattern
        if ($page instanceof BusinessTemplate) {
            //only victoire users are able to access a business page
            if (!$this->authorizationChecker->isGranted('ROLE_VICTOIRE')) {
                throw new AccessDeniedException('You are not allowed to see this page');
            }
        } elseif ($page instanceof BusinessPage) {
            $entity = $page->getBusinessEntity();
            if (!$entity->isVisibleOnFront() && !$this->authorizationChecker->isGranted('ROLE_VICTOIRE')) {
                throw new NotFoundHttpException('The BusinessPage for '.get_class($entity).'#'.$entity->getId().' is not visible on front.');
            }
            if (!$page->getId()) {
                $entityAllowed = $this->businessPageHelper->isEntityAllowed($page->getTemplate(), $entity, $this->entityManager);

                if ($entityAllowed === false) {
                    throw new NotFoundHttpException('The entity ['.$entity->getId().'] is not allowed for the page pattern ['.$page->getTemplate()->getId().']');
                }
            }
        }

        if (!$this->authorizationChecker->isGranted('ROLE_VICTOIRE')) {
            $roles = $this->getPageRoles($page);
            if ($roles && !$this->authorizationChecker->isGranted($roles, $entity)) {
                throw new AccessDeniedException('You are not allowed to see this page, see the access roles defined in the view or its parents and templates');
            }
        }
    }
131780
public function saveParentPage(Lang $lang, Page $page, int $parentPageId) : void
    {
        if ($parentPageId === 0)
        {
            $parentPage = $this->pageRepository->findOneLangRoot($lang);
        }
        else
        {
            $parentPage = $this->pageRepository->findOneById($parentPageId);
        }

        if (!$parentPage)
        {
            throw new \Exception("Nadřazená stránka s id: '{$parentPageId}' nebyla nalezena.");
        }

        $page->setParent($parentPage);
        $page->moveToLastChildOf($parentPage);
        $page->save();
    }
1004443
public function revokePagePrivileges(Page $page)
    {
        if ($this->revokePageStatement == null) {
            $this->revokePageStatement =
                $this->connection->prepare("DELETE FROM UserPrivileges WHERE username = ? AND pageId = ?");
        }
        $this->revokePageStatement->execute(array($this->user->getUsername(), $page->getID()));
        unset($this->pagePrivilege[$page->getID()]);
    }
132172
public function postAdd(Page $page)
    {
        $this->authorize('add', $page);

        $parent = $page->getAddPageParent();
        $newPage = $this->dispatch(new CreatePage($parent));

        return PageFacade::find($newPage->getId());
    }
228778
public function resetChildrenUri(Page $page)
    {
        foreach ($page->subpages as $subpage) {
            $uris = $subpage->getTranslations('uri');
            foreach ($uris as $locale => $uri) {
                $subpage->forgetTranslation('uri', $locale);
            }
            $subpage->save();
            $this->resetChildrenUri($subpage);
        }
    }
693707
public function settingsPostAction(Request $request, BasePage $page)
    {
        return new JsonResponse(parent::settingsPostAction($request, $page));
    }
56024
public function updateSeoByEntity(BasePage $page, $entity)
    {
        //if no entity is provided
        if ($entity === null) {
            //we look for the entity of the page
            if ($page->getBusinessEntity() !== null) {
                $entity = $page->getBusinessEntity();
            }
        }

        //only if we have an entity instance
        if ($entity !== null) {
            //the page seo
            $pageSeo = $page->getSeo();

            //the page seo might not exist yet
            if ($pageSeo !== null) {
                $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);

                if ($businessEntity !== null) {
                    $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');

                    //parse the business properties
                    foreach ($businessProperties as $businessProperty) {
                        //parse of seo attributes
                        foreach ($this->pageSeoAttributes as $seoAttribute) {
                            $value = $this->getEntityAttributeValue($pageSeo, $seoAttribute);
                            // we only update value if its a string and (if its a VBP or its a BP where value is not defined)
                            if (is_string($value) && ($page instanceof VirtualBusinessPage || ($page instanceof BusinessPage && $value == null))) {
                                $value = $this->parameterConverter->setBusinessPropertyInstance(
                                    $value,
                                    $businessProperty,
                                    $entity
                                );
                            }
                            $this->setEntityAttributeValue($pageSeo, $seoAttribute, $value);
                        }
                    }
                }
            }
        }
    }
459699
public function __HANDLER($page = null)
    {
        $parent = CMSNav::fullTree();
        $tree = new \samson\treeview\SamsonTree('tree/tree-template', 0, 'structure/addchildren');

        // Установим дерево ЭСС
        m()->view('index')
            ->title(t('Элементы структуры содержания сайта', true))
            ->set($tree->htmlTree($parent), 'tree');
    }
1348525
public function handleRequest(Request $request, Page &$page)
    {
        $page->setData([
            "link" => $request->request->get("vfou_cmsbundle_page")["link"],
            "code" => $request->request->get("vfou_cmsbundle_page")["code"]
        ]);
    }
1299456
public function initPage(Page $page)
	{
		/* @var $annotations PageUrlAnnotation[] */
		$annotations = $this->annotationManager->getClassAnnotations($page, '@page-url');

		if ( !$annotations || !($annotations[0] instanceof PageUrlAnnotation) ) {
			return $this;
		}

		$page->setUrlBuilder(
			$this->urlFactory->getBuilder(
				$this->urlNormalizer->normalize($annotations[0])
			)
		);

		return $this;
	}
103103
public function moveAsFirstChildOf(Page $page, Page $target)
    {
        return $this->moveAsChildOf($page, $target, true);
    }
1331898
public function addPageFilter(Page $page)
    {
        if ($page && !$page->isRoot()) {
            $this->leftJoin('cc._mainnode', 'p')
                    ->leftJoin('p._section', 'sp')
                    ->andWhere('sp._root = :selectedPageRoot')
                    ->andWhere('sp._leftnode >= :selectedPageLeftnode')
                    ->andWhere('sp._rightnode <= :selectedPageRightnode')
                    ->setParameters([
                        'selectedPageRoot' => $page->getSection()->getRoot(),
                        'selectedPageLeftnode' => $page->getLeftnode(),
                        'selectedPageRightnode' => $page->getRightnode(),
                    ]);
        }
    }
462476
public function andParentIs(Page $page = null)
    {
        if (null === $page) {
            // Looking for root
            return $this->andWhere($this->getSectionAlias() . '._parent IS NULL')
                            ->andWhere($this->getSectionAlias() . ' = ' . $this->getAlias());
        }

        if (false === $page->hasMainSection()) {
            // Page is leaf, no child
            return $this->andWhere('1 = 0');
        }

        $suffix = $this->getSuffix();
        $qOr = $this->expr()->orX();
        $qOr->add($this->getSectionAlias().'._parent = :parent'.$suffix)
                ->add($this->getAlias().'._section = :parent'.$suffix);

        return $this->andWhere($qOr)
                        ->andWhere($this->getAlias().'._level = :level'.$suffix)
                        ->setParameter('parent'.$suffix, $page->getSection())
                        ->setParameter('level'.$suffix, $page->getLevel() + 1);
    }
131067
private function readPage($page) {
        if (isset($page[1][1]['/Kids'])) {
            // Nested pages!
            foreach ($page[1][1]['/Kids'][1] as $subref) {
                $subpage = $this->getObjectVal($subref);
                $this->readPage($subpage);
            }
        } else {
            $this->pages[] = $page;
        }
    }
216204
public function setPage($page)
    {
        $this->page = min($page > 0 ? $page : $this->getFirstPage(), $this->getLastPage());
    }