Beispiel #1
0
 /**
  * @covers BackBee\NestedNode\Page::isAncestorOf()
  */
 public function testIsDescendantOf()
 {
     $child = new Page('child');
     $child->setSection($this->page->getSection());
     $this->assertFalse($child->isDescendantOf($child));
     $this->assertTrue($child->isDescendantOf($child, false));
     $this->assertTrue($child->isDescendantOf($this->page));
     $this->assertFalse($this->page->isDescendantOf($this->page));
     $this->assertTrue($this->page->isDescendantOf($this->page, false));
     $child2 = new Page('child2');
     $child2->setSection($this->page->getSection());
     $this->assertFalse($child->isDescendantOf($child2));
 }
Beispiel #2
0
 /**
  * Duplicate a page and its descendants.
  *
  * @param  Page                 $page               The page to be duplicated.
  * @param  string|null          $title              Optional, the title of the copy, if null (default) the title of the copied page.
  * @param  Page|null            $parent             Optional, the parent of the copy, if null (default) the parent of the copied page.
  *
  * @return Page                                     The copy of the page.
  *
  * @throws InvalidArgumentException                 Raises if the page is recursively duplicated in itself.
  */
 private function duplicateRecursively(Page $page, $title = null, Page $parent = null)
 {
     if (null !== $parent && true === $parent->isDescendantOf($page)) {
         throw new InvalidArgumentException('Cannot recursively duplicate a page in itself');
     }
     // Storing current children before clonage
     $children = $this->getDescendants($page, 1);
     // Cloning the page
     $new_page = $this->copy($page, $title, $parent);
     $this->_em->flush($new_page);
     // Cloning children
     foreach (array_reverse($children) as $child) {
         if (!(Page::STATE_DELETED & $child->getState())) {
             $new_child = $this->duplicateRecursively($child, null, $new_page);
             $new_page->cloningData = array_merge_recursive($new_page->cloningData, $new_child->cloningData);
         }
     }
     return $new_page;
 }