feat: sort groups price services by price first, then alphabetically

This commit is contained in:
Björn Fromme
2026-08-03 16:23:47 +02:00
parent 9d2aa11fdb
commit 0b21bb00cb
4 changed files with 55 additions and 5 deletions
@@ -156,6 +156,12 @@ class AccommodationBookingService
}
}
$boardServices = $this->sortServicesByPriceThenLabel($boardServices);
$ungrouped = $this->sortServicesByPriceThenLabel($ungrouped);
foreach ($grouped as $groupName => $groupServices) {
$grouped[$groupName] = $this->sortServicesByPriceThenLabel($groupServices);
}
return [
'boardServices' => $boardServices,
'additionalServices' => $additionalServices,
@@ -164,6 +170,27 @@ class AccommodationBookingService
];
}
/**
* Free services (price 0) first, then alphabetically; each group sorted alphabetically.
*
* @template T of BoardService|AdditionalService
*
* @param T[] $services
*
* @return T[]
*/
private function sortServicesByPriceThenLabel(array $services): array
{
usort($services, static function (BoardService|AdditionalService $a, BoardService|AdditionalService $b): int {
$aFree = 0 === $a->getPrice() ? 0 : 1;
$bFree = 0 === $b->getPrice() ? 0 : 1;
return $aFree <=> $bFree ?: strnatcasecmp($a->getLabel(), $b->getLabel());
});
return $services;
}
/**
* Determines whether the booking must be treated as non-binding and why.
*