src/Entity/Roles.php line 14

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