<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
#[ORM\Table(name: "category")]
#[ORM\Index(columns: ["name"], flags: ["fulltext"])]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Product::class)]
private Collection $product;
#[ORM\Column(nullable: true)]
private ?bool $indexVisible = null;
public function __construct()
{
$this->product = 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): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProduct(): Collection
{
return $this->product;
}
public function addProduct(Product $product): static
{
if (!$this->product->contains($product)) {
$this->product->add($product);
$product->setCategory($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->product->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCategory() === $this) {
$product->setCategory(null);
}
}
return $this;
}
public function isIndexVisible(): ?bool
{
return $this->indexVisible;
}
public function setIndexVisible(?bool $indexVisible): static
{
$this->indexVisible = $indexVisible;
return $this;
}
}