<?php
namespace App\Admin\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Security\Enum\RolesPermissions;
/**
* StdRolesPermissions
*/
#[ORM\Table(name: 'std_roles_permissions')]
#[ORM\Index(name: 'fk_std_roles_permissions_std_users_0', columns: ['updated_by'])]
#[ORM\Index(name: 'fk_std_roles_permissions_std_users', columns: ['created_by'])]
#[ORM\Index(name: 'fk_std_roles_permissions_std_options', columns: ['option_id'])]
#[ORM\Index(name: 'IDX_746083FCD60322AC', columns: ['role_id'])]
#[ORM\Entity]
class StdRolesPermissions
{
#[ORM\Column(name: 'permission_bits', type: 'integer', nullable: true, options: ['unsigned' => true, 'comment' => 'Sum of all the permissions of the option associated to the role'])]
private ?int $permissionBits = 0;
#[ORM\Column(name: 'created_date', type: 'datetime', nullable: false, options: ['default' => 'CURRENT_TIMESTAMP'])]
private \DateTimeInterface $createdDate;
#[ORM\Column(name: 'updated_date', type: 'datetime', nullable: false, options: ['default' => 'CURRENT_TIMESTAMP'])]
private \DateTimeInterface $updatedDate;
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: StdOptions::class)]
#[ORM\JoinColumn(name: 'option_id', referencedColumnName: 'id', nullable: false)]
private StdOptions $option;
#[ORM\JoinColumn(name: 'role_id', referencedColumnName: 'id')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\ManyToOne(targetEntity: 'StdRoles', inversedBy: 'optionsPermissions')]
private $role;
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $createdBy;
#[ORM\JoinColumn(name: 'updated_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $updatedBy;
public function __construct()
{
$this->createdDate = new \DateTimeImmutable();
$this->updatedDate = new \DateTimeImmutable();
$this->permissionBits = 0;
}
public function addPermission(int $permission): self
{
$this->permissionBits = RolesPermissions::add($this->permissionBits, $permission);
return $this;
}
public function removePermission(int $permission): self
{
$this->permissionBits = RolesPermissions::remove($this->permissionBits, $permission);
return $this;
}
public function hasPermission(int $permission): bool
{
return RolesPermissions::has($this->permissionBits, $permission);
}
public function getPermissionNames(): array
{
return RolesPermissions::toArray($this->permissionBits);
}
public function getCreatedDate(): \DateTimeInterface
{
return $this->createdDate;
}
public function setCreatedDate(\DateTimeInterface $createdDate): self
{
$this->createdDate = $createdDate;
return $this;
}
public function getUpdatedDate(): \DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
public function getRole(): ?StdRoles
{
return $this->role;
}
public function setRole(?StdRoles $role): self
{
$this->role = $role;
return $this;
}
public function getCreatedBy(): ?StdUsers
{
return $this->createdBy;
}
public function setCreatedBy(?StdUsers $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?StdUsers
{
return $this->updatedBy;
}
public function setUpdatedBy(?StdUsers $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getPermissionBits(): ?int
{
return $this->permissionBits;
}
public function setPermissionBits(?int $permissionBits): void
{
$this->permissionBits = $permissionBits;
}
public function getOption(): ?StdOptions
{
return $this->option;
}
public function setOption(?StdOptions $option): void
{
$this->option = $option;
}
}