Przeglądaj źródła

Merge pull request #487 from ethanresnick/patch-1

Support Reordering the Whole Tree
Gediminas Morkevicius 12 lat temu
rodzic
commit
473210190c

+ 16 - 3
lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php

@@ -717,10 +717,10 @@ class NestedTreeRepository extends AbstractTreeRepository
     }
 
     /**
-     * Reorders the sibling nodes and child nodes by given $node,
+     * Reorders $node's sibling nodes and child nodes,
      * according to the $sortByField and $direction specified
      *
-     * @param object $node - from which node to start reordering the tree
+     * @param object|null $node - node from which to start reordering the tree; null will reorder everything
      * @param string $sortByField - field name to sort by
      * @param string $direction - sort direction : "ASC" or "DESC"
      * @param boolean $verify - true to verify tree first
@@ -729,7 +729,7 @@ class NestedTreeRepository extends AbstractTreeRepository
     public function reorder($node, $sortByField = null, $direction = 'ASC', $verify = true)
     {
         $meta = $this->getClassMetadata();
-        if ($node instanceof $meta->name) {
+        if ($node instanceof $meta->name || $node==null) {
             $config = $this->listener->getConfiguration($this->_em, $meta->name);
             if ($verify && is_array($this->verify())) {
                 return false;
@@ -750,6 +750,19 @@ class NestedTreeRepository extends AbstractTreeRepository
         }
     }
 
+    /**
+     * Reorders all nodes in the tree according to the $sortByField and $direction specified.
+     *
+     * @param string $sortByField - field name to sort by
+     * @param string $direction - sort direction : "ASC" or "DESC"
+     * @param boolean $verify - true to verify tree first
+     * @return void
+     */
+    public function reorderAll($sortByField = null, $direction = 'ASC', $verify = true)
+    {
+        $this->reorder(null, $sortByField, $direction, $verify);
+    }
+
     /**
      * Verifies that current tree is valid.
      * If any error is detected it will return an array