Author: sevein
Date: Thu Jun 21 16:20:36 2012
New Revision: 11790
Log:
Add moveToPrevSiblingOf, moveToNextSiblingOf, moveSubtreeTo and shiftRLValues
methods in the ORM classes with nested set behavior
Modified:
trunk/lib/model/QubitInformationObject.php
trunk/lib/model/om/BaseActor.php
trunk/lib/model/om/BaseDigitalObject.php
trunk/lib/model/om/BaseInformationObject.php
trunk/lib/model/om/BaseMenu.php
trunk/lib/model/om/BasePhysicalObject.php
trunk/lib/model/om/BaseTaxonomy.php
trunk/lib/model/om/BaseTerm.php
trunk/lib/propel/builder/QubitObjectBuilder.php
Modified: trunk/lib/model/QubitInformationObject.php
==============================================================================
--- trunk/lib/model/QubitInformationObject.php Thu Jun 21 11:31:11 2012
(r11789)
+++ trunk/lib/model/QubitInformationObject.php Thu Jun 21 16:20:36 2012
(r11790)
@@ -1829,7 +1829,7 @@
$node['label'] = sfContext::getInstance()->i18n->__('+%1% ...',
array('%1%' => $count));
$node['parentId'] = $item['parentId'];
- $node['href'] = sfContext::getInstance()->routing->generate(null,
array(QubitInformationObject::getById($item['parentId']), 'module' =>
'informationobject', 'action' => 'browse'));
+ $node['href'] = sfContext::getInstance()->routing->generate(null,
array(QubitInformationObject::getById($item['parentId']), 'module' =>
'informationobject', 'action' => 'browse'));
$node['isLeaf'] = 'true';
$node['style'] = 'seeAllNode';
}
Modified: trunk/lib/model/om/BaseActor.php
==============================================================================
--- trunk/lib/model/om/BaseActor.php Thu Jun 21 11:31:11 2012 (r11789)
+++ trunk/lib/model/om/BaseActor.php Thu Jun 21 16:20:36 2012 (r11790)
@@ -764,4 +764,141 @@
return $this;
}
+
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitActor::LFT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitActor::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitActor::LFT, array('raw' => QubitActor::LFT . ' +
?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitActor::RGT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitActor::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitActor::RGT, array('raw' => QubitActor::RGT . ' +
?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
}
Modified: trunk/lib/model/om/BaseDigitalObject.php
==============================================================================
--- trunk/lib/model/om/BaseDigitalObject.php Thu Jun 21 11:31:11 2012
(r11789)
+++ trunk/lib/model/om/BaseDigitalObject.php Thu Jun 21 16:20:36 2012
(r11790)
@@ -491,4 +491,141 @@
return $this;
}
+
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitDigitalObject::LFT,
$first, Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+
$criterion->addAnd($whereCriteria->getNewCriterion(QubitDigitalObject::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitDigitalObject::LFT, array('raw' =>
QubitDigitalObject::LFT . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitDigitalObject::RGT,
$first, Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+
$criterion->addAnd($whereCriteria->getNewCriterion(QubitDigitalObject::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitDigitalObject::RGT, array('raw' =>
QubitDigitalObject::RGT . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
}
Modified: trunk/lib/model/om/BaseInformationObject.php
==============================================================================
--- trunk/lib/model/om/BaseInformationObject.php Thu Jun 21 11:31:11
2012 (r11789)
+++ trunk/lib/model/om/BaseInformationObject.php Thu Jun 21 16:20:36
2012 (r11790)
@@ -742,4 +742,141 @@
return $this;
}
+
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitInformationObject::LFT,
$first, Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+
$criterion->addAnd($whereCriteria->getNewCriterion(QubitInformationObject::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitInformationObject::LFT, array('raw' =>
QubitInformationObject::LFT . ' + ?', 'value' => $delta),
Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitInformationObject::RGT,
$first, Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+
$criterion->addAnd($whereCriteria->getNewCriterion(QubitInformationObject::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitInformationObject::RGT, array('raw' =>
QubitInformationObject::RGT . ' + ?', 'value' => $delta),
Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
}
Modified: trunk/lib/model/om/BaseMenu.php
==============================================================================
--- trunk/lib/model/om/BaseMenu.php Thu Jun 21 11:31:11 2012 (r11789)
+++ trunk/lib/model/om/BaseMenu.php Thu Jun 21 16:20:36 2012 (r11790)
@@ -932,6 +932,143 @@
return $this;
}
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitMenu::LFT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitMenu::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitMenu::LFT, array('raw' => QubitMenu::LFT . ' +
?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitMenu::RGT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitMenu::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitMenu::RGT, array('raw' => QubitMenu::RGT . ' +
?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
+
public function __call($name, $args)
{
if ('get' == substr($name, 0, 3) || 'set' == substr($name, 0, 3))
Modified: trunk/lib/model/om/BasePhysicalObject.php
==============================================================================
--- trunk/lib/model/om/BasePhysicalObject.php Thu Jun 21 11:31:11 2012
(r11789)
+++ trunk/lib/model/om/BasePhysicalObject.php Thu Jun 21 16:20:36 2012
(r11790)
@@ -614,4 +614,141 @@
return $this;
}
+
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitPhysicalObject::LFT,
$first, Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+
$criterion->addAnd($whereCriteria->getNewCriterion(QubitPhysicalObject::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitPhysicalObject::LFT, array('raw' =>
QubitPhysicalObject::LFT . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitPhysicalObject::RGT,
$first, Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+
$criterion->addAnd($whereCriteria->getNewCriterion(QubitPhysicalObject::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitPhysicalObject::RGT, array('raw' =>
QubitPhysicalObject::RGT . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
}
Modified: trunk/lib/model/om/BaseTaxonomy.php
==============================================================================
--- trunk/lib/model/om/BaseTaxonomy.php Thu Jun 21 11:31:11 2012 (r11789)
+++ trunk/lib/model/om/BaseTaxonomy.php Thu Jun 21 16:20:36 2012 (r11790)
@@ -649,4 +649,141 @@
return $this;
}
+
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitTaxonomy::LFT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitTaxonomy::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitTaxonomy::LFT, array('raw' => QubitTaxonomy::LFT
. ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitTaxonomy::RGT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitTaxonomy::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitTaxonomy::RGT, array('raw' => QubitTaxonomy::RGT
. ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
}
Modified: trunk/lib/model/om/BaseTerm.php
==============================================================================
--- trunk/lib/model/om/BaseTerm.php Thu Jun 21 11:31:11 2012 (r11789)
+++ trunk/lib/model/om/BaseTerm.php Thu Jun 21 16:20:36 2012 (r11790)
@@ -1876,4 +1876,141 @@
return $this;
}
+
+ public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->lft, $con);
+
+ return $this;
+ }
+
+ public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
+ {
+ /*
+ if (!$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if ($sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if ($sibling->isDescendantOf($this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ $this->moveSubtreeTo($sibling->rgt + 1, $con);
+
+ return $this;
+ }
+
+ protected function moveSubtreeTo($destLeft, PropelPDO $con = null)
+ {
+ $left = $this->lft;
+ $right = $this->rgt;
+
+ $treeSize = $right - $left +1;
+
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ $con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues($treeSize, $destLeft, null, $con);
+
+ if ($left >= $destLeft) // src was shifted too?
+ {
+ $left += $treeSize;
+ $right += $treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues($destLeft - $left, $left, $right, $con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-$treeSize, $right + 1, null, $con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, $con);
+
+ $con->commit();
+ }
+ catch (PropelException $e)
+ {
+ $con->rollback();
+
+ throw $e;
+ }
+ }
+
+ /**
+ * Adds $delta to all L and R values that are >= $first and <= $last.
+ * '$delta' can also be negative.
+ *
+ * @param int $delta Value to be shifted by, can be negative
+ * @param int $first First node to be shifted
+ * @param int $last Last node to be shifted (optional)
+ * @param PropelPDO $con Connection to use.
+ */
+ protected function shiftRLValues($delta, $first, $last = null, PropelPDO
$con = null)
+ {
+ if ($con === null)
+ {
+ $con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitTerm::LFT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitTerm::LFT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitTerm::LFT, array('raw' => QubitTerm::LFT . ' +
?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+
+ // Shift right column values
+ $whereCriteria = new Criteria;
+ $criterion = $whereCriteria->getNewCriterion(QubitTerm::RGT, $first,
Criteria::GREATER_EQUAL);
+ if (null !== $last)
+ {
+ $criterion->addAnd($whereCriteria->getNewCriterion(QubitTerm::RGT,
$last, Criteria::LESS_EQUAL));
+ }
+ $whereCriteria->add($criterion);
+
+ $valuesCriteria = new Criteria;
+ $valuesCriteria->add(QubitTerm::RGT, array('raw' => QubitTerm::RGT . ' +
?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
+ }
}
Modified: trunk/lib/propel/builder/QubitObjectBuilder.php
==============================================================================
--- trunk/lib/propel/builder/QubitObjectBuilder.php Thu Jun 21 11:31:11
2012 (r11789)
+++ trunk/lib/propel/builder/QubitObjectBuilder.php Thu Jun 21 16:20:36
2012 (r11790)
@@ -258,6 +258,10 @@
$this->addAddDescendantsCriteria($script);
$this->addUpdateNestedSet($script);
$this->addDeleteFromNestedSet($script);
+ $this->addMoveToPrevSiblingOf($script);
+ $this->addMoveToNextSiblingOf($script);
+ $this->addMoveSubtreeTo($script);
+ $this->addShiftRLValues($script);
}
$this->addCall($script);
@@ -2027,6 +2031,171 @@
script;
}
+ protected function addMoveToPrevSiblingOf(&$script)
+ {
+ $script .= <<<script
+
+ public function moveToPrevSiblingOf(\$sibling, PropelPDO \$con = null)
+ {
+ /*
+ if (!\$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if (\$sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if (\$sibling->isDescendantOf(\$this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ \$this->moveSubtreeTo(\$sibling->lft, \$con);
+
+ return \$this;
+ }
+
+script;
+ }
+
+ protected function addMoveToNextSiblingOf(&$script)
+ {
+ $script .= <<<script
+
+ public function moveToNextSiblingOf(\$sibling, PropelPDO \$con = null)
+ {
+ /*
+ if (!\$this->isInTree())
+ {
+ throw new PropelException('An object must be already in the tree to be
moved. Use the insertAsPrevSiblingOf() instead.');
+ }
+
+ if (\$sibling->isRoot())
+ {
+ throw new PropelException('Cannot move to previous sibling of a root
node.');
+ }
+
+ if (\$sibling->isDescendantOf(\$this))
+ {
+ throw new PropelException('Cannot move a node as sibling of one of its
subtree nodes.');
+ }
+ */
+
+ \$this->moveSubtreeTo(\$sibling->rgt + 1, \$con);
+
+ return \$this;
+ }
+
+script;
+ }
+
+ protected function addMoveSubtreeTo(&$script)
+ {
+ $script .= <<<script
+
+ protected function moveSubtreeTo(\$destLeft, PropelPDO \$con = null)
+ {
+ \$left = \$this->lft;
+ \$right = \$this->rgt;
+
+ \$treeSize = \$right - \$left +1;
+
+ if (\$con === null)
+ {
+ \$con = Propel::getConnection();
+ }
+
+ \$con->beginTransaction();
+
+ try
+ {
+ // make room next to the target for the subtree
+ self::shiftRLValues(\$treeSize, \$destLeft, null, \$con);
+
+ if (\$left >= \$destLeft) // src was shifted too?
+ {
+ \$left += \$treeSize;
+ \$right += \$treeSize;
+ }
+
+ // move the subtree to the target
+ self::shiftRLValues(\$destLeft - \$left, \$left, \$right, \$con);
+
+ // remove the empty room at the previous location of the subtree
+ self::shiftRLValues(-\$treeSize, \$right + 1, null, \$con);
+
+ // update all loaded nodes
+ // self::updateLoadedNodes(null, \$con);
+
+ \$con->commit();
+ }
+ catch (PropelException \$e)
+ {
+ \$con->rollback();
+
+ throw \$e;
+ }
+ }
+
+script;
+ }
+
+ protected function addShiftRLValues(&$script)
+ {
+ $script .= <<<script
+
+ /**
+ * Adds \$delta to all L and R values that are >= \$first and <= \$last.
+ * '\$delta' can also be negative.
+ *
+ * @param int \$delta Value to be shifted by, can be negative
+ * @param int \$first First node to be shifted
+ * @param int \$last Last node to be shifted (optional)
+ * @param PropelPDO \$con Connection to use.
+ */
+ protected function shiftRLValues(\$delta, \$first, \$last = null, PropelPDO
\$con = null)
+ {
+ if (\$con === null)
+ {
+ \$con = Propel::getConnection();
+ }
+
+ // Shift left column values
+ \$whereCriteria = new Criteria;
+ \$criterion =
\$whereCriteria->getNewCriterion({$this->getColumnConstant($this->nestedSetLeftColumn)},
\$first, Criteria::GREATER_EQUAL);
+ if (null !== \$last)
+ {
+
\$criterion->addAnd(\$whereCriteria->getNewCriterion({$this->getColumnConstant($this->nestedSetLeftColumn)},
\$last, Criteria::LESS_EQUAL));
+ }
+ \$whereCriteria->add(\$criterion);
+
+ \$valuesCriteria = new Criteria;
+
\$valuesCriteria->add({$this->getColumnConstant($this->nestedSetLeftColumn)},
array('raw' => {$this->getColumnConstant($this->nestedSetLeftColumn)} . ' + ?',
'value' => \$delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);
+
+ // Shift right column values
+ \$whereCriteria = new Criteria;
+ \$criterion =
\$whereCriteria->getNewCriterion({$this->getColumnConstant($this->nestedSetRightColumn)},
\$first, Criteria::GREATER_EQUAL);
+ if (null !== \$last)
+ {
+
\$criterion->addAnd(\$whereCriteria->getNewCriterion({$this->getColumnConstant($this->nestedSetRightColumn)},
\$last, Criteria::LESS_EQUAL));
+ }
+ \$whereCriteria->add(\$criterion);
+
+ \$valuesCriteria = new Criteria;
+
\$valuesCriteria->add({$this->getColumnConstant($this->nestedSetRightColumn)},
array('raw' => {$this->getColumnConstant($this->nestedSetRightColumn)} . ' +
?', 'value' => \$delta), Criteria::CUSTOM_EQUAL);
+
+ BasePeer::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);
+ }
+
+script;
+ }
+
protected function addCall(&$script)
{
if (isset($this->inheritanceFk))
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.