Author: sevein
Date: Tue Jul 10 14:38:14 2012
New Revision: 11886

Log:
Add extra nested methods to the ORM builder class (useful for the migration 
procedure)

Modified:
   trunk/lib/propel/builder/QubitObjectBuilder.php

Modified: trunk/lib/propel/builder/QubitObjectBuilder.php
==============================================================================
--- trunk/lib/propel/builder/QubitObjectBuilder.php     Tue Jul 10 14:37:09 
2012        (r11885)
+++ trunk/lib/propel/builder/QubitObjectBuilder.php     Tue Jul 10 14:38:14 
2012        (r11886)
@@ -259,6 +259,10 @@
       $this->addAddDescendantsCriteria($script);
       $this->addUpdateNestedSet($script);
       $this->addDeleteFromNestedSet($script);
+      $this->addIsInTree($script);
+      $this->addIsDescendantOf($script);
+      $this->addMoveToFirstChildOf($script);
+      $this->addMoveToLastChildOf($script);
       $this->addMoveToPrevSiblingOf($script);
       $this->addMoveToNextSiblingOf($script);
       $this->addMoveSubtreeTo($script);
@@ -2044,6 +2048,68 @@
 script;
   }
 
+  protected function addIsInTree(&$script)
+  {
+    $script .= <<<script
+
+  public function isInTree()
+  {
+    return \$this->lft > 0 && \$this->rgt > \$this->lft;
+  }
+
+script;
+  }
+
+  protected function addIsDescendantOf(&$script)
+  {
+    $script .= <<<script
+
+  public function isDescendantOf(\$parent)
+  {
+    return \$this->isInTree() && \$this->lft > \$parent->lft && \$this->rgt < 
\$parent->rgt;
+  }
+
+script;
+  }
+
+  protected function addMoveToFirstChildOf(&$script)
+  {
+    $script .= <<<script
+
+  public function moveToFirstChildOf(\$parent, PropelPDO \$con = null)
+  {
+    if (\$parent->isDescendantOf(\$this))
+    {
+      throw new PropelException('Cannot move a node as child of one of its 
subtree nodes.');
+    }
+
+    \$this->moveSubtreeTo(\$parent->lft + 1, \$con);
+
+    return \$this;
+  }
+
+script;
+  }
+
+  protected function addMoveToLastChildOf(&$script)
+  {
+    $script .= <<<script
+
+  public function moveToLastChildOf(\$parent, PropelPDO \$con = null)
+  {
+    if (\$parent->isDescendantOf(\$this))
+    {
+      throw new PropelException('Cannot move a node as child of one of its 
subtree nodes.');
+    }
+
+    \$this->moveSubtreeTo(\$parent->rgt, \$con);
+
+    return \$this;
+  }
+
+script;
+  }
+
   protected function addMoveToPrevSiblingOf(&$script)
   {
     $script .= <<<script

-- 
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.

Reply via email to