/** * Replace root contentset for a page and its descendants. * * @param \BackBee\CoreDomain\NestedNode\Page $page * @param \BackBee\CoreDomain\ClassContent\ContentSet $oldContentSet * @param \BackBee\CoreDomain\ClassContent\ContentSet $newContentSet * @param \BackBee\Security\Token\BBUserToken $userToken */ public function updateRootContentSetByPage(Page $page, ContentSet $oldContentSet, ContentSet $newContentSet, BBUserToken $userToken) { $em = $this->_em; $q = $this->createQueryBuilder('c'); $results = $q->leftJoin('c._pages', 'p')->leftJoin('p._section', 'sp')->leftJoin('c._subcontent', 'subcontent')->where('subcontent = :contentToReplace')->andWhere('sp._root = :cpageRoot')->andWhere('sp._leftnode > :cpageLeftnode')->andWhere('sp._rightnode < :cpageRightnode')->setParameters(['contentToReplace' => $oldContentSet, 'cpageRoot' => $page->getSection()->getRoot(), 'cpageLeftnode' => $page->getLeftnode(), 'cpageRightnode' => $page->getRightnode()])->getQuery()->getResult(); if ($results) { foreach ($results as $parentContentSet) { /* create draft for the main container */ $draft = $em->getRepository('BackBee\\CoreDomain\\ClassContent\\Revision')->getDraft($parentContentSet, $userToken, true); if (null !== $draft) { $parentContentSet->setDraft($draft); } /* Replace the old ContentSet by the new one */ $parentContentSet->replaceChildBy($oldContentSet, $newContentSet); $em->persist($parentContentSet); } } }
/** * Sets the parent node. * * @param Page $parent * * @return Page */ public function setParent(Page $parent) { if (!$parent->hasMainSection()) { throw new InvalidArgumentException('A parent page must be a section'); } if (!$this->hasMainSection() || $this->isRoot()) { $this->setSection($parent->getSection()); } else { $this->getSection()->setParent($parent->getSection()); } return $this; }
/** * Add query part to select descendants of $page. * * @param Page $page The page to look for descendants * @param boolean $strict Optional, if false (by default) $node is include to the selection * @param integer|null $depth Optional, filter ancestors by their level * @param string[]|null $order Optional, ordering spec ( [$field => $sort] ) * @param integer|null $limit Optional, max number of results, if null no limit * @param integer $start Optional, first result index (0 by default) * @param boolean $limitToSection Optional, if true limits to descendants being section * * @return PageQueryBuilder */ public function andIsDescendantOf(Page $page, $strict = false, $depth = null, array $order = null, $limit = null, $start = 0, $limitToSection = false) { $suffix = $this->getSuffix(); $this->andWhere($this->getSectionAlias() . '._root = :root' . $suffix)->andWhere($this->expr()->between($this->getSectionAlias() . '._leftnode', $page->getSection()->getLeftnode(), $page->getSection()->getRightnode()))->setParameter('root' . $suffix, $page->getSection()->getRoot()); if (true === $strict) { $this->andWhere($this->getAlias() . ' != :page' . $suffix)->setParameter('page' . $suffix, $page); } if (null !== $depth) { $this->andWhere($this->getAlias() . '._level <= :level' . $suffix)->setParameter('level' . $suffix, $page->getLevel() + $depth); } if (null !== $order) { $this->addMultipleOrderBy($order); } if (null !== $limit) { $this->setMaxResults($limit)->setFirstResult($start); } if (true === $limitToSection) { $this->andIsSection(); } return $this; }
/** * Shift level values for pages descendants of $page by $delta. * * @param Page $page The page for which to shift level. * @param integer $delta The shift value of position. * @param boolean $strict Does $page is include (true) or not (false, by default). * * @return PageRepository */ private function shiftLevel(Page $page, $delta, $strict = false) { if (false === $page->hasMainSection() && true === $strict) { return $this; } $query = $this->createQueryBuilder('p')->update()->set('p._level', 'p._level + :delta'); if (true === $page->hasMainSection()) { $subquery = $this->getEntityManager()->getRepository('BackBee\\CoreDomain\\NestedNode\\Section')->createQueryBuilder('n')->select('n._uid')->andIsDescendantOf($page->getSection()); $query->andWhere('p._section IN (' . $subquery->getDQL() . ')')->setParameters($subquery->getParameters()); if (true === $strict) { $query->andWhere('p <> :page')->setParameter('page', $page); } } else { $query->andWhere('p = :page')->setParameter('page', $page); } $query->setParameter('delta', $delta)->getQuery()->execute(); return $this; }
/** * Set a page to filter the query on a nested portion. * * @param BackBee\CoreDomain\NestedNode\Page $page */ 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()]); } }