futtern/src/Entity/FoodVendor.php
Continuous Integration 70b39515ec
All checks were successful
/ ls (push) Successful in 2m16s
/ ls (release) Successful in 51s
Continuous Integration Fixes
2024-12-19 00:16:09 +00:00

150 lines
3.7 KiB
PHP

<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\FoodVendorRepository;
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: FoodVendorRepository::class)]
class FoodVendor
{
#[ORM\Column(length: 50)]
private string|null $name = null;
#[ORM\Column(length: 50, nullable: true, options: [
'default' => '',
])]
private string|null $phone = null;
/**
* @var Collection<int, FoodOrder>
*/
#[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;
#[ORM\Column(length: 255, nullable: true)]
private string|null $menuLink = null;
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid
) {
$this->foodOrders = new ArrayCollection;
$this->menuItems = new ArrayCollection;
}
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;
}
/**
* @return Collection<int, FoodOrder>
*/
public function getFoodOrders(): Collection
{
return $this->foodOrders;
}
public function addFoodOrder(FoodOrder $foodOrder): static
{
if (! $this->foodOrders->contains($foodOrder)) {
$this->foodOrders->add($foodOrder);
$foodOrder->setFoodVendor($this);
}
return $this;
}
public function removeFoodOrder(FoodOrder $foodOrder): static
{
// set the owning side to null (unless already changed)
if ($this->foodOrders->removeElement($foodOrder)) {
$foodOrder->setFoodVendor(null);
}
return $this;
}
/**
* @return Collection<int, MenuItem>
*/
public function getMenuItems(bool $withDeleted = false): Collection
{
if ($withDeleted) {
return $this->menuItems;
}
return $this->menuItems->filter(
static fn(MenuItem $item): bool => $item->isDeleted() === false
);
}
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->setFoodVendor(null);
}
return $this;
}
public function getMenuLink(): string|null
{
return $this->menuLink;
}
public function setMenuLink(string|null $menuLink): static
{
$this->menuLink = $menuLink;
return $this;
}
public function getPhone(): string|null
{
return $this->phone;
}
public function setPhone(string|null $phone): static
{
$this->phone = $phone;
return $this;
}
}