src/Entity/Roles.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RolesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  * @ORM\Entity(repositoryClass=RolesRepository::class)
  11.  *  @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"name"})})
  12.  *  @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"code"})})
  13.  */
  14. class Roles
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, unique=true)
  24.      * @Assert\NotBlank(message="Le nom du rôle est obligatoire")
  25.      */
  26.     private $name;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, unique=true)
  29.      * @Assert\NotBlank(message="Le code du rôle est obligatoire")
  30.      */
  31.     private $code;
  32.     /**
  33.      * @ORM\Column(type="boolean")
  34.      */
  35.     private $status true;
  36.     /**
  37.      * @ORM\Column(name="rank_level", type="integer", options={"default": 7})
  38.      * @Assert\Range(min=1, max=7, notInRangeMessage="Le rang doit etre compris entre 1 et 7")
  39.      */
  40.     private $rank 7;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity=RolePermission::class, mappedBy="role", cascade={"persist", "remove"})
  43.      */
  44.     private $rolePermissions;
  45.     public function __construct()
  46.     {
  47.         $this->rolePermissions = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.  
  54.     public function getName(): ?string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function setName(string $name): self
  59.     {
  60.         $this->name $name;
  61.         return $this;
  62.     }
  63.     public function getCode(): ?string
  64.     {
  65.         return $this->code;
  66.     }
  67.     public function setCode(string $code): self
  68.     {
  69.         $this->code $code;
  70.         return $this;
  71.     }
  72.     public function isStatus(): ?bool
  73.     {
  74.         return $this->status;
  75.     }
  76.     public function setStatus(bool $status): self
  77.     {
  78.         $this->status $status;
  79.         return $this;
  80.     }
  81.     public function getRank(): ?int
  82.     {
  83.         return $this->rank;
  84.     }
  85.     public function setRank(int $rank): self
  86.     {
  87.         $this->rank $rank;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Collection<int, RolePermission>
  92.      */
  93.     public function getRolePermissions(): Collection
  94.     {
  95.         return $this->rolePermissions;
  96.     }
  97.     public function addRolePermission(RolePermission $rolePermission): self
  98.     {
  99.         if (!$this->rolePermissions->contains($rolePermission)) {
  100.             $this->rolePermissions[] = $rolePermission;
  101.             $rolePermission->setRole($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeRolePermission(RolePermission $rolePermission): self
  106.     {
  107.         if ($this->rolePermissions->removeElement($rolePermission)) {
  108.             if ($rolePermission->getRole() === $this) {
  109.                 $rolePermission->setRole(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114.     function __toString()
  115.     {
  116.         return $this->getName();
  117.     }
  118. }