]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Queries/EntityQueries.php
Lexical: Updated tests for node changes
[bookstack] / app / Entities / Queries / EntityQueries.php
index 39a21c9138cb684fa644ed93a41cdd6faa6b34c3..36dc6c0bc8ac04b2408eaf6a9074b32b44f99dfd 100644 (file)
@@ -3,6 +3,8 @@
 namespace BookStack\Entities\Queries;
 
 use BookStack\Entities\Models\Entity;
+use Illuminate\Database\Eloquent\Builder;
+use InvalidArgumentException;
 
 class EntityQueries
 {
@@ -11,6 +13,7 @@ class EntityQueries
         public BookQueries $books,
         public ChapterQueries $chapters,
         public PageQueries $pages,
+        public PageRevisionQueries $revisions,
     ) {
     }
 
@@ -24,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,
@@ -35,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;
     }
 }