1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00

Queries: Moved out or removed some class-level items

Also ran auto-removal of unused imports across app folder.
This commit is contained in:
Dan Brown
2024-02-07 22:41:45 +00:00
parent 546cfb0dcc
commit b77ab6f3af
29 changed files with 85 additions and 107 deletions

View File

@@ -3,6 +3,8 @@
namespace BookStack\Entities\Queries;
use BookStack\Entities\Models\Entity;
use Illuminate\Database\Eloquent\Builder;
use InvalidArgumentException;
class EntityQueries
{
@@ -25,9 +27,25 @@ class EntityQueries
$explodedId = explode(':', $identifier);
$entityType = $explodedId[0];
$entityId = intval($explodedId[1]);
$queries = $this->getQueriesForType($entityType);
return $queries->findVisibleById($entityId);
}
/**
* Start a query of visible entities of the given type,
* suitable for listing display.
*/
public function visibleForList(string $entityType): Builder
{
$queries = $this->getQueriesForType($entityType);
return $queries->visibleForList();
}
protected function getQueriesForType(string $type): ProvidesEntityQueries
{
/** @var ?ProvidesEntityQueries $queries */
$queries = match ($entityType) {
$queries = match ($type) {
'page' => $this->pages,
'chapter' => $this->chapters,
'book' => $this->books,
@@ -36,9 +54,9 @@ class EntityQueries
};
if (is_null($queries)) {
return null;
throw new InvalidArgumentException("No entity query class configured for {$type}");
}
return $queries->findVisibleById($entityId);
return $queries;
}
}