src/Entity/Droit.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DroitRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassDroitRepository::class)]
  8. class Droit implements \Stringable
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[ORM\Column(type'string'length255nullabletrue)]
  15.     private $name;
  16.     #[ORM\Column(type'string'length255nullabletrue)]
  17.     private $name_fr;
  18.     #[ORM\Column(type'string'length255nullabletrue)]
  19.     private $role;
  20.     #[ORM\OneToMany(targetEntityUser::class, mappedBy'droit')]
  21.     private $users;
  22.     #[ORM\ManyToMany(targetEntityRoute::class, inversedBy'droits')]
  23.     private $routes;
  24.     public function __construct()
  25.     {
  26.         $this->users = new ArrayCollection();
  27.         $this->routes = new ArrayCollection();
  28.     }
  29.     public function __toString(): string
  30.     {
  31.         return (string) $this->name_fr;
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(?string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     public function getNameFr(): ?string
  47.     {
  48.         return $this->name_fr;
  49.     }
  50.     public function setNameFr(?string $name_fr): self
  51.     {
  52.         $this->name_fr $name_fr;
  53.         return $this;
  54.     }
  55.     public function getRole(): ?string
  56.     {
  57.         return $this->role;
  58.     }
  59.     public function setRole(?string $role): self
  60.     {
  61.         $this->role $role;
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection|User[]
  66.      */
  67.     public function getUsers(): Collection
  68.     {
  69.         return $this->users;
  70.     }
  71.     public function addUser(User $user): self
  72.     {
  73.         if (!$this->users->contains($user)) {
  74.             $this->users[] = $user;
  75.             $user->setDroit($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeUser(User $user): self
  80.     {
  81.         if ($this->users->removeElement($user)) {
  82.             // set the owning side to null (unless already changed)
  83.             if ($user->getDroit() === $this) {
  84.                 $user->setDroit(null);
  85.             }
  86.         }
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection|Route[]
  91.      */
  92.     public function getRoutes(): Collection
  93.     {
  94.         return $this->routes;
  95.     }
  96.     public function addRoute(Route $route): self
  97.     {
  98.         if (!$this->routes->contains($route)) {
  99.             $this->routes[] = $route;
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeRoute(Route $route): self
  104.     {
  105.         $this->routes->removeElement($route);
  106.         return $this;
  107.     }
  108. }