From 9003c572efd9403ffa2b7cae4dc8869d37b0a344 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 14 May 2026 12:50:41 +0200 Subject: [PATCH] Use same categories layout as in header search --- app/Providers/AppServiceProvider.php | 2 ++ .../Releases/ReleaseSearchService.php | 31 ++++++------------- resources/views/search/index.blade.php | 24 +++++++------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 37c071d7b..29c1ced03 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -49,12 +49,14 @@ class AppServiceProvider extends ServiceProvider // Share global data with layouts and all admin views // Admin child views need direct registration because @section blocks // are evaluated before the layout composer runs + // Same for search.* so category menu data (e.g. parentcatlist) exists in @section('content') view()->composer([ 'layouts.main', 'layouts.admin', 'layouts.guest', 'layouts.app', 'admin.*', + 'search.*', ], GlobalDataComposer::class); Gate::define('viewPulse', function (User $user) { diff --git a/app/Services/Releases/ReleaseSearchService.php b/app/Services/Releases/ReleaseSearchService.php index fe85b8777..1da60b1f1 100644 --- a/app/Services/Releases/ReleaseSearchService.php +++ b/app/Services/Releases/ReleaseSearchService.php @@ -66,6 +66,7 @@ class ReleaseSearchService Log::debug('ReleaseSearchService::search called', [ 'searchArr' => $searchArr, 'limit' => $limit, + 'type' => $type, ]); } @@ -89,9 +90,7 @@ class ReleaseSearchService } } - $categoryIdsRaw = $type === 'basic' - ? Category::getCategorySearch($cat, null, true) - : (((int) ($cat[0] ?? -1) !== -1) ? [(int) $cat[0]] : null); + $categoryIdsRaw = Category::getCategorySearch($cat, null, true); $categoryIds = null; if (is_array($categoryIdsRaw)) { @@ -176,7 +175,6 @@ class ReleaseSearchService $daysOld, $maxAge, $excludedCats, - $type, $cat, $minSize ); @@ -1723,7 +1721,6 @@ class ReleaseSearchService mixed $daysOld, int $maxAge, array $excludedCats, - string $type, array $cat, int $minSize ): string { @@ -1755,7 +1752,7 @@ class ReleaseSearchService } // Category conditions - only add if not empty - $catQuery = $this->buildCategoryCondition($type, $cat); + $catQuery = $this->buildCategoryCondition($cat); if (! empty($catQuery) && $catQuery !== '1=1') { $conditions[] = $catQuery; } @@ -1851,26 +1848,18 @@ class ReleaseSearchService } /** - * Build category condition based on search type + * Build category condition for web search (basic and advanced). * * @param array $cat Category IDs (list or associative) */ - private function buildCategoryCondition(string $type, array $cat): string + private function buildCategoryCondition(array $cat): string { - if ($type === 'basic') { - $catSearch = Category::getCategorySearch($cat); - // Remove WHERE and AND from the beginning as we're building it into a larger WHERE clause - $catSearch = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catSearch)); + $catSearch = Category::getCategorySearch($cat); + // Remove WHERE and AND from the beginning as we're building it into a larger WHERE clause + $catSearch = preg_replace('/^(WHERE|AND)\s+/i', '', trim((string) $catSearch)); - // Don't return '1=1' as it's not needed - return ($catSearch === '1=1') ? '' : $catSearch; - } - - if ($type === 'advanced' && (int) $cat[0] !== -1) { - return sprintf('r.categories_id = %d', (int) $cat[0]); - } - - return ''; + // Don't return '1=1' as it's not needed + return ($catSearch === '1=1') ? '' : $catSearch; } /** diff --git a/resources/views/search/index.blade.php b/resources/views/search/index.blade.php index 424cbd8a2..c7ef86968 100644 --- a/resources/views/search/index.blade.php +++ b/resources/views/search/index.blade.php @@ -59,20 +59,22 @@ @if(isset($parentcatlist)) @foreach($parentcatlist as $parentcat) @php + $parentId = is_object($parentcat) ? $parentcat->id : ($parentcat['id'] ?? ''); $parentTitle = is_object($parentcat) ? $parentcat->title : ($parentcat['title'] ?? 'Category'); $subcategories = is_object($parentcat) ? $parentcat->categories : ($parentcat['categories'] ?? []); @endphp - - @foreach($subcategories as $subcat) - @php - $subcatId = is_object($subcat) ? $subcat->id : ($subcat['id'] ?? ''); - $subcatTitle = is_object($subcat) ? $subcat->title : ($subcat['title'] ?? ''); - @endphp - - @endforeach - + + @foreach($subcategories as $subcat) + @php + $subcatId = is_object($subcat) ? $subcat->id : ($subcat['id'] ?? ''); + $subcatTitle = is_object($subcat) ? $subcat->title : ($subcat['title'] ?? ''); + @endphp + + @endforeach @endforeach @elseif(isset($catlist)) @foreach($catlist as $catId => $catTitle)