<?php
namespace App\Entity;
use App\Entity\FoodItem;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\FoodCategoryRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
#[ORM\Entity(repositoryClass: FoodCategoryRepository::class)]
class FoodCategory
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $name = null;
#[ORM\Column(type: 'integer')]
private ?int $orderId = null;
// OneToMany relationship with FoodItem
#[ORM\OneToMany(mappedBy: 'category', targetEntity: FoodItem::class)]
private Collection $foodItems;
public function __construct()
{
$this->foodItems = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getOrderId(): ?int
{
return $this->orderId;
}
public function setOrderId(int $orderId): self
{
$this->orderId = $orderId;
return $this;
}
/**
* @return Collection|FoodItem[]
*/
public function getFoodItems(): Collection
{
return $this->foodItems;
}
public function addFoodItem(FoodItem $foodItem): self
{
if (!$this->foodItems->contains($foodItem)) {
$this->foodItems[] = $foodItem;
$foodItem->setCategory($this);
}
return $this;
}
public function removeFoodItem(FoodItem $foodItem): self
{
if ($this->foodItems->removeElement($foodItem)) {
// set the owning side to null (unless already changed)
if ($foodItem->getCategory() === $this) {
$foodItem->setCategory(null);
}
}
return $this;
}
}