src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  8. #[ORM\Table(name"category")]
  9. #[ORM\Index(columns: ["name"], flags: ["fulltext"])]
  10. class Category
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $name null;
  18.     #[ORM\OneToMany(mappedBy'category'targetEntityProduct::class)]
  19.     private Collection $product;
  20.     #[ORM\Column(nullabletrue)]
  21.     private ?bool $indexVisible null;
  22.     public function __construct()
  23.     {
  24.         $this->product = new ArrayCollection();
  25.     }
  26.     public function __toString()
  27.     {
  28.         return $this->name;
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): static
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     /**
  44.      * @return Collection<int, Product>
  45.      */
  46.     public function getProduct(): Collection
  47.     {
  48.         return $this->product;
  49.     }
  50.     public function addProduct(Product $product): static
  51.     {
  52.         if (!$this->product->contains($product)) {
  53.             $this->product->add($product);
  54.             $product->setCategory($this);
  55.         }
  56.         return $this;
  57.     }
  58.     public function removeProduct(Product $product): static
  59.     {
  60.         if ($this->product->removeElement($product)) {
  61.             // set the owning side to null (unless already changed)
  62.             if ($product->getCategory() === $this) {
  63.                 $product->setCategory(null);
  64.             }
  65.         }
  66.         return $this;
  67.     }
  68.     public function isIndexVisible(): ?bool
  69.     {
  70.         return $this->indexVisible;
  71.     }
  72.     public function setIndexVisible(?bool $indexVisible): static
  73.     {
  74.         $this->indexVisible $indexVisible;
  75.         return $this;
  76.     }
  77. }