Skip to content

Commit

Permalink
Fix visitor age group sorting in report
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcage committed Nov 16, 2023
1 parent 9fbe432 commit 6d1e6c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 5.3.1

* Fix visitor age group sorting in report

## 5.3.0

* Added new visitor gender, nationality, age distribution charts
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/Visitors/API/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function ageDistribution(Request $request): JsonResponse

[$startDate, $endDate] = $this->getDatePeriodFromRequest($request, defaultDays: null, dateStartField: 'date_start', dateEndField: 'date_end');

$ageDistribution = Visitor::query()
$data = Visitor::query()
->selectRaw('CASE
WHEN age <= 5 THEN "1-5"
WHEN age >= 6 AND age <= 11 THEN "6-11"
Expand All @@ -155,9 +155,10 @@ public function ageDistribution(Request $request): JsonResponse
}, 's')
->groupBy('age_group')
->orderBy('age_group')
->get();
->get()
->sortBy('age_group', SORT_NATURAL)->values();

return response()->json($ageDistribution
return response()->json($data
->map(fn ($e) => [
'label' => __($e->age_group),
'value' => $e->total_count,
Expand Down

0 comments on commit 6d1e6c9

Please sign in to comment.