init
This commit is contained in:
commit
203233d2ed
71 changed files with 8213 additions and 0 deletions
78
src/Entity/Vendor.php
Normal file
78
src/Entity/Vendor.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\VendorRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
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: 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,
|
||||
|
||||
/** @var Collection<int, MenuItem> $menuItems */
|
||||
#[ORM\OneToMany(mappedBy: 'vendor', targetEntity: MenuItem::class)]
|
||||
public Collection $menuItems = new ArrayCollection,
|
||||
|
||||
/** @var Collection<int, FoodOrder> $foodOrders */
|
||||
#[ORM\OneToMany(
|
||||
mappedBy: 'vendor',
|
||||
targetEntity: FoodOrder::class,
|
||||
orphanRemoval: true,
|
||||
)]
|
||||
private Collection $foodOrders = new ArrayCollection,
|
||||
) {}
|
||||
|
||||
public function addMenuItem(MenuItem $menuItem): static
|
||||
{
|
||||
if (! $this->menuItems->contains($menuItem)) {
|
||||
$this->menuItems->add($menuItem);
|
||||
$menuItem->vendor = $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
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
|
||||
) {
|
||||
$foodOrder->vendor = null;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue