src/Entity/Role.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. #[ORM\Entity(repositoryClass'App\Repository\RoleRepository')]
  9. #[UniqueEntity(fields: ['name'])]
  10. class Role
  11. {
  12.     const ROLE_USER 2;
  13.     const USER 'User';
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'string'length255)]
  19.     #[Groups(['default''backend'])]
  20.     private ?string $name null;
  21.     #[ORM\ManyToMany(targetEntity'App\Entity\Permission')]
  22.     private Collection $permissions;
  23.     #[ORM\Column(type'string'length255nullabletrue)]
  24.     private ?string $displayName null;
  25.     #[ORM\Column(type'boolean'nullabletrue)]
  26.     private ?bool $isBaseRole null;
  27.     #[ORM\Column(type'integer'nullabletrue)]
  28.     private ?int $ordering null;
  29.     public function __construct()
  30.     {
  31.         $this->permissions = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     /**
  47.      * @return Collection|Permission[]
  48.      */
  49.     public function getPermissions(): Collection
  50.     {
  51.         return $this->permissions;
  52.     }
  53.     public function addPermission(Permission $permission): self
  54.     {
  55.         if (!$this->permissions->contains($permission)) {
  56.             $this->permissions[] = $permission;
  57.         }
  58.         return $this;
  59.     }
  60.     public function removePermission(Permission $permission): self
  61.     {
  62.         if ($this->permissions->contains($permission)) {
  63.             $this->permissions->removeElement($permission);
  64.         }
  65.         return $this;
  66.     }
  67.     public function getDisplayName(): ?string
  68.     {
  69.         return $this->displayName;
  70.     }
  71.     public function setDisplayName(?string $displayName): self
  72.     {
  73.         $this->displayName $displayName;
  74.         return $this;
  75.     }
  76.     public function getIsBaseRole(): ?bool
  77.     {
  78.         return $this->isBaseRole;
  79.     }
  80.     public function setIsBaseRole(?bool $isBaseRole): self
  81.     {
  82.         $this->isBaseRole $isBaseRole;
  83.         return $this;
  84.     }
  85.     public function getOrdering(): ?int
  86.     {
  87.         return $this->ordering;
  88.     }
  89.     public function setOrdering(?int $ordering): self
  90.     {
  91.         $this->ordering $ordering;
  92.         return $this;
  93.     }
  94. }