<?php
namespace App\Entity;
use App\Repository\RolesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=RolesRepository::class)
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"name"})})
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"code"})})
*/
class Roles
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\NotBlank(message="Le nom du rôle est obligatoire")
*/
private $name;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\NotBlank(message="Le code du rôle est obligatoire")
*/
private $code;
/**
* @ORM\Column(type="boolean")
*/
private $status = true;
/**
* @ORM\Column(name="rank_level", type="integer", options={"default": 7})
* @Assert\Range(min=1, max=7, notInRangeMessage="Le rang doit etre compris entre 1 et 7")
*/
private $rank = 7;
/**
* @ORM\OneToMany(targetEntity=RolePermission::class, mappedBy="role", cascade={"persist", "remove"})
*/
private $rolePermissions;
public function __construct()
{
$this->rolePermissions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function isStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(int $rank): self
{
$this->rank = $rank;
return $this;
}
/**
* @return Collection<int, RolePermission>
*/
public function getRolePermissions(): Collection
{
return $this->rolePermissions;
}
public function addRolePermission(RolePermission $rolePermission): self
{
if (!$this->rolePermissions->contains($rolePermission)) {
$this->rolePermissions[] = $rolePermission;
$rolePermission->setRole($this);
}
return $this;
}
public function removeRolePermission(RolePermission $rolePermission): self
{
if ($this->rolePermissions->removeElement($rolePermission)) {
if ($rolePermission->getRole() === $this) {
$rolePermission->setRole(null);
}
}
return $this;
}
function __toString()
{
return $this->getName();
}
}