fix
This commit is contained in:
@@ -339,17 +339,25 @@ public function filters(Request $request)
|
||||
}
|
||||
$caseSql .= "WHEN duration > {$this->durationOtherMin()} THEN '120-' END";
|
||||
|
||||
$durations = Media::select(
|
||||
DB::raw("{$caseSql} as duration_range"),
|
||||
DB::raw('COUNT(*) as total')
|
||||
)
|
||||
->where('duration', '>', 0) // every positive duration falls into a bucket
|
||||
// Counts only for buckets that currently have media.
|
||||
$counts = Media::query()
|
||||
->select(DB::raw("{$caseSql} as duration_range"), DB::raw('COUNT(*) as total'))
|
||||
->where('duration', '>', 0)
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
})
|
||||
->groupBy('duration_range')
|
||||
->get();
|
||||
->pluck('total', 'duration_range');
|
||||
|
||||
// Always return every range (the UI needs all of them), with 0 when empty.
|
||||
$durations = collect(array_keys($this->durationRanges()))
|
||||
->push('120-')
|
||||
->map(fn ($key) => [
|
||||
'duration_range' => $key,
|
||||
'total' => (int) ($counts[$key] ?? 0),
|
||||
])
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'categories' => $categories,
|
||||
|
||||
Reference in New Issue
Block a user