src/Entity/Category.php line 15

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 Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  11.  */
  12. class Category
  13. {
  14.     /**
  15.      * @ORM\Id()
  16.      * @ORM\GeneratedValue()
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      *
  23.      * @Assert\NotBlank(message="Veuillez donner un nom à la catégorie")
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $image;
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      * @Groups("publication:read","post:read")
  33.      */
  34.     private $slug;
  35.     /**
  36.      * @ORM\ManyToMany(targetEntity=SubCategory::class, mappedBy="categories")
  37.      */
  38.     private $subCategories;
  39.     /**
  40.      * @ORM\ManyToMany(targetEntity=Company::class, mappedBy="category")
  41.      */
  42.     private $companies;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=Annonce::class, mappedBy="categorys")
  45.      */
  46.     private $annonces;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=CategoryMaster::class, inversedBy="categories")
  49.      * @ORM\JoinColumn(nullable=false)
  50.      */
  51.     private $categoryMaster;
  52.     public function __construct()
  53.     {
  54.         $this->articles = new ArrayCollection();
  55.         $this->subCategories = new ArrayCollection();
  56.         $this->companies = new ArrayCollection();
  57.         $this->annonces = new ArrayCollection();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getName(): ?string
  64.     {
  65.         return $this->name;
  66.     }
  67.     public function setName(string $name): self
  68.     {
  69.         $this->name $name;
  70.         return $this;
  71.     }
  72.     public function getImage(): ?string
  73.     {
  74.         return $this->image;
  75.     }
  76.     public function setImage(?string $image): self
  77.     {
  78.         $this->image $image;
  79.         return $this;
  80.     }
  81.     public function getSlug(): ?string
  82.     {
  83.         return $this->slug;
  84.     }
  85.     public function setSlug(string $slug): self
  86.     {
  87.         $this->slug $slug;
  88.         return $this;
  89.     }
  90.     public function getCategoryMaster(): ?CategoryMaster
  91.     {
  92.         return $this->categoryMaster;
  93.     }
  94.     public function setCategoryMaster(?CategoryMaster $categoryMaster): self
  95.     {
  96.         $this->categoryMaster $categoryMaster;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection|SubCategory[]
  101.      */
  102.     public function getSubCategories(): Collection
  103.     {
  104.         return $this->subCategories;
  105.     }
  106.     public function addSubCategory(SubCategory $subCategory): self
  107.     {
  108.         if (!$this->subCategories->contains($subCategory)) {
  109.             $this->subCategories[] = $subCategory;
  110.             $subCategory->setCategory($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeSubCategory(SubCategory $subCategory): self
  115.     {
  116.         if ($this->subCategories->contains($subCategory)) {
  117.             $this->subCategories->removeElement($subCategory);
  118.             // set the owning side to null (unless already changed)
  119.             if ($subCategory->getCategory() === $this) {
  120.                 $subCategory->setCategory(null);
  121.             }
  122.         }
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return Collection|Company[]
  127.      */
  128.     public function getCompanies(): Collection
  129.     {
  130.         return $this->companies;
  131.     }
  132.     public function addCompany(Company $company): self
  133.     {
  134.         if (!$this->companies->contains($company)) {
  135.             $this->companies[] = $company;
  136.             $company->addCategory($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeCompany(Company $company): self
  141.     {
  142.         if ($this->companies->contains($company)) {
  143.             $this->companies->removeElement($company);
  144.             $company->removeCategory($this);
  145.         }
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection|Annonce[]
  150.      */
  151.     public function getAnnonces(): Collection
  152.     {
  153.         return $this->annonces;
  154.     }
  155.     public function addAnnonce(Annonce $annonce): self
  156.     {
  157.         if (!$this->annonces->contains($annonce)) {
  158.             $this->annonces[] = $annonce;
  159.             $annonce->setCategorys($this);
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeAnnonce(Annonce $annonce): self
  164.     {
  165.         if ($this->annonces->removeElement($annonce)) {
  166.             // set the owning side to null (unless already changed)
  167.             if ($annonce->getCategorys() === $this) {
  168.                 $annonce->setCategorys(null);
  169.             }
  170.         }
  171.         return $this;
  172.     }
  173. }