Example #1
0
 /**
  * Inserts a page in a tree.
  *
  * @param  Page                 $page               The page to be inserted.
  * @param  Page                 $parent             The parent node.
  * @param  integer              $position           The position of the inserted page
  * @param  boolean              $section            If true, the page is inserted with a section (false by default).
  *
  * @return Page                                     The inserted page.
  *
  * @throws InvalidArgumentException                 Raises if parent page is not a section.
  */
 public function insertNode(Page $page, Page $parent, $position, $section = false)
 {
     if (!$parent->hasMainSection()) {
         throw new InvalidArgumentException('Parent page is not a section.');
     }
     $current_parent = $page->getSection();
     $page->setParent($parent)->setPosition($position)->setLevel($parent->getSection()->getLevel() + 1);
     if (true === $section) {
         $page = $this->saveWithSection($page, $current_parent);
     } else {
         $this->shiftPosition($page, 1, true);
     }
     $parent->getSection()->setHasChildren(true);
     return $page;
 }
Example #2
0
 /**
  * Returns the built page instance.
  *
  * @return Page                                     The built page.
  */
 public function getPage()
 {
     if (null === $this->site || null === $this->layout || null === $this->title) {
         $this->reset();
         throw new \Exception("Required data missing");
     }
     $page = new Page($this->uid);
     $page->setTitle($this->title);
     $page->setSite($this->site);
     if (null !== $this->parent) {
         $page->setParent($this->insureParentIsSection($this->parent));
     }
     $page->setLayout($this->layout, $this->itemToPushInMainZone);
     if (null !== $this->url) {
         $page->setUrl($this->url);
     }
     if (null !== $this->redirect) {
         $page->setRedirect($this->redirect);
     }
     if (null !== $this->target) {
         $page->setTarget($this->target);
     }
     if (null !== $this->altTitle) {
         $page->setAltTitle($this->altTitle);
     }
     if (null !== $this->state) {
         $page->setState($this->state);
     }
     if (null !== $this->publishedAt) {
         $page->setPublishing($this->publishedAt);
     }
     if (null !== $this->createdAt) {
         $page->setCreated($this->createdAt);
     }
     if (null !== $this->archiving) {
         $page->setArchiving($this->archiving);
     }
     $pageContentSet = $page->getContentSet();
     $this->updateContentRevision($pageContentSet);
     while ($column = $pageContentSet->next()) {
         $this->updateContentRevision($column);
     }
     if (0 < count($this->elements)) {
         foreach ($this->elements as $e) {
             $column = $pageContentSet->item($e['content_set_position']);
             if ($e['set_main_node']) {
                 $e['content']->setMainNode($page);
             }
             $column->push($e['content']);
         }
         $pageContentSet->rewind();
     }
     $this->doPersistIfValid($page);
     $this->reset();
     return $page;
 }
 /**
  * @covers \BackBee\NestedNode\Repository\PageQueryBuilder::andIsSiblingsOf
  */
 public function testAndIsSiblingOf()
 {
     $root = new Page('root');
     $child = new Page('child');
     $child->setParent($root);
     $q = $this->repository->createQueryBuilder('p')->andIsSiblingsOf($root);
     $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')->andIsSiblingsOf($child);
     $this->assertEquals('SELECT p FROM BackBee\\NestedNode\\Page p INNER JOIN p._section p_s WHERE p_s._root = :root0 AND (p_s._leftnode BETWEEN 1 AND 2) AND p._level <= :level0', $q->getDql());
     $this->assertEquals($child->getSection()->getRoot(), $q->getParameter('root0')->getValue());
     $this->assertEquals($child->getLevel(), $q->getParameter('level0')->getValue());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($child, true);
     $this->assertEquals('SELECT p FROM BackBee\\NestedNode\\Page p INNER JOIN p._section p_s WHERE p_s._root = :root0 AND (p_s._leftnode BETWEEN 1 AND 2) AND p._level <= :level0 AND p != :page2', $q->getDql());
     $this->assertEquals($child, $q->getParameter('page2')->getValue());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($child, false, array('p._position' => 'ASC'));
     $this->assertEquals('SELECT p FROM BackBee\\NestedNode\\Page p INNER JOIN p._section p_s WHERE p_s._root = :root0 AND (p_s._leftnode BETWEEN 1 AND 2) AND p._level <= :level0 ORDER BY p._position ASC', $q->getDql());
     $q->andIsSiblingsOf($child, false, null, 10);
     $this->assertEquals(10, $q->getMaxResults());
     $this->assertEquals(0, $q->getFirstResult());
     $q->andIsSiblingsOf($child, false, null, 10, 1);
     $this->assertEquals(10, $q->getMaxResults());
     $this->assertEquals(1, $q->getFirstResult());
 }
Example #4
0
 /**
  * @covers BackBee\NestedNode\Page::setParent()
  * @expectedException \BackBee\Exception\InvalidArgumentException
  */
 public function testSetParentWithLeaf()
 {
     $child1 = new Page('child1');
     $child2 = new Page('child2');
     $child1->setParent($this->page);
     $child2->setParent($child1);
 }
Example #5
0
 private function generatePage($title = 'backbee', $url = null, $doPersist = false)
 {
     $page = new Page();
     $page->setRoot($this->root);
     $page->setParent($this->root);
     $page->setTitle($title);
     $page->setUrl($url);
     if ($doPersist) {
         self::$em->persist($page);
         self::$em->flush($page);
     }
     return $page;
 }