Skip to content

Commit

Permalink
Sort teams on clarification for by identifier.
Browse files Browse the repository at this point in the history
As requested by @baierjan.
  • Loading branch information
nickygerritsen committed Mar 24, 2024
1 parent e391fd5 commit a41efab
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions webapp/src/Form/Type/JuryClarificationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
} else {
/** @var Team|null $limitToTeam */
$teams = $this->em->getRepository(Team::class)->findAll();

// Sort teams by identifier
usort($teams, function (Team $a, Team $b) {
return strnatcmp($this->getTeamIdentifier($a), $this->getTeamIdentifier($b));
});

foreach ($teams as $team) {
$recipientOptions[$this->getTeamLabel($team)] = $team->getTeamid();
}
Expand Down Expand Up @@ -114,15 +120,20 @@ public function configureOptions(OptionsResolver $resolver): void
}

private function getTeamLabel(Team $team): string
{
return sprintf('%s (%s)', $team->getEffectiveName(), $this->getTeamIdentifier($team));
}

private function getTeamIdentifier(Team $team): string
{
if ($team->getLabel()) {
return sprintf('%s (%s)', $team->getEffectiveName(), $team->getLabel());
return $team->getLabel();
}

if ($this->eventLogService->externalIdFieldForEntity($team)) {
return sprintf('%s (%s)', $team->getEffectiveName(), $team->getExternalId());
return $team->getExternalId();
}

return sprintf('%s (t%s)', $team->getEffectiveName(), $team->getTeamid());
return (string)$team->getTeamid();
}
}

0 comments on commit a41efab

Please sign in to comment.