#45 sort orderitems aplhabetically in order view show
All checks were successful
/ ls (pull_request) Successful in 35s

This commit is contained in:
lubiana 2024-08-14 19:41:04 +02:00
parent add3631376
commit 83989916a3
No known key found for this signature in database
3 changed files with 74 additions and 1 deletions

View file

@ -99,6 +99,22 @@ class FoodOrder
return $this->orderItems;
}
/**
* @return Collection<int, OrderItem>
*/
public function getOrderItemsSortedByName(): Collection
{
$iterator = $this->getOrderItems()->getIterator();
$iterator->uasort(
fn (OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
);
return new ArrayCollection(
iterator_to_array(
$iterator
)
);
}
public function addOrderItem(OrderItem $orderItem): static
{
if (! $this->orderItems->contains($orderItem)) {