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 Aug 6, 2024
1 parent 6d6e1bd commit e1c0eb2
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 @@ -43,6 +43,7 @@ public function getAllParticipantsWithStatus(
array $orders = [],
bool $filterEmptyParticipants = false,
?int $limit = null,
bool $sortedByTroopOrPatrol = false,
): array {
$qb = $this->createFluent();

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

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

return $participants;
}

Expand Down Expand Up @@ -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); });

Check failure on line 209 in src/Participant/ParticipantRepository.php

View workflow job for this annotation

GitHub Actions / test / Static Analysis

Missing parameter typehint for closure parameter $a.

Check failure on line 209 in src/Participant/ParticipantRepository.php

View workflow job for this annotation

GitHub Actions / test / Static Analysis

Missing parameter typehint for closure parameter $b.

Check failure on line 209 in src/Participant/ParticipantRepository.php

View workflow job for this annotation

GitHub Actions / test / Static Analysis

Using - over non-number (mixed - mixed)
return $participants;
}

/**
* @param string[] $contingents
* @return StatisticUserValueObject[]
Expand Down

0 comments on commit e1c0eb2

Please sign in to comment.