/** * Move current node and its children to location $destLeft and updates rest of tree * * @param int $destLeft Destination left value * @param int $levelDelta Delta to add to the levels * @param PropelPDO $con Connection to use. */ protected function moveSubtreeTo($destLeft, $levelDelta, PropelPDO $con = null) { $left = $this->getLeftValue(); $right = $this->getRightValue(); $scope = $this->getScopeValue(); $treeSize = $right - $left + 1; if ($con === null) { $con = Propel::getConnection(CausadiferidoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { // make room next to the target for the subtree CausadiferidoPeer::shiftRLValues($treeSize, $destLeft, null, $scope, $con); if ($left >= $destLeft) { // src was shifted too? $left += $treeSize; $right += $treeSize; } if ($levelDelta) { // update the levels of the subtree CausadiferidoPeer::shiftLevel($levelDelta, $left, $right, $scope, $con); } // move the subtree to the target CausadiferidoPeer::shiftRLValues($destLeft - $left, $left, $right, $scope, $con); // remove the empty room at the previous location of the subtree CausadiferidoPeer::shiftRLValues(-$treeSize, $right + 1, null, $scope, $con); // update all loaded nodes CausadiferidoPeer::updateLoadedNodes(null, $con); $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } }
/** * Update the tree to allow insertion of a leaf at the specified position * * @param int $left left column value * @param integer $scope scope column value * @param mixed $prune Object to prune from the shift * @param PropelPDO $con Connection to use. */ public static function makeRoomForLeaf($left, $scope, $prune = null, PropelPDO $con = null) { // Update database nodes CausadiferidoPeer::shiftRLValues(2, $left, null, $scope, $con); // Update all loaded nodes CausadiferidoPeer::updateLoadedNodes($prune, $con); }