Example #1
0
 /**
  * @covers BackBee\NestedNode\Page::getLeftnode()
  * @covers BackBee\NestedNode\Page::getRightnode()
  */
 public function testGetNode()
 {
     $this->assertEquals(1, $this->page->getLeftnode());
     $this->assertEquals(2, $this->page->getRightnode());
     $child = new Page('child');
     $child->setSection($this->page->getSection());
     $this->assertEquals(1, $child->getLeftnode());
     $this->assertEquals(2, $child->getRightnode());
 }
 /**
  * @covers \BackBee\NestedNode\Repository\PageRepository::copy
  */
 public function testCopy()
 {
     $section1 = $this->repository->find('section1');
     $section2 = $this->repository->find('section2');
     $page1 = $this->repository->find('page1');
     $new_page1 = $this->invokeMethod($this->repository, 'copy', array($page1));
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $new_page1);
     $this->assertTrue(self::$em->contains($new_page1));
     $this->assertFalse($new_page1->hasMainSection());
     $this->assertEquals('page1', $new_page1->getTitle());
     $this->assertEquals($page1->getParent(), $new_page1->getParent());
     $new_page2 = $this->invokeMethod($this->repository, 'copy', array($page1, 'new_title'));
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $new_page2);
     $this->assertEquals('new_title', $new_page2->getTitle());
     $new_page3 = $this->invokeMethod($this->repository, 'copy', array($page1, 'new_title', $section2));
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $new_page3);
     $this->assertEquals($section2, $new_page3->getParent());
     $new_section = $this->invokeMethod($this->repository, 'copy', array($section1, 'new_section', $this->root));
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $new_section);
     $this->assertTrue($new_section->hasMainSection());
     $this->assertEquals($this->root->getSection(), $new_section->getSection()->getParent());
 }
Example #3
0
 /**
  * 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\\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;
 }
 /**
  * Replace root contentset for a page and its descendants.
  *
  * @param \BackBee\NestedNode\Page            $page
  * @param \BackBee\ClassContent\ContentSet    $oldContentSet
  * @param \BackBee\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\\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);
         }
     }
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * Set a page to filter the query on a nested portion.
  *
  * @param  BackBee\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()]);
     }
 }
 /**
  * @covers \BackBee\NestedNode\Repository\PageQueryBuilder::andParentIs
  */
 public function testParentIs()
 {
     $root = new Page('root');
     $child = new Page('child');
     $child->setSection($root->getSection());
     $q = $this->repository->createQueryBuilder('p')->andParentIs();
     $this->assertInstanceOf('BackBee\\NestedNode\\Repository\\PageQueryBuilder', $q);
     $this->assertEquals('SELECT p FROM BackBee\\NestedNode\\Page p INNER JOIN p._section p_s WHERE p_s._parent IS NULL AND p_s = p', $q->getDql());
     $q->resetDQLPart('where')->andParentIs($child);
     $this->assertEquals('SELECT p FROM BackBee\\NestedNode\\Page p INNER JOIN p._section p_s WHERE 1 = 0', $q->getDql());
     $q->resetDQLPart('where')->andParentIs($root);
     $this->assertEquals('SELECT p FROM BackBee\\NestedNode\\Page p INNER JOIN p._section p_s WHERE (p_s._parent = :parent0 OR p._section = :parent0) AND p._level = :level0', $q->getDql());
     $this->assertEquals($root->getSection(), $q->getParameter('parent0')->getValue());
     $this->assertEquals($root->getLevel() + 1, $q->getParameter('level0')->getValue());
 }