src/Entity/Role.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Permission;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\RoleRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. #[ORM\Entity(repositoryClassRoleRepository::class)]
  10. class Role
  11. {
  12.   #[ORM\Id]
  13.   #[ORM\GeneratedValue]
  14.   #[ORM\Column()]
  15.   private ?int $id null;
  16.   #[ORM\Column]
  17.   #[Gedmo\Timestampable(on'create')]
  18.   private ?\DateTimeImmutable $createdAt null;
  19.   #[ORM\Column(length255)]
  20.   private ?string $title null;
  21.   #[ORM\Column(length255)]
  22.   private ?string $label null;
  23.   #[ORM\Column(nullabletrue)]
  24.   private ?int $authorId null;
  25.   #[ORM\ManyToMany(mappedBy'roles'targetEntityPermission::class)]
  26.   private Collection $permissions;
  27.   #[ORM\ManyToMany(targetEntityUser::class, inversedBy'accessRoles')]
  28.   private Collection $users;
  29.   public function __construct()
  30.   {
  31.     $this->permissions = new ArrayCollection();
  32.     $this->users = new ArrayCollection();
  33.   }
  34.   public function getId(): ?int
  35.   {
  36.     return $this->id;
  37.   }
  38.   public function getCreatedAt(): ?\DateTimeImmutable
  39.   {
  40.     return $this->createdAt;
  41.   }
  42.   public function setCreatedAt(\DateTimeImmutable $createdAt): self
  43.   {
  44.     $this->createdAt $createdAt;
  45.     return $this;
  46.   }
  47.   public function getTitle(): ?string
  48.   {
  49.     return $this->title;
  50.   }
  51.   public function setTitle(string $title): self
  52.   {
  53.     $this->title $title;
  54.     return $this;
  55.   }
  56.   public function getLabel(): ?string
  57.   {
  58.     return $this->label;
  59.   }
  60.   public function setLabel(string $label): self
  61.   {
  62.     $this->label $label;
  63.     return $this;
  64.   }
  65.   public function getAuthorId(): ?int
  66.   {
  67.     return $this->authorId;
  68.   }
  69.   public function setAuthorId(?int $authorId): self
  70.   {
  71.     $this->authorId $authorId;
  72.     return $this;
  73.   }
  74.   public function setUsers(?User $users): self
  75.   {
  76.     $this->users $users;
  77.     return $this;
  78.   }
  79.   /**
  80.    * @return Collection<int, User>
  81.    */
  82.   public function getUsers(): Collection
  83.   {
  84.     return $this->users;
  85.   }
  86.   public function addUser(User $user): self
  87.   {
  88.     if (!$this->users->contains($user)) {
  89.       $this->users->add($user);
  90.     }
  91.     return $this;
  92.   }
  93.   public function removeUser(User $user): self
  94.   {
  95.     $this->users->removeElement($user);
  96.     return $this;
  97.   }
  98.   /**
  99.    * @return Collection<int, Permission>
  100.    */
  101.   public function getPermissions(): Collection
  102.   {
  103.     return $this->permissions;
  104.   }
  105.   public function addPermission(Permission $permission): self
  106.   {
  107.     if (!$this->permissions->contains($permission)) {
  108.       $this->permissions->add($permission);
  109.       $permission->addRole($this);
  110.     }
  111.     return $this;
  112.   }
  113.   public function removePermission(Permission $permission): self
  114.   {
  115.     if ($this->permissions->removeElement($permission)) {
  116.       $permission->removeRole($this);
  117.     }
  118.     return $this;
  119.   }
  120. }