All checks were successful
/ ls (pull_request) Successful in 30s
add order item stuff
76 lines
2 KiB
PHP
76 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use App\Entity\FoodOrder;
|
|
use App\Entity\FoodVendor;
|
|
use Doctrine\Common\Collections\Order;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
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;
|
|
|
|
#[AsCommand(
|
|
name: 'app:fake-data',
|
|
description: 'Add a short description for your command',
|
|
)]
|
|
class FakeDataCommand extends Command
|
|
{
|
|
public function __construct(
|
|
private EntityManagerInterface $entityManager,
|
|
)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$arg1 = $input->getArgument('arg1');
|
|
|
|
if ($arg1) {
|
|
$io->note(sprintf('You passed an argument: %s', $arg1));
|
|
}
|
|
|
|
if ($input->getOption('option1')) {
|
|
// ...
|
|
}
|
|
|
|
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @return FoodVendor[]
|
|
*/
|
|
public function generateVendors(int $amount = 10): array
|
|
{
|
|
$vendors = [];
|
|
foreach (range(1, $amount) as $i) {
|
|
$vendor = new FoodVendor();
|
|
$vendor->setName('Food Vendor ' . $i);
|
|
$this->entityManager->persist($vendor);
|
|
$vendors[] = $vendor;
|
|
}
|
|
return $vendors;
|
|
}
|
|
|
|
public function generateOrdersForVendor(FoodVendor $vendor, int $amount = 10): array
|
|
{
|
|
$orders = [];
|
|
foreach (range(1, $amount) as $i) {
|
|
$order = new FoodOrder();
|
|
$order->setFoodVendor($vendor);
|
|
if ($i % 2 === 0) {
|
|
$order->close();
|
|
}
|
|
$orders[] = $order;
|
|
}
|
|
return $orders;
|
|
}
|
|
}
|