src/Entity/Role.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RoleRepository;
  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\Entity(repositoryClassRoleRepository::class)]
  9. #[ORM\HasLifecycleCallbacks]
  10. class Role
  11. {
  12.     use TimeStampTrait;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length50)]
  18.     private ?string $code null;
  19.     #[ORM\Column(length50nullabletrue)]
  20.     private ?string $name null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?bool $status null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $description null;
  25.     #[ORM\ManyToMany(targetEntityPrivilege::class, inversedBy'roles')]
  26.     private Collection $privilege;
  27.     #[ORM\OneToMany(mappedBy'role'targetEntityUser::class)]
  28.     private Collection $users;
  29.     #[ORM\ManyToOne(inversedBy'roles')]
  30.     private ?Entreprise $marchand null;
  31.     public function __construct()
  32.     {
  33.         $this->privilege = new ArrayCollection();
  34.         $this->users = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getCode(): ?string
  41.     {
  42.         return $this->code;
  43.     }
  44.     public function setCode(string $code): self
  45.     {
  46.         $this->code $code;
  47.         return $this;
  48.     }
  49.     public function getName(): ?string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function setName(?string $name): self
  54.     {
  55.         $this->name $name;
  56.         return $this;
  57.     }
  58.     public function isStatus(): ?bool
  59.     {
  60.         return $this->status;
  61.     }
  62.     public function setStatus(?bool $status): self
  63.     {
  64.         $this->status $status;
  65.         return $this;
  66.     }
  67.     public function getDescription(): ?string
  68.     {
  69.         return $this->description;
  70.     }
  71.     public function setDescription(?string $description): self
  72.     {
  73.         $this->description $description;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection<int, Privilege>
  78.      */
  79.     public function getPrivilege(): Collection
  80.     {
  81.         return $this->privilege;
  82.     }
  83.     public function addPrivilege(Privilege $privilege): self
  84.     {
  85.         if (!$this->privilege->contains($privilege)) {
  86.             $this->privilege->add($privilege);
  87.         }
  88.         return $this;
  89.     }
  90.     public function removePrivilege(Privilege $privilege): self
  91.     {
  92.         $this->privilege->removeElement($privilege);
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, User>
  97.      */
  98.     public function getUsers(): Collection
  99.     {
  100.         return $this->users;
  101.     }
  102.     public function addUser(User $user): self
  103.     {
  104.         if (!$this->users->contains($user)) {
  105.             $this->users->add($user);
  106.             $user->setRole($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeUser(User $user): self
  111.     {
  112.         if ($this->users->removeElement($user)) {
  113.             // set the owning side to null (unless already changed)
  114.             if ($user->getRole() === $this) {
  115.                 $user->setRole(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     public function __toString(): string
  121.     {
  122.         return $this->name;
  123.     }
  124.     public function getMarchand(): ?Entreprise
  125.     {
  126.         return $this->marchand;
  127.     }
  128.     public function setMarchand(?Entreprise $marchand): static
  129.     {
  130.         $this->marchand $marchand;
  131.         return $this;
  132.     }
  133. }