src/Entity/Category.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\CategoryRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  9. class Category
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length64)]
  16.     #[Groups("shop_browse")]
  17.     private ?string $name null;
  18.     #[ORM\Column(length255nullabletrue)]
  19.     private ?string $picture null;
  20.     // mappedBy
  21.     #[ORM\ManyToMany(targetEntityShop::class, mappedBy'categories'cascade: ["persist"])]
  22.     //#[Groups("shop_browse")]
  23.     private Collection $shops;
  24.     #[ORM\Column(length64)]
  25.     private ?string $subtitle null;
  26.     #[ORM\OneToMany(mappedBy'category'targetEntitySubCategory::class)]
  27.     private Collection $subcategories;
  28.     public function __construct()
  29.     {
  30.         $this->shops = new ArrayCollection();
  31.         $this->subcategories = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     public function getPicture(): ?string
  47.     {
  48.         return $this->picture;
  49.     }
  50.     public function setPicture(?string $picture): self
  51.     {
  52.         $this->picture $picture;
  53.         return $this;
  54.     }
  55.     /**
  56.      * @return Collection<int, Shop>
  57.      */
  58.     public function getShops(): Collection
  59.     {
  60.         return $this->shops;
  61.     }
  62.     public function addShop(Shop $shop): self
  63.     {
  64.         if (!$this->shops->contains($shop)) {
  65.             $this->shops->add($shop);
  66.             $shop->addCategory($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function removeShop(Shop $shop): self
  71.     {
  72.         if ($this->shops->removeElement($shop)) {
  73.             $shop->removeCategory($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function getSubtitle(): ?string
  78.     {
  79.         return $this->subtitle;
  80.     }
  81.     public function setSubtitle(string $subtitle): self
  82.     {
  83.         $this->subtitle $subtitle;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, SubCategory>
  88.      */
  89.     public function getSubcategories(): Collection
  90.     {
  91.         return $this->subcategories;
  92.     }
  93.     public function addSubcategory(SubCategory $subcategory): self
  94.     {
  95.         if (!$this->subcategories->contains($subcategory)) {
  96.             $this->subcategories->add($subcategory);
  97.             $subcategory->setCategory($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeSubcategory(SubCategory $subcategory): self
  102.     {
  103.         if ($this->subcategories->removeElement($subcategory)) {
  104.             // set the owning side to null (unless already changed)
  105.             if ($subcategory->getCategory() === $this) {
  106.                 $subcategory->setCategory(null);
  107.             }
  108.         }
  109.         return $this;
  110.     }
  111.     public function __toString()
  112.     {
  113.         return $this->name;
  114.     }
  115. }