Browse Source

fixed childrenhierarchy function that returns proper array

Orgil 13 years ago
parent
commit
80a46a7e9d
1 changed files with 14 additions and 4 deletions
  1. 14 4
      lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php

+ 14 - 4
lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php

@@ -271,7 +271,17 @@ class NestedTreeRepository extends AbstractTreeRepository
         }
         if (!$sortByField) {
             $qb->orderBy('node.' . $config['left'], 'ASC');
-        } else {
+        }
+        elseif (is_array($sortByField)) {
+            $fields = '';
+            foreach ($sortByField as $field)
+            {
+                $fields .= 'node.'.$field.',';
+            }
+            $fields=rtrim($fields,',');
+            $qb->orderBy($fields,$direction);
+        }
+        else {
             if ($meta->hasField($sortByField) && in_array(strtolower($direction), array('asc', 'desc'))) {
                 $qb->orderBy('node.' . $sortByField, $direction);
             } else {
@@ -286,7 +296,7 @@ class NestedTreeRepository extends AbstractTreeRepository
      *
      * @param object $node - if null, all tree nodes will be taken
      * @param boolean $direct - true to take only direct children
-     * @param string $sortByField - field name to sort by
+     * @param string|array $sortByField - field names to sort by
      * @param string $direction - sort direction : "ASC" or "DESC"
      * @return Doctrine\ORM\Query
      */
@@ -799,11 +809,11 @@ class NestedTreeRepository extends AbstractTreeRepository
         }
 
         // Gets the array of $node results.
-        // It must be order by 'root' field
+        // It must be order by 'root' and 'left' field
         $nodes = self::childrenQuery(
             $node,
             $direct,
-            isset($config['root']) ? $config['root'] : $config['left'],
+            array($config['root'],$config['left']),
             'ASC'
         )->getArrayResult();