Ejemplo n.º 1
0
 /**
  * Returns the next online sibling of $page.
  *
  * @param  Page                 $page               The page to look for next sibling.
  *
  * @return Page|null                                The next page or null if the entity can not be found.
  */
 public function getOnlineNextSibling(Page $page)
 {
     $query = $this->createQueryBuilder('p');
     if (true === $page->hasMainSection()) {
         $query->andWhere($query->getSectionAlias() . '._leftnode >= :leftnode')->orWhere('p._section IN (:sections)')->setParameter('leftnode', $page->getLeftnode())->setParameter('sections', [$page->getSection(), $page->getSection()->getParent()]);
     } else {
         $query->andWhere('p._position > :position')->setParameter('position', $page->getPosition());
     }
     return $query->andIsSiblingsOf($page, true, ['_position' => 'ASC', '_leftnode' => 'ASC'], 1, 0)->andIsOnline()->getQuery()->getOneOrNullResult();
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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()]);
     }
 }