feat: sort groups price services by price first, then alphabetically
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user