fixed edges again

This commit is contained in:
2023-12-12 14:08:39 +02:00
parent ccbd1f6a5b
commit e024ed2c65
2 changed files with 17 additions and 7 deletions
+11 -4
View File
@@ -17,6 +17,7 @@ final class Graph
public Collection $records,
public Collection $edges,
public Collection $parentEdges,
public QueryOptions $queryOptions,
public ?int $total = null,
)
{
@@ -41,14 +42,18 @@ final class Graph
return $this->getRootRecords()
->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 && $ed->depth === $depth)
->unique(fn(Edge $ed) => $ed->targetSchema . $ed->field . $ed->target . $ed->source . $ed->depth)
if($this->queryOptions->childrenDepth < $depth){
return $record;
}
$recordEdges = $this->edges
->filter(fn(Edge $ed) => $ed->source === $record->id )
->unique(fn(Edge $ed) => $ed->targetSchema . $ed->field . $ed->target . $ed->source)
->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
$groupRecordEdges = [];
foreach ($recordEdges as $element) {
$groupRecordEdges[$element->field][] = $element;
@@ -73,7 +78,9 @@ final class Graph
public function findParents(QueryRecord $record, int $depth = 1): QueryRecord
{
if($this->queryOptions->parentsDepth < $depth){
return $record;
}
$recordEdges = $this->parentEdges->filter(fn(Edge $ed) => $ed->target === $record->id)->where("depth", $depth)->values()->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
$groupRecordEdges = [];