示例#1
0
 /**
  * Inserts a leaf node in a tree.
  *
  * @param  \BackBee\NestedNode\AbstractNestedNode             $node         The node to be inserted
  * @param  \BackBee\NestedNode\AbstractNestedNode             $parent       The parent node
  * @param  int                                                $newLeftNode  The new left node of the inserted node
  *
  * @return \BackBee\NestedNode\AbstractNestedNode             The inserted node
  * @throws \BackBee\Exception\InvalidArgumentException Occurs if the node is an ancestor of $parent or $parent is not flushed yet
  */
 protected function _insertNode(AbstractNestedNode $node, AbstractNestedNode $parent, $newLeftNode)
 {
     if ($parent->isDescendantOf($node, false)) {
         throw new InvalidArgumentException('Cannot insert node in itself or one of its descendants');
     }
     if (false === $this->_em->contains($parent)) {
         throw new InvalidArgumentException('Cannot insert in a non managed node');
     }
     $this->detachOrPersistNode($node);
     $newRightNode = $newLeftNode + $node->getWeight() - 1;
     $node->setLeftnode($newLeftNode)->setRightnode($newRightNode)->setLevel($parent->getLevel() + 1)->setParent($parent)->setRoot($parent->getRoot());
     $this->shiftRlValues($node, $node->getLeftnode(), $node->getWeight());
     $this->_em->refresh($parent);
     return $node;
 }