src/Entity/Role.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\RoleRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassRoleRepository::class)]
  10. #[ApiResource(
  11.     normalizationContext: ['groups' => ['role']]
  12. )]
  13. class Role
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     #[Groups("role")]
  19.     private ?int $id null;
  20.     #[ORM\Column(length255)]
  21.     #[Groups("role")]
  22.     private ?string $nom null;
  23.     #[ORM\Column(length255)]
  24.     #[Groups("role")]
  25.     private ?string $code null;
  26.     #[ORM\OneToMany(mappedBy'role'targetEntityProfilDroitPage::class, orphanRemovaltrue)]
  27.     #[Groups("role")]
  28.     private Collection $profilDroitPages;
  29.     public function __construct()
  30.     {
  31.         $this->profilDroitPages = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getNom(): ?string
  38.     {
  39.         return $this->nom;
  40.     }
  41.     public function setNom(string $nom): static
  42.     {
  43.         $this->nom $nom;
  44.         return $this;
  45.     }
  46.     public function getCode(): ?string
  47.     {
  48.         return $this->code;
  49.     }
  50.     public function setCode(string $code): static
  51.     {
  52.         $this->code $code;
  53.         return $this;
  54.     }
  55.     /**
  56.      * @return Collection<int, ProfilDroitPage>
  57.      */
  58.     public function getProfilDroitPages(): Collection
  59.     {
  60.         return $this->profilDroitPages;
  61.     }
  62.     public function addProfilDroitPage(ProfilDroitPage $profilDroitPage): static
  63.     {
  64.         if (!$this->profilDroitPages->contains($profilDroitPage)) {
  65.             $this->profilDroitPages->add($profilDroitPage);
  66.             $profilDroitPage->setRole($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function removeProfilDroitPage(ProfilDroitPage $profilDroitPage): static
  71.     {
  72.         if ($this->profilDroitPages->removeElement($profilDroitPage)) {
  73.             // set the owning side to null (unless already changed)
  74.             if ($profilDroitPage->getRole() === $this) {
  75.                 $profilDroitPage->setRole(null);
  76.             }
  77.         }
  78.         return $this;
  79.     }
  80. }