Skip to content

Commit

Permalink
"All data" and "Only paid" exports now sort participants based on the…
Browse files Browse the repository at this point in the history
…ir "patrol leader id", "troop leader id" or "id" in this order.
  • Loading branch information
paaton authored and Lung committed Jul 1, 2024
1 parent d5241c3 commit f846e75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Export/ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function healthDataToCSV(Event $event, User $adminUser): array
[UserStatus::Paid],
$event,
$adminUser,
sortedByTroopOrPatrol: true,
);

$rows = [];
Expand Down Expand Up @@ -153,6 +154,7 @@ public function allRegistrationDataToCSV(Event $event, User $adminUser): array
[UserStatus::Closed, UserStatus::Approved, UserStatus::Paid],
$event,
$adminUser,
sortedByTroopOrPatrol: true,
);

$rows = [[
Expand Down
15 changes: 15 additions & 0 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getAllParticipantsWithStatus(
array $orders = [],
bool $filterEmptyParticipants = false,
?int $limit = null,
bool $sortedByTroopOrPatrol = false,
): array {
$qb = $this->createFluent();

Expand Down Expand Up @@ -87,6 +88,10 @@ public function getAllParticipantsWithStatus(
$participants = $this->filterEmptyParticipants($participants);
}

if ($sortedByTroopOrPatrol) {
$participants = $this->sortParticipantsBasedOnTroopOrPatrol($participants);
}

return $participants;
}

Expand Down Expand Up @@ -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[]
Expand Down

0 comments on commit f846e75

Please sign in to comment.