<?phpnamespace App\Entity;use App\Enum\CategoryTypeEnum;use App\Repository\CategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: CategoryRepository::class)]class Category extends BaseEntity{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 255)] #[Assert\NotBlank] private ?string $name = null; #[ORM\Column] #[Assert\Range(min: 1, max: 10)] private ?int $priority = 1; #[ORM\Column(length: 255, nullable: true)] private ?string $color = null; #[ORM\Column(type: 'string', enumType: CategoryTypeEnum::class)] private CategoryTypeEnum $type = CategoryTypeEnum::PHYSICAL; #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] #[ORM\JoinColumn(onDelete: 'SET NULL')] private ?self $parent = null; #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] private Collection $children; #[ORM\Column(length: 255, nullable: true)] private ?string $image = null; #[ORM\ManyToMany(targetEntity: Product::class, mappedBy: 'categories')] private Collection $products; public function __construct() { $this->children = new ArrayCollection(); $this->products = new ArrayCollection(); } public function __toString(): string { return $this->name ?? 'New Category'; } 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 getPriority(): ?int { return $this->priority; } public function setPriority(int $priority): self { $this->priority = $priority; return $this; } public function getColor(): ?string { return $this->color; } public function setColor(?string $color): self { $this->color = $color; return $this; } public function getType(): CategoryTypeEnum { return $this->type; } public function setType(CategoryTypeEnum $type): self { $this->type = $type; return $this; } public function getParent(): ?self { return $this->parent; } public function setParent(?self $parent): self { $this->parent = $parent; return $this; } /** * @return Collection<int, self> */ public function getChildren(): Collection { return $this->children; } public function addChild(self $child): self { if (!$this->children->contains($child)) { $this->children->add($child); $child->setParent($this); } return $this; } public function removeChild(self $child): self { if ($this->children->removeElement($child)) { // set the owning side to null (unless already changed) if ($child->getParent() === $this) { $child->setParent(null); } } return $this; } public function getImage(): ?string { return $this->image; } public function setImage(?string $image): self { $this->image = $image; return $this; } /** * @return Collection<int, Product> */ public function getProducts(): Collection { return $this->products; } public function addProduct(Product $product): self { if (!$this->products->contains($product)) { $this->products->add($product); $product->addCategory($this); } return $this; } public function removeProduct(Product $product): self { if ($this->products->removeElement($product)) { $product->removeCategory($this); } return $this; }}