public function addChild(Node $node)
    {
        if($node instanceof NodeWrapper)
        {
            if($node == $this)
            {
                throw new \InvalidArgumentException('Cannot insert node as a child of itself');
            }

            $node->insertAsLastChildOf($this);
            return $node;
        }

        $node->setLeftValue($this->getRightValue());
        $node->setRightValue($this->getRightValue() + 1);
        if($this->hasManyRoots())
        {
            $node->setRootValue($this->getRootValue());
        }

        $em = $this->getManager()->getEntityManager();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            $this->shiftRLRange($this->getRightValue(), 0, 2, ($this->hasManyRoots() ? $this->getRootValue() : null));

            $em->persist($node);

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction

        return $this->getManager()->wrapNode($node);
    }
public function addChild(Node $node)
    {
        if($node instanceof NodeWrapper)
        {
            if($node == $this)
            {
                throw new \InvalidArgumentException('Cannot insert node as a child of itself');
            }

            $node->insertAsLastChildOf($this);
            return $node;
        }

        $node->setLeftValue($this->getRightValue());
        $node->setRightValue($this->getRightValue() + 1);
        if($this->hasManyRoots())
        {
            $node->setRootValue($this->getRootValue());
        }

        $em = $this->getManager()->getEntityManager();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            $this->shiftRLRange($this->getRightValue(), 0, 2, ($this->hasManyRoots() ? $this->getRootValue() : null));

            $em->persist($node);

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction

        return $this->getManager()->wrapNode($node);
    }
public function addChild ( Node $ node ) { if ( $ node instanceof NodeWrapper ) { if ( $ node == $ this ) { throw new \ InvalidArgumentException ( 'Cannot insert node as a child of itself' ) ; } $ node -> insertAsLastChildOf ( $ this ) ; return $ node ; } $ node -> setLeftValue ( $ this -> getRightValue ( ) ) ; $ node -> setRightValue ( $ this -> getRightValue ( ) + 1 ) ; if ( $ this -> hasManyRoots ( ) ) { $ node -> setRootValue ( $ this -> getRootValue ( ) ) ; } $ em = $ this -> getManager ( ) -> getEntityManager ( ) ; // beginTransaction $ em -> getConnection ( ) -> beginTransaction ( ) ; try { $ this -> shiftRLRange ( $ this -> getRightValue ( ) , 0 , 2 , ( $ this -> hasManyRoots ( ) ? $ this -> getRootValue ( ) : null ) ) ; $ em -> persist ( $ node ) ; $ em -> flush ( ) ; $ em -> getConnection ( ) -> commit ( ) ; } catch ( \ Exception $ e ) { // @codeCoverageIgnoreStart $ em -> close ( ) ; $ em -> getConnection ( ) -> rollback ( ) ; throw $ e ; // @codeCoverageIgnoreEnd } // endTransaction return $ this -> getManager ( ) -> wrapNode ( $ node ) ; }
adds given node as the last child of this entity

@param Node $node

@return NodeWrapper $wrapper
adds given node as the last child of this entity