fix depth

This commit is contained in:
2023-12-08 20:11:18 +02:00
parent ce587387c5
commit ccbd1f6a5b
+4 -6
View File
@@ -39,17 +39,15 @@ final class Graph
public function tree(): Collection public function tree(): Collection
{ {
return $this->getRootRecords() return $this->getRootRecords()
->map([$this, 'findParents']) ->map(fn($r) => $this->findParents($r))
->map([$this, 'findChildren']) ->map(fn($r) => $this->findChildren($r));
;
} }
public function findChildren(QueryRecord $record, int $depth = 1): QueryRecord public function findChildren(QueryRecord $record, int $depth = 1): QueryRecord
{ {
$recordEdges = $this->edges->filter(fn(Edge $ed) => $ed->source === $record->id) $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) ->unique(fn(Edge $ed) => $ed->targetSchema . $ed->field . $ed->target . $ed->source . $ed->depth)
->where("depth", $depth) ->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
->values()->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
$groupRecordEdges = []; $groupRecordEdges = [];
foreach ($recordEdges as $element) { foreach ($recordEdges as $element) {