From ccbd1f6a5bf8f88f3aa7758f7bea022cf6b03639 Mon Sep 17 00:00:00 2001 From: lexx Date: Fri, 8 Dec 2023 20:11:18 +0200 Subject: [PATCH] fix depth --- src/Query/Graph.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Query/Graph.php b/src/Query/Graph.php index 96b66c4..73a562c 100644 --- a/src/Query/Graph.php +++ b/src/Query/Graph.php @@ -39,17 +39,15 @@ final class Graph public function tree(): Collection { return $this->getRootRecords() - ->map([$this, 'findParents']) - ->map([$this, 'findChildren']) - ; + ->map(fn($r) => $this->findParents($r)) + ->map(fn($r) => $this->findChildren($r)); } public function findChildren(QueryRecord $record, int $depth = 1): QueryRecord { - $recordEdges = $this->edges->filter(fn(Edge $ed) => $ed->source === $record->id) - ->unique(fn(Edge $ed) => $ed->targetSchema.$ed->field.$ed->target.$ed->source.$ed->depth) - ->where("depth", $depth) - ->values()->sort(fn($a, $b) => $a->rank <=> $b->rank)->values(); + $recordEdges = $this->edges->filter(fn(Edge $ed) => $ed->source === $record->id && $ed->depth === $depth) + ->unique(fn(Edge $ed) => $ed->targetSchema . $ed->field . $ed->target . $ed->source . $ed->depth) + ->sort(fn($a, $b) => $a->rank <=> $b->rank)->values(); $groupRecordEdges = []; foreach ($recordEdges as $element) { @@ -92,7 +90,7 @@ final class Graph continue; } - $parents[$field][] = $this->findParents($aRecord[0],$depth + 1); + $parents[$field][] = $this->findParents($aRecord[0], $depth + 1); } } $record->_parents = $parents;