#45 sort orderitems aplhabetically in order view show #46

Merged
lubiana merged 2 commits from #45_sort-article-list into main 2024-08-14 17:45:19 +00:00
2 changed files with 15 additions and 5 deletions
Showing only changes of commit 25b73e7da5 - Show all commits

View file

@ -11,6 +11,8 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
use function iterator_to_array;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
class FoodOrder
{
@ -104,9 +106,10 @@ class FoodOrder
*/
public function getOrderItemsSortedByName(): Collection
{
$iterator = $this->getOrderItems()->getIterator();
$iterator = $this->getOrderItems()
->getIterator();
$iterator->uasort(
fn (OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
static fn(OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
);
return new ArrayCollection(
iterator_to_array(

View file

@ -58,36 +58,43 @@ final class FoodOrderControllerTest extends DbWebTest
{
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->persist($this->vendor);
$menuItemA = new MenuItem();
$menuItemA = new MenuItem;
$menuItemA->setName('A');
$menuItemA->setFoodVendor($this->vendor);
$this->manager->persist($menuItemA);
$itemA = new OrderItem;
$itemA->setMenuItem($menuItemA);
$itemA->setName($menuItemA->getName());
$order->addOrderItem($itemA);
$this->manager->persist($itemA);
$menuItemC = new MenuItem();
$menuItemC = new MenuItem;
$menuItemC->setName('C');
$menuItemC->setFoodVendor($this->vendor);
$this->manager->persist($menuItemC);
$itemC = new OrderItem;
$itemC->setMenuItem($menuItemC);
$itemC->setName($menuItemC->getName());
$order->addOrderItem($itemC);
$this->manager->persist($itemC);
$menuItemB = new MenuItem();
$menuItemB = new MenuItem;
$menuItemB->setName('B');
$menuItemB->setFoodVendor($this->vendor);
$this->manager->persist($menuItemB);
$itemB = new OrderItem;
$itemB->setMenuItem($menuItemB);
$itemB->setName($menuItemB->getName());
$order->addOrderItem($itemB);
$this->manager->persist($itemB);