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 $name;
  22. /**
  23. * @ORM\Column(type="text", nullable=true)
  24. */
  25. private $description;
  26. /**
  27. * @ORM\ManyToMany(targetEntity=User::class, inversedBy="userRoles")
  28. */
  29. private $users;
  30. /**
  31. * @ORM\ManyToMany(targetEntity=Permission::class, mappedBy="roles")
  32. */
  33. private $permissions;
  34. public function __construct()
  35. {
  36. $this->users = new ArrayCollection();
  37. $this->permissions = new ArrayCollection();
  38. }
  39. public function getId(): ?int
  40. {
  41. return $this->id;
  42. }
  43. public function getName(): ?string
  44. {
  45. return $this->name;
  46. }
  47. public function setName(string $name): self
  48. {
  49. $this->name = $name;
  50. return $this;
  51. }
  52. public function getDescription(): ?string
  53. {
  54. return $this->description;
  55. }
  56. public function setDescription(?string $description): self
  57. {
  58. $this->description = $description;
  59. return $this;
  60. }
  61. /**
  62. * @return Collection<int, User>
  63. */
  64. public function getUsers(): Collection
  65. {
  66. return $this->users;
  67. }
  68. public function addUser(User $user): self
  69. {
  70. if (!$this->users->contains($user)) {
  71. $this->users[] = $user;
  72. }
  73. return $this;
  74. }
  75. public function removeUser(User $user): self
  76. {
  77. $this->users->removeElement($user);
  78. return $this;
  79. }
  80. /**
  81. * @return Collection<int, Permission>
  82. */
  83. public function getPermissions(): Collection
  84. {
  85. return $this->permissions;
  86. }
  87. public function addPermission(Permission $permission): self
  88. {
  89. if (!$this->permissions->contains($permission)) {
  90. $this->permissions[] = $permission;
  91. $permission->addRole($this);
  92. }
  93. return $this;
  94. }
  95. public function removePermission(Permission $permission): self
  96. {
  97. if ($this->permissions->removeElement($permission)) {
  98. $permission->removeRole($this);
  99. }
  100. return $this;
  101. }
  102. }