src/Entity/UserRoles.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CommonTrait;
  4. use App\Repository\UserRolesRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserRolesRepository::class)
  11.  * @ORM\Table(name="app_user_roles")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @UniqueEntity({"uuid"})
  14.  */
  15. class UserRoles
  16. {
  17.     use CommonTrait;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $role;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="userRoles")
  28.      */
  29.     private $users;
  30.     public function __construct()
  31.     {
  32.         $this->users = new ArrayCollection();
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     public function getRole(): ?string
  44.     {
  45.         return $this->role;
  46.     }
  47.     public function setRole(string $role): self
  48.     {
  49.         $this->role $role;
  50.         return $this;
  51.     }
  52.     public function __toString()
  53.     {
  54.         return $this->name;
  55.     }
  56.     /**
  57.      * @return Collection|User[]
  58.      */
  59.     public function getUsers(): Collection
  60.     {
  61.         return $this->users;
  62.     }
  63.     public function addUser(User $user): self
  64.     {
  65.         if (!$this->users->contains($user)) {
  66.             $this->users[] = $user;
  67.             $user->addUserRole($this);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeUser(User $user): self
  72.     {
  73.         if ($this->users->contains($user)) {
  74.             $this->users->removeElement($user);
  75.             $user->removeUserRole($this);
  76.         }
  77.         return $this;
  78.     }
  79. }