Use same categories layout as in header search

This commit is contained in:
DariusIII
2026-05-14 12:50:41 +02:00
parent bd9aa517d3
commit 9003c572ef
3 changed files with 25 additions and 32 deletions
+2
View File
@@ -49,12 +49,14 @@ class AppServiceProvider extends ServiceProvider
// Share global data with layouts and all admin views // Share global data with layouts and all admin views
// Admin child views need direct registration because @section blocks // Admin child views need direct registration because @section blocks
// are evaluated before the layout composer runs // are evaluated before the layout composer runs
// Same for search.* so category menu data (e.g. parentcatlist) exists in @section('content')
view()->composer([ view()->composer([
'layouts.main', 'layouts.main',
'layouts.admin', 'layouts.admin',
'layouts.guest', 'layouts.guest',
'layouts.app', 'layouts.app',
'admin.*', 'admin.*',
'search.*',
], GlobalDataComposer::class); ], GlobalDataComposer::class);
Gate::define('viewPulse', function (User $user) { Gate::define('viewPulse', function (User $user) {
+10 -21
View File
@@ -66,6 +66,7 @@ class ReleaseSearchService
Log::debug('ReleaseSearchService::search called', [ Log::debug('ReleaseSearchService::search called', [
'searchArr' => $searchArr, 'searchArr' => $searchArr,
'limit' => $limit, 'limit' => $limit,
'type' => $type,
]); ]);
} }
@@ -89,9 +90,7 @@ class ReleaseSearchService
} }
} }
$categoryIdsRaw = $type === 'basic' $categoryIdsRaw = Category::getCategorySearch($cat, null, true);
? Category::getCategorySearch($cat, null, true)
: (((int) ($cat[0] ?? -1) !== -1) ? [(int) $cat[0]] : null);
$categoryIds = null; $categoryIds = null;
if (is_array($categoryIdsRaw)) { if (is_array($categoryIdsRaw)) {
@@ -176,7 +175,6 @@ class ReleaseSearchService
$daysOld, $daysOld,
$maxAge, $maxAge,
$excludedCats, $excludedCats,
$type,
$cat, $cat,
$minSize $minSize
); );
@@ -1723,7 +1721,6 @@ class ReleaseSearchService
mixed $daysOld, mixed $daysOld,
int $maxAge, int $maxAge,
array $excludedCats, array $excludedCats,
string $type,
array $cat, array $cat,
int $minSize int $minSize
): string { ): string {
@@ -1755,7 +1752,7 @@ class ReleaseSearchService
} }
// Category conditions - only add if not empty // Category conditions - only add if not empty
$catQuery = $this->buildCategoryCondition($type, $cat); $catQuery = $this->buildCategoryCondition($cat);
if (! empty($catQuery) && $catQuery !== '1=1') { if (! empty($catQuery) && $catQuery !== '1=1') {
$conditions[] = $catQuery; $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<int|string, mixed> $cat Category IDs (list or associative) * @param array<int|string, mixed> $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);
$catSearch = Category::getCategorySearch($cat); // Remove WHERE and AND from the beginning as we're building it into a larger WHERE clause
// 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));
$catSearch = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catSearch));
// Don't return '1=1' as it's not needed // Don't return '1=1' as it's not needed
return ($catSearch === '1=1') ? '' : $catSearch; return ($catSearch === '1=1') ? '' : $catSearch;
}
if ($type === 'advanced' && (int) $cat[0] !== -1) {
return sprintf('r.categories_id = %d', (int) $cat[0]);
}
return '';
} }
/** /**
+13 -11
View File
@@ -59,20 +59,22 @@
@if(isset($parentcatlist)) @if(isset($parentcatlist))
@foreach($parentcatlist as $parentcat) @foreach($parentcatlist as $parentcat)
@php @php
$parentId = is_object($parentcat) ? $parentcat->id : ($parentcat['id'] ?? '');
$parentTitle = is_object($parentcat) ? $parentcat->title : ($parentcat['title'] ?? 'Category'); $parentTitle = is_object($parentcat) ? $parentcat->title : ($parentcat['title'] ?? 'Category');
$subcategories = is_object($parentcat) ? $parentcat->categories : ($parentcat['categories'] ?? []); $subcategories = is_object($parentcat) ? $parentcat->categories : ($parentcat['categories'] ?? []);
@endphp @endphp
<optgroup label="{{ $parentTitle }}"> <option value="{{ $parentId }}" class="font-semibold" {{ request('t') == $parentId ? 'selected' : '' }}>
@foreach($subcategories as $subcat) {{ $parentTitle }}
@php </option>
$subcatId = is_object($subcat) ? $subcat->id : ($subcat['id'] ?? ''); @foreach($subcategories as $subcat)
$subcatTitle = is_object($subcat) ? $subcat->title : ($subcat['title'] ?? ''); @php
@endphp $subcatId = is_object($subcat) ? $subcat->id : ($subcat['id'] ?? '');
<option value="{{ $subcatId }}" {{ request('t') == $subcatId ? 'selected' : '' }}> $subcatTitle = is_object($subcat) ? $subcat->title : ($subcat['title'] ?? '');
{{ $subcatTitle }} @endphp
</option> <option value="{{ $subcatId }}" {{ request('t') == $subcatId ? 'selected' : '' }}>
@endforeach &nbsp;&nbsp;{{ $subcatTitle }}
</optgroup> </option>
@endforeach
@endforeach @endforeach
@elseif(isset($catlist)) @elseif(isset($catlist))
@foreach($catlist as $catId => $catTitle) @foreach($catlist as $catId => $catTitle)