src/Entity/Actualites/Categories.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Actualites;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\Actualites\CategoriesRepository")
  12.  * @UniqueEntity("name")
  13.  */
  14. class Categories
  15. {
  16.     /**
  17.      * @ORM\Id()
  18.      * @ORM\GeneratedValue()
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      * @Assert\NotBlank(message="Veuillez saisir le nom de la catégorie")
  25.      */
  26.     private $name;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      * @Gedmo\Slug(fields={"name"})
  30.      */
  31.     private $slug;
  32.     /**
  33.      * @ORM\OneToMany(targetEntity="App\Entity\Actualites\Actualites", mappedBy="categories")
  34.      */
  35.     private $actualites;
  36.     public function __construct()
  37.     {
  38.         $this->actualites = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): self
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getSlug(): ?string
  54.     {
  55.         return $this->slug;
  56.     }
  57.     /**
  58.      * @return Collection|Actualites[]
  59.      */
  60.     public function getActualites(): Collection
  61.     {
  62.         return $this->actualites;
  63.     }
  64.     public function addActualite(Actualites $actualite): self
  65.     {
  66.         if (!$this->actualites->contains($actualite)) {
  67.             $this->actualites[] = $actualite;
  68.             $actualite->setCategories($this);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeActualite(Actualites $actualite): self
  73.     {
  74.         if ($this->actualites->contains($actualite)) {
  75.             $this->actualites->removeElement($actualite);
  76.             // set the owning side to null (unless already changed)
  77.             if ($actualite->getCategories() === $this) {
  78.                 $actualite->setCategories(null);
  79.             }
  80.         }
  81.         return $this;
  82.     }
  83.     public function __toString()
  84.     {
  85.         return $this->name;
  86.     }
  87. }