Prechádzať zdrojové kódy

[Tree] Added buildTree method to Materialized Path strategy (ORM)

comfortablynumb 13 rokov pred
rodič
commit
02edb412f3

+ 1 - 17
lib/Gedmo/Tree/Entity/Repository/MaterializedPathRepository.php

@@ -153,23 +153,7 @@ class MaterializedPathRepository extends AbstractTreeRepository
      */
     public function getNodesHierarchy($node, $direct, array $config, array $options = array())
     {
-        throw new FeatureNotImplementedException('You can\'t build an array with the tree structure for this strategy yet.');
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function buildTree(array $nodes, array $options = array())
-    {
-        throw new FeatureNotImplementedException('You can\'t build an array with the tree structure for this strategy yet.');
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function childrenHierarchy($node = null, $direct = false, array $options = array())
-    {
-        throw new FeatureNotImplementedException('You can\'t build an array with the tree structure for this strategy yet.');
+        return $this->getChildrenQuery()->getArrayResult();
     }
 
     /**

+ 16 - 0
tests/Gedmo/Tree/MaterializedPathORMRepositoryTest.php

@@ -101,6 +101,22 @@ class MaterializedPathORMRepositoryTest extends BaseTestCaseORM
         $this->assertEquals('Sports', $tree[5]->getTitle());
     }
 
+    public function testBuildTreeMethod()
+    {
+        $repo = $this->em->getRepository(self::CATEGORY);
+        $roots = $repo->getRootNodes();
+        $tree = $repo->childrenHierarchy($roots[0]);
+
+        $vegitables = $tree[0]['__children'][1];
+
+        $this->assertEquals('Food', $tree[0]['title']);
+        $this->assertEquals('Fruits', $tree[0]['__children'][0]['title']);
+        $this->assertEquals('Vegitables', $tree[0]['__children'][1]['title']);
+        $this->assertEquals('Carrots', $vegitables['__children'][0]['title']);
+        $this->assertEquals('Potatoes', $vegitables['__children'][1]['title']);
+        $this->assertEquals('Sports', $tree[1]['title']);
+    }
+
     protected function getUsedEntityFixtures()
     {
         return array(