This commit is contained in:
Jonas 2024-02-17 12:30:54 +01:00
parent d30bb74cc5
commit 9e804c6113
6 changed files with 30 additions and 49 deletions

View file

@ -6,6 +6,7 @@ use App\Entity\FoodOrder;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use App\Entity\OrderItem; use App\Entity\OrderItem;
use App\Form\OrderItemType; use App\Form\OrderItemType;
use App\Repository\ItemExtraRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -60,6 +61,7 @@ class FoodOrderController extends AbstractController
FoodOrder $foodOrder, FoodOrder $foodOrder,
MenuItem $menuItem, MenuItem $menuItem,
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
ItemExtraRepository $extraRepository,
Request $request, Request $request,
): Response { ): Response {
$orderItem = new OrderItem; $orderItem = new OrderItem;
@ -86,8 +88,10 @@ class FoodOrderController extends AbstractController
); );
} }
return $this->render('food_order/orderitem.html.twig', [ return $this->render('food_order/orderitem.html.twig', [
'form' => $form, 'form' => $form,
'extras' => $extraRepository->getUniqueNames(),
]); ]);
} }

View file

@ -128,25 +128,8 @@ class FoodOrder
return $this; return $this;
} }
public function groupedOrderItems(): array public function groupedOrderItems(): Collection
{ {
return $this->orderItems->reduce( return $this->getOrderItems();
static function (array $carry, OrderItem $item): array {
$menuItemStringId = (string) $item->getMenuItem()
->getId();
if (isset($carry[$menuItemStringId])) {
$carry[$menuItemStringId]['amount']++;
} else {
$carry[$menuItemStringId] = [
'item' => $item,
'amount' => 1,
];
}
return $carry;
},
[],
);
} }
} }

View file

@ -8,6 +8,7 @@ use App\Entity\OrderItem;
use Override; use Override;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -31,6 +32,11 @@ class OrderItemType extends AbstractType
'expanded' => true, 'expanded' => true,
], ],
); );
$builder->add('customextra', TextType::class, [
'label' => 'Not yet know extras, seperated by comma',
'mapped' => false,
'attr' => ['datalist' => 'item-extra-list'],
]);
} }
#[Override] #[Override]

View file

@ -4,6 +4,8 @@ namespace App\Repository;
use App\Entity\ItemExtra; use App\Entity\ItemExtra;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
/** /**
@ -21,27 +23,12 @@ class ItemExtraRepository extends ServiceEntityRepository
parent::__construct($registry, ItemExtra::class); parent::__construct($registry, ItemExtra::class);
} }
// /** public function getUniqueNames(): Collection
// * @return ItemExtra[] Returns an array of ItemExtra objects {
// */ $qb = $this->createQueryBuilder('p');
// public function findByExampleField($value): array
// { $qb->groupBy('p.name');
// return $this->createQueryBuilder('i')
// ->andWhere('i.exampleField = :val') return new ArrayCollection($qb->getQuery()->getResult());
// ->setParameter('val', $value) }
// ->orderBy('i.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?ItemExtra
// {
// return $this->createQueryBuilder('i')
// ->andWhere('i.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
} }

View file

@ -2,5 +2,10 @@
{% block body %} {% block body %}
{{ include('_form.html.twig') }} {{ include('_form.html.twig') }}
<datalist id="item-extra-list">
{% for item in extras %}
<option value="{{ item.name }}"></option>
{% endfor %}
</datalist>
{% endblock %} {% endblock %}

View file

@ -44,19 +44,15 @@
{% for orderItem in food_order.groupedOrderItems %} {% for orderItem in food_order.groupedOrderItems %}
<tr> <tr>
<td> <td>
{{ orderItem.item.menuItem.menuItemAliases|map(i => i.name)|join(' / ') }} {{ orderItem.menuItem.menuItemAliases|map(i => i.name)|join(' / ') }}
</td> </td>
<td> <td>
{{ orderItem.item.extras|map(i => i.name)|join(' / ') }} {{ orderItem.extras|map(i => i.name)|join(' / ') }}
</td> </td>
<td> <td>
{{ orderItem.item.menuItem.price|cents_to_eur }} {{ orderItem.menuItem.price|cents_to_eur }}
</td> </td>
<td> <td>
{{ orderItem.amount }} |
<a href="{{ path('app_foodorder_add_item', {foodOrder: food_order.id, menuItem: orderItem.item.menuItem.id}) }}">+1</a> |
<a href="{{ path('app_foodorder_remove_item', {foodOrder: food_order.id, orderItem: orderItem.item.id}) }}">-1</a> |
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}