Skip to content

Commit c9782cf

Browse files
Christoph WeygandChristoph Weygand
authored andcommitted
Allow multiple order critieria in NestedTreeRepository::reorder and NestedTreeRepository:reorderAll
1 parent ade7387 commit c9782cf

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/Tree/Entity/Repository/NestedTreeRepository.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,11 @@ public function removeFromTree($node)
801801
* Reorders $node's child nodes,
802802
* according to the $sortByField and $direction specified
803803
*
804-
* @param object|null $node node from which to start reordering the tree; null will reorder everything
805-
* @param string $sortByField field name to sort by
806-
* @param string $direction sort direction : "ASC" or "DESC"
807-
* @param bool $verify true to verify tree first
808-
* @param bool $recursive true to also reorder further descendants, not just the direct children
804+
* @param object|null $node node from which to start reordering the tree; null will reorder everything
805+
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
806+
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
807+
* @param bool $verify true to verify tree first
808+
* @param bool $recursive true to also reorder further descendants, not just the direct children
809809
*
810810
* @return void
811811
*/
@@ -836,9 +836,9 @@ public function reorder($node, $sortByField = null, $direction = 'ASC', $verify
836836
/**
837837
* Reorders all nodes in the tree according to the $sortByField and $direction specified.
838838
*
839-
* @param string $sortByField field name to sort by
840-
* @param string $direction sort direction : "ASC" or "DESC"
841-
* @param bool $verify true to verify tree first
839+
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
840+
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
841+
* @param bool $verify true to verify tree first
842842
*
843843
* @return void
844844
*/

tests/Gedmo/Tree/NestedTreeRootRepositoryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,31 @@ public function testShouldHandleAdvancedRepositoryFunctions(): void
420420
static::assertSame(9, $node->getLeft());
421421
static::assertSame(10, $node->getRight());
422422

423+
// reorder (multiple order critieria)
424+
425+
$node = $repo->findOneBy(['title' => 'Vegitables']);
426+
$repo->reorder($node, ['level', 'title'], ['ASC', 'DESC'], false, false);
427+
428+
$node = $repo->findOneBy(['title' => 'Cabbages']);
429+
430+
static::assertSame(9, $node->getLeft());
431+
static::assertSame(10, $node->getRight());
432+
433+
$node = $repo->findOneBy(['title' => 'Carrots']);
434+
435+
static::assertSame(7, $node->getLeft());
436+
static::assertSame(8, $node->getRight());
437+
438+
$node = $repo->findOneBy(['title' => 'Onions']);
439+
440+
static::assertSame(5, $node->getLeft());
441+
static::assertSame(6, $node->getRight());
442+
443+
$node = $repo->findOneBy(['title' => 'Potatoes']);
444+
445+
static::assertSame(3, $node->getLeft());
446+
static::assertSame(4, $node->getRight());
447+
423448
// reorder
424449

425450
$node = $repo->findOneBy(['title' => 'Food']);

0 commit comments

Comments
 (0)