add order item stuff #5
2 changed files with 17 additions and 13 deletions
|
@ -1,32 +1,33 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Entity\FoodVendor;
|
||||
use Doctrine\Common\Collections\Order;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Override;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
use function range;
|
||||
use function sprintf;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:fake-data',
|
||||
description: 'Add a short description for your command',
|
||||
)]
|
||||
class FakeDataCommand extends Command
|
||||
final class FakeDataCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
)
|
||||
{
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
@ -52,7 +53,7 @@ class FakeDataCommand extends Command
|
|||
{
|
||||
$vendors = [];
|
||||
foreach (range(1, $amount) as $i) {
|
||||
$vendor = new FoodVendor();
|
||||
$vendor = new FoodVendor;
|
||||
$vendor->setName('Food Vendor ' . $i);
|
||||
$this->entityManager->persist($vendor);
|
||||
$vendors[] = $vendor;
|
||||
|
@ -64,7 +65,7 @@ class FakeDataCommand extends Command
|
|||
{
|
||||
$orders = [];
|
||||
foreach (range(1, $amount) as $i) {
|
||||
$order = new FoodOrder();
|
||||
$order = new FoodOrder;
|
||||
$order->setFoodVendor($vendor);
|
||||
if ($i % 2 === 0) {
|
||||
$order->close();
|
||||
|
|
|
@ -60,7 +60,8 @@ final class OrderItemController extends AbstractController
|
|||
$entityManager->persist($newOrderItem);
|
||||
$entityManager->flush();
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
'id' => $orderItem->getFoodOrder()->getId(),
|
||||
'id' => $orderItem->getFoodOrder()
|
||||
->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,8 @@ final class OrderItemController extends AbstractController
|
|||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
'id' => $orderItem->getFoodOrder()->getId(),
|
||||
'id' => $orderItem->getFoodOrder()
|
||||
->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
|
@ -102,7 +104,8 @@ final class OrderItemController extends AbstractController
|
|||
$entityManager->remove($orderItem);
|
||||
$entityManager->flush();
|
||||
return $this->redirectToRoute('app_food_order_show', [
|
||||
'id' => $orderItem->getFoodOrder()->getId(),
|
||||
'id' => $orderItem->getFoodOrder()
|
||||
->getId(),
|
||||
], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue