backlinks
This commit is contained in:
+23
-2
@@ -115,7 +115,6 @@ final class Query
|
||||
})->sortBy("rank")->values()->toArray();
|
||||
|
||||
|
||||
|
||||
return new Graph(
|
||||
new Collection($queryRecords),
|
||||
new Collection($queryEdges),
|
||||
@@ -145,19 +144,35 @@ final class Query
|
||||
{
|
||||
$query = DB::table("records");
|
||||
$query = $this->parseFilters($query);
|
||||
$query = $this->findNotLinked($query);
|
||||
if ($this->options->limit > 0) {
|
||||
$query->limit($this->options->limit);
|
||||
$query->offset($this->options->skip);
|
||||
}
|
||||
|
||||
$query = $this->orderByQuery($query);
|
||||
|
||||
return $query->get()->map(function ($r) {
|
||||
$r->isRoot = true;
|
||||
return $r;
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
|
||||
private function findNotLinked(Builder $query): Builder
|
||||
{
|
||||
if(empty($this->options->notLinked)){
|
||||
return $query;
|
||||
}
|
||||
|
||||
// This returns only records that have no parents
|
||||
$query
|
||||
->select("records.*")
|
||||
->join('edges', 'records.id', '=', 'edges.target', 'left outer')
|
||||
->whereNull("edges.target")
|
||||
;
|
||||
return $query;
|
||||
}
|
||||
|
||||
private
|
||||
function getChildren(array $ids): array
|
||||
{
|
||||
@@ -256,4 +271,10 @@ final class Query
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function notLinked(string $value): Query
|
||||
{
|
||||
$this->options->notLinked = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user