forked from lubiana/futtern
add option to select previous menuitems
This commit is contained in:
parent
57b4e33028
commit
45029e0a4c
11 changed files with 410 additions and 94 deletions
|
@ -28,9 +28,16 @@ class FoodVendor
|
|||
#[ORM\OneToMany(targetEntity: FoodOrder::class, mappedBy: 'foodVendor', orphanRemoval: true)]
|
||||
private Collection $foodOrders;
|
||||
|
||||
/**
|
||||
* @var Collection<int, MenuItem>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
|
||||
private Collection $menuItems;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->foodOrders = new ArrayCollection;
|
||||
$this->menuItems = new ArrayCollection;
|
||||
}
|
||||
|
||||
public function getId(): Ulid|null
|
||||
|
@ -77,4 +84,32 @@ class FoodVendor
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, MenuItem>
|
||||
*/
|
||||
public function getMenuItems(): Collection
|
||||
{
|
||||
return $this->menuItems;
|
||||
}
|
||||
|
||||
public function addMenuItem(MenuItem $menuItem): static
|
||||
{
|
||||
if (! $this->menuItems->contains($menuItem)) {
|
||||
$this->menuItems->add($menuItem);
|
||||
$menuItem->setFoodVendor($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeMenuItem(MenuItem $menuItem): static
|
||||
{
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($this->menuItems->removeElement($menuItem) && $menuItem->getFoodVendor() === $this) {
|
||||
$menuItem->setFoodVendor(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
55
src/Entity/MenuItem.php
Normal file
55
src/Entity/MenuItem.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\MenuItemRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
|
||||
class MenuItem
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private string|null $name = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'menuItems')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private FoodVendor|null $foodVendor = null;
|
||||
|
||||
public function getId(): Ulid|null
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string|null
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFoodVendor(): FoodVendor|null
|
||||
{
|
||||
return $this->foodVendor;
|
||||
}
|
||||
|
||||
public function setFoodVendor(FoodVendor|null $foodVendor): static
|
||||
{
|
||||
$this->foodVendor = $foodVendor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -24,9 +24,13 @@ class OrderItem
|
|||
private string|null $extras = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'orderItems')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
private FoodOrder|null $foodOrder = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
private MenuItem|null $menuItem = null;
|
||||
|
||||
public function getId(): Ulid|null
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -67,4 +71,16 @@ class OrderItem
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMenuItem(): MenuItem|null
|
||||
{
|
||||
return $this->menuItem;
|
||||
}
|
||||
|
||||
public function setMenuItem(MenuItem|null $menuItem): static
|
||||
{
|
||||
$this->menuItem = $menuItem;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue