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 070c5fc8..2f5ce75c 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -39,6 +39,7 @@ public function getAllParticipantsWithStatus( array $orders = [], bool $filterEmptyParticipants = false, ?int $limit = null, + bool $sortedByTroopOrPatrol = false, ): array { $qb = $this->createFluent(); @@ -87,6 +88,10 @@ public function getAllParticipantsWithStatus( $participants = $this->filterEmptyParticipants($participants); } + if ($sortedByTroopOrPatrol) { + $participants = $this->sortParticipantsBasedOnTroopOrPatrol($participants); + } + return $participants; } @@ -191,6 +196,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[]