src/Entity/Roles.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RolesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: RolesRepository::class)]
  8. class Roles
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id = null;
  14.     #[ORM\Column(length: 255)]
  15.     private ?string $role = null;
  16.     #[ORM\ManyToMany(targetEntity: Routes::class, mappedBy: 'roles')]
  17.     private Collection $routes;
  18.     #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'roles_user')]
  19.     private Collection $users;
  20.     #[ORM\ManyToMany(targetEntity: UserOdoo::class, mappedBy: 'roles_user')]
  21.     private Collection $usersOdoo;
  22.     public function __construct()
  23.     {
  24.         $this->routes = new ArrayCollection();
  25.         $this->users = new ArrayCollection();
  26.         $this->usersOdoo = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getRole(): ?string
  33.     {
  34.         return $this->role;
  35.     }
  36.     public function setRole(string $role): self
  37.     {
  38.         $this->role = $role;
  39.         return $this;
  40.     }
  41.     /**
  42.      * @return Collection<int, Routes>
  43.      */
  44.     public function getRoutes(): Collection
  45.     {
  46.         return $this->routes;
  47.     }
  48.     public function addRoute(Routes $route): self
  49.     {
  50.         if (!$this->routes->contains($route)) {
  51.             $this->routes->add($route);
  52.             $route->addRole($this);
  53.         }
  54.         return $this;
  55.     }
  56.     public function removeRoute(Routes $route): self
  57.     {
  58.         if ($this->routes->removeElement($route)) {
  59.             $route->removeRole($this);
  60.         }
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return Collection<int, User>
  65.      */
  66.     public function getUsers(): Collection
  67.     {
  68.         return $this->users;
  69.     }
  70.     public function addUser(User $user): self
  71.     {
  72.         if (!$this->users->contains($user)) {
  73.             $this->users->add($user);
  74.             $user->addRolesUser($this);
  75.         }
  76.         return $this;
  77.     }
  78.     public function removeUser(User $user): self
  79.     {
  80.         if ($this->users->removeElement($user)) {
  81.             $user->removeRolesUser($this);
  82.         }
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection<int, UserOdoo>
  87.      */
  88.     public function getUsersOdoo(): Collection
  89.     {
  90.         return $this->usersOdoo;
  91.     }
  92.     public function addUserOdoo(UserOdoo $user): self
  93.     {
  94.         if (!$this->usersOdoo->contains($user)) {
  95.             $this->usersOdoo->add($user);
  96.             $user->addRolesUser($this);
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeUserOdoo(UserOdoo $user): self
  101.     {
  102.         if ($this->usersOdoo->removeElement($user)) {
  103.             $user->removeRolesUser($this);
  104.         }
  105.         return $this;
  106.     }
  107. }