fix depth
This commit is contained in:
+6
-8
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user