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.     public function __construct()
  48.     {
  49.         $this->articles = new ArrayCollection();
  50.         $this->subCategories = new ArrayCollection();
  51.         $this->companies = new ArrayCollection();
  52.         $this->annonces = new ArrayCollection();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getName(): ?string
  59.     {
  60.         return $this->name;
  61.     }
  62.     public function setName(string $name): self
  63.     {
  64.         $this->name $name;
  65.         return $this;
  66.     }
  67.     public function getImage(): ?string
  68.     {
  69.         return $this->image;
  70.     }
  71.     public function setImage(?string $image): self
  72.     {
  73.         $this->image $image;
  74.         return $this;
  75.     }
  76.     public function getSlug(): ?string
  77.     {
  78.         return $this->slug;
  79.     }
  80.     public function setSlug(string $slug): self
  81.     {
  82.         $this->slug $slug;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection|SubCategory[]
  87.      */
  88.     public function getSubCategories(): Collection
  89.     {
  90.         return $this->subCategories;
  91.     }
  92.     public function addSubCategory(SubCategory $subCategory): self
  93.     {
  94.         if (!$this->subCategories->contains($subCategory)) {
  95.             $this->subCategories[] = $subCategory;
  96.             $subCategory->setCategory($this);
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeSubCategory(SubCategory $subCategory): self
  101.     {
  102.         if ($this->subCategories->contains($subCategory)) {
  103.             $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.     /**
  112.      * @return Collection|Company[]
  113.      */
  114.     public function getCompanies(): Collection
  115.     {
  116.         return $this->companies;
  117.     }
  118.     public function addCompany(Company $company): self
  119.     {
  120.         if (!$this->companies->contains($company)) {
  121.             $this->companies[] = $company;
  122.             $company->addCategory($this);
  123.         }
  124.         return $this;
  125.     }
  126.     public function removeCompany(Company $company): self
  127.     {
  128.         if ($this->companies->contains($company)) {
  129.             $this->companies->removeElement($company);
  130.             $company->removeCategory($this);
  131.         }
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Collection|Annonce[]
  136.      */
  137.     public function getAnnonces(): Collection
  138.     {
  139.         return $this->annonces;
  140.     }
  141.     public function addAnnonce(Annonce $annonce): self
  142.     {
  143.         if (!$this->annonces->contains($annonce)) {
  144.             $this->annonces[] = $annonce;
  145.             $annonce->setCategorys($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeAnnonce(Annonce $annonce): self
  150.     {
  151.         if ($this->annonces->removeElement($annonce)) {
  152.             // set the owning side to null (unless already changed)
  153.             if ($annonce->getCategorys() === $this) {
  154.                 $annonce->setCategorys(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159. }