src\Entity\Role.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use App\Repository\RoleRepository;
  8. #[ORM\Entity(repositoryClass: RoleRepository::class)]
  9. #[ORM\Table(name: '`role`')]
  10. #[UniqueEntity(fields: ['libelle'], message: 'Le nom du rôle existe déjà')]
  11. class Role {
  12. #[ORM\Id]
  13. #[ORM\Column(type:"integer")]
  14. private ?int $role_id = null;
  15. #[ORM\Column(type:"string",length: 50, unique: true,nullable:false)]
  16. private ?string $libelle = null;
  17. #[ORM\OneToMany(targetEntity: Possede::class, mappedBy: 'role_id', orphanRemoval: true, cascade: ['persist'])]
  18. private Collection $possede;
  19. public function __construct() {
  20. $this->possede = new ArrayCollection();
  21. }
  22. public function getRoleId(): ?int
  23. {
  24. return $this->role_id;
  25. }
  26. public function setRoleId(int $role_id): static
  27. {
  28. $this->role_id = $role_id;
  29. return $this;
  30. }
  31. public function getLibelle(): ?string
  32. {
  33. return $this->libelle;
  34. }
  35. public function setLibelle(string $libelle): static
  36. {
  37. $this->libelle = $libelle;
  38. return $this;
  39. }
  40. /**
  41. * @return Collection<int, Possede>
  42. */
  43. public function getPossedes(): Collection
  44. {
  45. return $this->possede;
  46. }
  47. public function addPossede(Possede $possede): static {
  48. if (!$this->possede->contains($possede)) {
  49. $this->possede->add($possede);
  50. $possede->setRoleId($this);
  51. }
  52. return $this;
  53. }
  54. public function removePossede(Possede $possede): static {
  55. if ($this->possede->removeElement($possede)) {
  56. // set the owning side to null (unless already changed)
  57. if ($possede->getRoleId() === $this) {
  58. $possede->setRoleId(null);
  59. }
  60. }
  61. return $this;
  62. }
  63. }