This commit is contained in:
lubiana 2024-02-12 22:03:17 +01:00
parent 203233d2ed
commit 93fa2da696
45 changed files with 2633 additions and 550 deletions

View file

@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace App\Entity;
@ -13,33 +14,58 @@ use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: VendorRepository::class)]
class Vendor
{
public function __construct(
#[ORM\Column]
public string $name,
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
public Ulid $id = new Ulid,
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid $id;
/** @var Collection<int, MenuItem> $menuItems */
#[ORM\OneToMany(mappedBy: 'vendor', targetEntity: MenuItem::class)]
public Collection $menuItems = new ArrayCollection,
#[ORM\Column(length: 50)]
private string|null $name = null;
/** @var Collection<int, FoodOrder> $foodOrders */
#[ORM\OneToMany(
mappedBy: 'vendor',
targetEntity: FoodOrder::class,
orphanRemoval: true,
)]
private Collection $foodOrders = new ArrayCollection,
) {}
#[ORM\OneToMany(
mappedBy: 'vendor',
targetEntity: MenuItem::class,
orphanRemoval: true,
)]
private Collection $menuItems;
public function __construct()
{
$this->id = new Ulid;
$this->menuItems = new ArrayCollection;
}
public function getId(): Ulid
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
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->vendor = $this;
$menuItem->setVendor($this);
}
return $this;
@ -48,29 +74,11 @@ class Vendor
public function removeMenuItem(MenuItem $menuItem): static
{
// set the owning side to null (unless already changed)
if ($this->menuItems->removeElement($menuItem) && $menuItem->vendor === $this) {
$menuItem->vendor = null;
}
return $this;
}
public function addFoodOrder(FoodOrder $foodOrder): static
{
if (! $this->foodOrders->contains($foodOrder)) {
$this->foodOrders->add($foodOrder);
$foodOrder->vendor = $this;
}
return $this;
}
public function removeFoodOrder(FoodOrder $foodOrder): static
{
if (
$this->foodOrders->removeElement($foodOrder) && $foodOrder->vendor === $this
$this->menuItems->removeElement($menuItem)
&& $menuItem->getVendor() === $this
) {
$foodOrder->vendor = null;
$menuItem->setVendor(null);
}
return $this;