yolo
This commit is contained in:
parent
d30bb74cc5
commit
9e804c6113
6 changed files with 30 additions and 49 deletions
|
@ -6,6 +6,7 @@ use App\Entity\FoodOrder;
|
|||
use App\Entity\MenuItem;
|
||||
use App\Entity\OrderItem;
|
||||
use App\Form\OrderItemType;
|
||||
use App\Repository\ItemExtraRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -60,6 +61,7 @@ class FoodOrderController extends AbstractController
|
|||
FoodOrder $foodOrder,
|
||||
MenuItem $menuItem,
|
||||
EntityManagerInterface $entityManager,
|
||||
ItemExtraRepository $extraRepository,
|
||||
Request $request,
|
||||
): Response {
|
||||
$orderItem = new OrderItem;
|
||||
|
@ -86,8 +88,10 @@ class FoodOrderController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
return $this->render('food_order/orderitem.html.twig', [
|
||||
'form' => $form,
|
||||
'extras' => $extraRepository->getUniqueNames(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -128,25 +128,8 @@ class FoodOrder
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function groupedOrderItems(): array
|
||||
public function groupedOrderItems(): Collection
|
||||
{
|
||||
return $this->orderItems->reduce(
|
||||
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;
|
||||
},
|
||||
[],
|
||||
);
|
||||
return $this->getOrderItems();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Entity\OrderItem;
|
|||
use Override;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
|
@ -31,6 +32,11 @@ class OrderItemType extends AbstractType
|
|||
'expanded' => true,
|
||||
],
|
||||
);
|
||||
$builder->add('customextra', TextType::class, [
|
||||
'label' => 'Not yet know extras, seperated by comma',
|
||||
'mapped' => false,
|
||||
'attr' => ['datalist' => 'item-extra-list'],
|
||||
]);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace App\Repository;
|
|||
|
||||
use App\Entity\ItemExtra;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
|
@ -21,27 +23,12 @@ class ItemExtraRepository extends ServiceEntityRepository
|
|||
parent::__construct($registry, ItemExtra::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return ItemExtra[] Returns an array of ItemExtra objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('i')
|
||||
// ->andWhere('i.exampleField = :val')
|
||||
// ->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()
|
||||
// ;
|
||||
// }
|
||||
public function getUniqueNames(): Collection
|
||||
{
|
||||
$qb = $this->createQueryBuilder('p');
|
||||
|
||||
$qb->groupBy('p.name');
|
||||
|
||||
return new ArrayCollection($qb->getQuery()->getResult());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,10 @@
|
|||
|
||||
{% block body %}
|
||||
{{ include('_form.html.twig') }}
|
||||
<datalist id="item-extra-list">
|
||||
{% for item in extras %}
|
||||
<option value="{{ item.name }}"></option>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -44,19 +44,15 @@
|
|||
{% for orderItem in food_order.groupedOrderItems %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ orderItem.item.menuItem.menuItemAliases|map(i => i.name)|join(' / ') }}
|
||||
{{ orderItem.menuItem.menuItemAliases|map(i => i.name)|join(' / ') }}
|
||||
</td>
|
||||
<td>
|
||||
{{ orderItem.item.extras|map(i => i.name)|join(' / ') }}
|
||||
{{ orderItem.extras|map(i => i.name)|join(' / ') }}
|
||||
</td>
|
||||
<td>
|
||||
{{ orderItem.item.menuItem.price|cents_to_eur }}
|
||||
{{ orderItem.menuItem.price|cents_to_eur }}
|
||||
</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>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in a new issue