src/Entity/Categorie.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategorieRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CategorieRepository::class)
  9.  */
  10. class Categorie
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=50, nullable=true)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\ManyToMany(targetEntity=Formation::class, mappedBy="categories")
  24.      */
  25.     private $formations;
  26.     public function __construct()
  27.     {
  28.         $this->formations = new ArrayCollection();
  29.     }
  30.     public function __toString()
  31.     {
  32.         return $this->name;
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getName(): ?string
  39.     {
  40.         return $this->name;
  41.     }
  42.     public function setName(?string $name): self
  43.     {
  44.         $this->name $name;
  45.         return $this;
  46.     }
  47.     /**
  48.      * @return Collection<int, Formation>
  49.      */
  50.     public function getFormations(): Collection
  51.     {
  52.         return $this->formations;
  53.     }
  54.     public function addFormation(Formation $formation): self
  55.     {
  56.         if (!$this->formations->contains($formation)) {
  57.             $this->formations[] = $formation;
  58.             $formation->addCategory($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeFormation(Formation $formation): self
  63.     {
  64.         if ($this->formations->removeElement($formation)) {
  65.             $formation->removeCategory($this);
  66.         }
  67.         return $this;
  68.     }
  69. }