- public function searchPaginatedByType($type, $searchTerm, $page = 0, $pageSize = 24)
- {
- $images = $this->image->where('type', '=', strtolower($type))->where('name', 'LIKE', '%' . $searchTerm . '%');
- return $this->returnPaginated($images, $page, $pageSize);
+ public function getEntityFiltered(
+ string $type,
+ ?string $filterType,
+ int $page,
+ int $pageSize,
+ int $uploadedTo,
+ ?string $search
+ ): array {
+ $contextPage = $this->pageQueries->findVisibleByIdOrFail($uploadedTo);
+ $parentFilter = null;
+
+ if ($filterType === 'book' || $filterType === 'page') {
+ $parentFilter = function (Builder $query) use ($filterType, $contextPage) {
+ if ($filterType === 'page') {
+ $query->where('uploaded_to', '=', $contextPage->id);
+ } elseif ($filterType === 'book') {
+ $validPageIds = $contextPage->book->pages()
+ ->scopes('visible')
+ ->pluck('id')
+ ->toArray();
+ $query->whereIn('uploaded_to', $validPageIds);
+ }
+ };
+ }
+
+ return $this->getPaginatedByType($type, $page, $pageSize, null, $search, $parentFilter);