backlinks

This commit is contained in:
2024-08-16 17:38:26 +03:00
parent 9bbd53b586
commit 5a13ddb2ec
20 changed files with 60 additions and 851 deletions
+1
View File
@@ -64,6 +64,7 @@ class RecordController extends Controller
$graphArray = null;
$graph = $this->query
->filter($arguments)
->notLinked($request->input("notlinked") ?? "")
->limit($limit)
->status(explode(",", $arguments["status_in"]))
->skip($skip)
+23 -2
View File
@@ -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;
}
}
+2 -1
View File
@@ -16,7 +16,8 @@ final class QueryOptions
public array $childrenFields = [],
public array $parentFields = [],
public array $sort = [],
public array $status = ["published", "draft"]
public array $status = ["published", "draft"],
public string $notLinked = ""
)
{