Author: dr
Date: Tue Aug  7 09:52:15 2007
New Revision: 5824

Log:
- Optimized the isDecendentOf() and getPathLength() methods of
  ezcTreeDbNestedSet.

Modified:
    trunk/Tree/src/backends/db_nested_set.php

Modified: trunk/Tree/src/backends/db_nested_set.php
==============================================================================
--- trunk/Tree/src/backends/db_nested_set.php [iso-8859-1] (original)
+++ trunk/Tree/src/backends/db_nested_set.php [iso-8859-1] Tue Aug  7 09:52:15 
2007
@@ -139,16 +139,8 @@
      */
     public function getPathLength( $id )
     {
-        // TODO
-        $id = $this->getParentId( $id );
-        $length = 0;
-
-        while ( $id !== null )
-        {
-            $id = $this->getParentId( $id );
-            $length++;
-        }
-        return $length;
+        $path = $this->fetchPath( $id );
+        return count( $path->getNodes() ) - 1;
     }
 
     /**
@@ -161,17 +153,12 @@
      */
     public function isDecendantOf( $childId, $parentId )
     {
-        // TODO
-        $parentId = (string) $parentId;
-        $id = $childId;
-        do
-        {
-            $id = $this->getParentId( $id );
-            if ( $parentId === $id )
-            {
-                return true;
-            }
-        } while ( $id !== null );
+        $path = $this->fetchPath( $childId );
+
+        if ( isset( $path[$parentId] ) && ( $childId !== $parentId ) )
+        {
+            return true;
+        }
         return false;
     }
 


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to