src/Entity/Role.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RoleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=RoleRepository::class)
  9.  */
  10. class Role
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $libelle;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="role")
  24.      */
  25.     private $users;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=Fonction::class, mappedBy="role")
  28.      */
  29.     private $fonctions;
  30.     public function __construct()
  31.     {
  32.         $this->users = new ArrayCollection();
  33.         $this->fonctions = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getLibelle(): ?string
  40.     {
  41.         return $this->libelle;
  42.     }
  43.     public function setLibelle(string $libelle): self
  44.     {
  45.         $this->libelle $libelle;
  46.         return $this;
  47.     }
  48.     /**
  49.      * @return Collection<int, User>
  50.      */
  51.     public function getUsers(): Collection
  52.     {
  53.         return $this->users;
  54.     }
  55.     public function addUser(User $user): self
  56.     {
  57.         if (!$this->users->contains($user)) {
  58.             $this->users[] = $user;
  59.             $user->setRole($this);
  60.         }
  61.         return $this;
  62.     }
  63.     public function removeUser(User $user): self
  64.     {
  65.         if ($this->users->removeElement($user)) {
  66.             // set the owning side to null (unless already changed)
  67.             if ($user->getRole() === $this) {
  68.                 $user->setRole(null);
  69.             }
  70.         }
  71.         return $this;
  72.     }
  73.     /**
  74.      * @return Collection<int, Fonction>
  75.      */
  76.     public function getFonctions(): Collection
  77.     {
  78.         return $this->fonctions;
  79.     }
  80.     public function addFonction(Fonction $fonction): self
  81.     {
  82.         if (!$this->fonctions->contains($fonction)) {
  83.             $this->fonctions[] = $fonction;
  84.             $fonction->addRole($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeFonction(Fonction $fonction): self
  89.     {
  90.         if ($this->fonctions->removeElement($fonction)) {
  91.             $fonction->removeRole($this);
  92.         }
  93.         return $this;
  94.     }
  95. }