src/Entity/Category.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Subcategory;
  4. use App\Entity\Company;
  5. use App\Model\TranslationModel;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping\OrderBy;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Doctrine\ORM\Mapping\UniqueConstraint as UniqueConstraint;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. #[ORM\Table(name"category")]
  14. #[ORM\Entity(repositoryClass"App\Repository\CategoryRepository")]
  15. class Category extends TranslationModel
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue(strategy'AUTO')]
  19.     #[ORM\Column(name'id'type'integer'uniquetrue)]
  20.     #[Groups(['category''company'])]
  21.     private $id;
  22.     #[ORM\Column(name'name'type'string'length255)]
  23.     #[Groups(['category''company'])]
  24.     protected $name;
  25.     #[ORM\Column(name'description'type'text'nullabletrue)]
  26.     #[Groups(['category''company'])]
  27.     protected $description;
  28.     #[ORM\Column(name'image'type'string')]
  29.     #[Groups(['category''company'])]
  30.     protected $image;
  31.     #[ORM\Column(name'slug'type'string'length255nullabletrue)]
  32.     #[Groups(['category''company'])]
  33.     protected $slug;
  34.     #[ORM\ManyToMany(targetEntityCompany::class, mappedBy'categories'cascade: ['persist'])]
  35.     protected Collection $companies;
  36.     #[Groups(['category''company'])]
  37.     #[ORM\ManyToMany(targetEntitySubcategory::class, inversedBy'categories'cascade: ['persist'])]
  38.     protected Collection $subcategories;
  39.     public function __construct()
  40.     {
  41.         $this->subcategories = new ArrayCollection();
  42.         $this->companies = new ArrayCollection();
  43.     }
  44.     public function getCompanies(): Collection
  45.     {
  46.         return $this->companies;
  47.     }
  48.     public function addCompany(Company $company): self
  49.     {
  50.         if (!$this->companies->contains($company)) {
  51.             $this->companies->add($company);
  52.         }
  53.         return $this;
  54.     }
  55.     public function removeCompany(Company $company): self
  56.     {
  57.         $this->companies->removeElement($company);
  58.         return $this;
  59.     }
  60.     public function getSubcategories(): Collection
  61.     {
  62.         return $this->subcategories;
  63.     }
  64.     public function addSubcategory(Subcategory $subcategory): self
  65.     {
  66.         if (!$this->subcategories->contains($subcategory)) {
  67.             $this->subcategories->add($subcategory);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeSubcategory(Subcategory $subcategory): self
  72.     {
  73.         $this->subcategories->removeElement($subcategory);
  74.         return $this;
  75.     }
  76.     public function setSubcategories(Collection $subcategories): self
  77.     {
  78.         $this->subcategories $subcategories;
  79.         return $this;
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function setId(int $id): self
  86.     {
  87.         $this->id $id;
  88.         return $this;
  89.     }
  90.     public function getName(): ?string
  91.     {
  92.         return $this->name;
  93.     }
  94.     public function setName(string $name): self
  95.     {
  96.         $this->name $name;
  97.         return $this;
  98.     }
  99.     public function getDescription(): ?string
  100.     {
  101.         return $this->description;
  102.     }
  103.     public function setDescription(?string $description): self
  104.     {
  105.         $this->description $description;
  106.         return $this;
  107.     }
  108.     public function getSlug(): ?string
  109.     {
  110.         return $this->slug;
  111.     }
  112.     public function setSlug(?string $slug): self
  113.     {
  114.         $this->slug $slug;
  115.         return $this;
  116.     }
  117.     public function getImage(): ?string
  118.     {
  119.         return $this->image;
  120.     }
  121.     public function setImage(string $image): self
  122.     {
  123.         $this->image $image;
  124.         return $this;
  125.     }
  126. }