From e1c0eb2bc190f5caac5bb4a166b758e82d2ae400 Mon Sep 17 00:00:00 2001 From: paaton Date: Thu, 20 Jun 2024 20:20:48 +0200 Subject: [PATCH] "All data" and "Only paid" exports now sort participants based on their "patrol leader id", "troop leader id" or "id" in this order. --- src/Export/ExportService.php | 2 ++ src/Participant/ParticipantRepository.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Export/ExportService.php b/src/Export/ExportService.php index fe1ad214..4acc92c3 100755 --- a/src/Export/ExportService.php +++ b/src/Export/ExportService.php @@ -42,6 +42,7 @@ public function healthDataToCSV(Event $event, User $adminUser): array [UserStatus::Paid], $event, $adminUser, + sortedByTroopOrPatrol: true, ); $rows = []; @@ -153,6 +154,7 @@ public function allRegistrationDataToCSV(Event $event, User $adminUser): array [UserStatus::Closed, UserStatus::Approved, UserStatus::Paid], $event, $adminUser, + sortedByTroopOrPatrol: true, ); $rows = [[ diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index 03c6d045..9bca08e9 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -43,6 +43,7 @@ public function getAllParticipantsWithStatus( array $orders = [], bool $filterEmptyParticipants = false, ?int $limit = null, + bool $sortedByTroopOrPatrol = false, ): array { $qb = $this->createFluent(); @@ -91,6 +92,10 @@ public function getAllParticipantsWithStatus( $participants = $this->filterEmptyParticipants($participants); } + if ($sortedByTroopOrPatrol) { + $participants = $this->sortParticipantsBasedOnTroopOrPatrol($participants); + } + return $participants; } @@ -195,6 +200,16 @@ private function filterEmptyParticipants(array $participants): array ); } + /** + * @param Participant[] $participants + * @return Participant[] + */ + private function sortParticipantsBasedOnTroopOrPatrol(array $participants): array{ + usort($participants, + function ($a, $b) { return ($a->troopLeader ?? $a->patrolLeader ?? $a->id) - ($b->troopLeader ?? $b->patrolLeader ?? $b->id); }); + return $participants; + } + /** * @param string[] $contingents * @return StatisticUserValueObject[]