예제 #1
0
 /**
  * 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;
     }
 }