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;
    }
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;
    }
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 ; }
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.
Inserts a page in a tree .