/**
  * @covers \BackBee\NestedNode\Repository\PageRepository::getVisibleDescendants
  * @covers \BackBee\NestedNode\Repository\PageRepository::getOrderingDescendants
  */
 public function testGetVisibleDescendants()
 {
     $section1 = $this->repository->find('section1');
     $section2 = $this->repository->find('section2');
     $page1 = $this->repository->find('page1');
     $page2 = $this->repository->find('page2');
     $page3 = $this->repository->find('page3');
     $this->root->setState(Page::STATE_ONLINE);
     $section2->setState(Page::STATE_ONLINE + Page::STATE_HIDDEN);
     $section1->setState(Page::STATE_ONLINE);
     $page1->setState(Page::STATE_ONLINE);
     $page2->setState(Page::STATE_ONLINE + Page::STATE_HIDDEN);
     $page3->setState(Page::STATE_ONLINE);
     self::$em->flush();
     $this->assertEquals(array(), $this->repository->getVisibleDescendants($page1));
     $this->assertEquals(array($page3, $section1, $page1), $this->repository->getVisibleDescendants($this->root));
     $this->assertEquals(array($section1, $page3), $this->repository->getVisibleDescendants($this->root, 1));
     $this->assertEquals(array($page3, $section1, $page1), $this->repository->getVisibleDescendants($this->root, 2));
     $this->assertEquals(array($this->root, $page3, $section1, $page1), $this->repository->getVisibleDescendants($this->root, 2, true));
     $this->assertEquals(array($this->root, $page3, $section1, $page1), $this->repository->getVisibleDescendants($this->root, 2, true, array()));
     $this->assertEquals(array($page1, $page3, $this->root, $section1), $this->repository->getVisibleDescendants($this->root, 2, true, array('_title' => 'ASC')));
     $this->assertEquals(array($this->root, $section1), $this->repository->getVisibleDescendants($this->root, 2, true, array('_title' => 'ASC'), false, null, null, true));
     $result = $this->repository->getVisibleDescendants($this->root, 2, true, array(), true, 1, 2);
     $this->assertInstanceOf('Doctrine\\ORM\\Tools\\Pagination\\Paginator', $result);
     $this->assertEquals(4, $result->count());
     $this->assertEquals(2, $result->getIterator()->count());
     $this->assertEquals(1, $result->getQuery()->getFirstResult());
     $this->assertEquals(2, $result->getQuery()->getMaxResults());
 }
Example #2
0
 private function updatePageState(Page $page, $state)
 {
     if ($state === 'online') {
         if (!$page->isOnline(true)) {
             $page->setState($page->getState() + 1);
         } else {
             throw new NotModifiedException();
         }
     } elseif ($state === 'offline') {
         if ($page->isOnline(true)) {
             $page->setState($page->getState() - 1);
         } else {
             throw new NotModifiedException();
         }
     } elseif ($state === 'delete') {
         if ($page->getState() >= 4) {
             $this->hardDelete($page);
         } else {
             $page->setState(4);
         }
     }
 }
Example #3
0
 /**
  * Sets state of $page and is descendant to STATE_DELETED.
  *
  * @param  Page                 $page               The page to delete.
  *
  * @return Page                                     The instance of Page entity.
  */
 public function toTrash(Page $page)
 {
     $page->setState(Page::STATE_DELETED);
     if (!$page->isLeaf()) {
         $subquery = $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->createQueryBuilder('n')->select('n._uid')->andIsDescendantOf($page->getSection());
         $this->createQueryBuilder('p')->update()->set('p._state', Page::STATE_DELETED)->andWhere('p._section IN (' . $subquery->getDQL() . ')')->setParameters($subquery->getParameters())->getQuery()->execute();
     }
     return $page;
 }
Example #4
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;
 }
Example #5
0
 /**
  * @expectedException \LogicException
  */
 public function testRootPageCantBePutOffline()
 {
     $this->page->setState(Page::STATE_OFFLINE);
 }