src/Admin/Entity/StdRolesPermissions.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Security\Enum\RolesPermissions;
  5. /**
  6.  * StdRolesPermissions
  7.  */
  8. #[ORM\Table(name'std_roles_permissions')]
  9. #[ORM\Index(name'fk_std_roles_permissions_std_users_0'columns: ['updated_by'])]
  10. #[ORM\Index(name'fk_std_roles_permissions_std_users'columns: ['created_by'])]
  11. #[ORM\Index(name'fk_std_roles_permissions_std_options'columns: ['option_id'])]
  12. #[ORM\Index(name'IDX_746083FCD60322AC'columns: ['role_id'])]
  13. #[ORM\Entity]
  14. class StdRolesPermissions
  15. {
  16.     #[ORM\Column(name'permission_bits'type'integer'nullabletrueoptions: ['unsigned' => true'comment' => 'Sum of all the permissions of the option associated to the role'])]
  17.     private ?int $permissionBits 0;
  18.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['default' => 'CURRENT_TIMESTAMP'])]
  19.     private \DateTimeInterface $createdDate;
  20.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['default' => 'CURRENT_TIMESTAMP'])]
  21.     private \DateTimeInterface $updatedDate;
  22.     #[ORM\Id]
  23.     #[ORM\ManyToOne(targetEntityStdOptions::class)]
  24.     #[ORM\JoinColumn(name'option_id'referencedColumnName'id'nullablefalse)]
  25.     private StdOptions $option;
  26.     #[ORM\JoinColumn(name'role_id'referencedColumnName'id')]
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue(strategy'NONE')]
  29.     #[ORM\ManyToOne(targetEntity'StdRoles'inversedBy'optionsPermissions')]
  30.     private $role;
  31.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  32.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  33.     private $createdBy;
  34.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  35.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  36.     private $updatedBy;
  37.     public function __construct()
  38.     {
  39.         $this->createdDate = new \DateTimeImmutable();
  40.         $this->updatedDate = new \DateTimeImmutable();
  41.         $this->permissionBits 0;
  42.     }
  43.     public function addPermission(int $permission): self
  44.     {
  45.         $this->permissionBits RolesPermissions::add($this->permissionBits$permission);
  46.         return $this;
  47.     }
  48.     public function removePermission(int $permission): self
  49.     {
  50.         $this->permissionBits RolesPermissions::remove($this->permissionBits$permission);
  51.         return $this;
  52.     }
  53.     public function hasPermission(int $permission): bool
  54.     {
  55.         return RolesPermissions::has($this->permissionBits$permission);
  56.     }
  57.     public function getPermissionNames(): array
  58.     {
  59.         return RolesPermissions::toArray($this->permissionBits);
  60.     }
  61.     public function getCreatedDate(): \DateTimeInterface
  62.     {
  63.         return $this->createdDate;
  64.     }
  65.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  66.     {
  67.         $this->createdDate $createdDate;
  68.         return $this;
  69.     }
  70.     public function getUpdatedDate(): \DateTimeInterface
  71.     {
  72.         return $this->updatedDate;
  73.     }
  74.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  75.     {
  76.         $this->updatedDate $updatedDate;
  77.         return $this;
  78.     }
  79.     public function getRole(): ?StdRoles
  80.     {
  81.         return $this->role;
  82.     }
  83.     public function setRole(?StdRoles $role): self
  84.     {
  85.         $this->role $role;
  86.         return $this;
  87.     }
  88.     public function getCreatedBy(): ?StdUsers
  89.     {
  90.         return $this->createdBy;
  91.     }
  92.     public function setCreatedBy(?StdUsers $createdBy): self
  93.     {
  94.         $this->createdBy $createdBy;
  95.         return $this;
  96.     }
  97.     public function getUpdatedBy(): ?StdUsers
  98.     {
  99.         return $this->updatedBy;
  100.     }
  101.     public function setUpdatedBy(?StdUsers $updatedBy): self
  102.     {
  103.         $this->updatedBy $updatedBy;
  104.         return $this;
  105.     }
  106.     public function getPermissionBits(): ?int
  107.     {
  108.         return $this->permissionBits;
  109.     }
  110.     public function setPermissionBits(?int $permissionBits): void
  111.     {
  112.         $this->permissionBits $permissionBits;
  113.     }
  114.     public function getOption(): ?StdOptions
  115.     {
  116.         return $this->option;
  117.     }
  118.     public function setOption(?StdOptions $option): void
  119.     {
  120.         $this->option $option;
  121.     }
  122. }