src/Entity/Privilege.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PrivilegeRepository;
  4. use App\Traits\TimeStampTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\HasLifecycleCallbacks]
  9. #[ORM\Entity(repositoryClassPrivilegeRepository::class)]
  10. class Privilege
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length50)]
  17.     private ?string $code null;
  18.     #[ORM\Column(length50nullabletrue)]
  19.     private ?string $name null;
  20.     #[ORM\Column(length50nullabletrue)]
  21.     private ?string $libelle null;
  22.     #[ORM\ManyToMany(targetEntityRole::class, mappedBy'privilege')]
  23.     private Collection $roles;
  24.     public function __construct()
  25.     {
  26.         $this->roles = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getCode(): ?string
  33.     {
  34.         return $this->code;
  35.     }
  36.     public function setCode(string $code): self
  37.     {
  38.         $this->code $code;
  39.         return $this;
  40.     }
  41.     public function getName(): ?string
  42.     {
  43.         return $this->name;
  44.     }
  45.     public function setName(?string $name): self
  46.     {
  47.         $this->name $name;
  48.         return $this;
  49.     }
  50.     public function getLibelle(): ?string
  51.     {
  52.         return $this->libelle;
  53.     }
  54.     public function setLibelle(?string $libelle): self
  55.     {
  56.         $this->libelle $libelle;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, Role>
  61.      */
  62.     public function getRoles(): Collection
  63.     {
  64.         return $this->roles;
  65.     }
  66.     public function addRole(Role $role): self
  67.     {
  68.         if (!$this->roles->contains($role)) {
  69.             $this->roles->add($role);
  70.             $role->addPrivilege($this);
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeRole(Role $role): self
  75.     {
  76.         if ($this->roles->removeElement($role)) {
  77.             $role->removePrivilege($this);
  78.         }
  79.         return $this;
  80.     }
  81.     public function __toString(): string
  82.     {
  83.         return $this->name;
  84.     }
  85. }