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