src/Entity/Pays.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use App\Repository\PaysRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassPaysRepository::class)]
  11. #[ApiResource(
  12.     operations: [
  13.         new GetCollection(
  14.             normalizationContext: [
  15.                 'groups' => ['read:pays:collection']
  16.             ]
  17.         )
  18.     ],
  19.     normalizationContext: [
  20.         'groups' => ['read:pays:collection']
  21.     ]
  22. )]
  23. class Pays
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     #[Groups(['read:course:item''read:user:item''read:pays:collection'])]
  29.     private ?int $id null;
  30.     #[ORM\Column(length255)]
  31.     #[Groups(['read:course:item''read:user:item''read:pays:collection'])]
  32.     private ?string $name null;
  33.     #[ORM\Column(length255)]
  34.     #[Groups(['read:course:item''read:user:item''read:pays:collection'])]
  35.     private ?string $slug null;
  36.     #[ORM\Column(length100)]
  37.     #[Groups(['read:course:item''read:user:item''read:pays:collection'])]
  38.     private ?string $code null;
  39.     #[ORM\OneToMany(mappedBy'pays'targetEntityPersonne::class)]
  40.     private Collection $personnes;
  41.     #[ORM\OneToMany(mappedBy'pays'targetEntityEtablissement::class, orphanRemovaltrue)]
  42.     private Collection $etablissements;
  43.     public function __construct()
  44.     {
  45.         $this->personnes = new ArrayCollection();
  46.         $this->etablissements = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): self
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     public function getSlug(): ?string
  62.     {
  63.         return $this->slug;
  64.     }
  65.     public function setSlug(string $slug): self
  66.     {
  67.         $this->slug $slug;
  68.         return $this;
  69.     }
  70.     public function getCode(): ?string
  71.     {
  72.         return $this->code;
  73.     }
  74.     public function setCode(string $code): self
  75.     {
  76.         $this->code $code;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @return Collection<int, Personne>
  81.      */
  82.     public function getPersonnes(): Collection
  83.     {
  84.         return $this->personnes;
  85.     }
  86.     public function addPersonne(Personne $personne): self
  87.     {
  88.         if (!$this->personnes->contains($personne)) {
  89.             $this->personnes->add($personne);
  90.             $personne->setPays($this);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removePersonne(Personne $personne): self
  95.     {
  96.         if ($this->personnes->removeElement($personne)) {
  97.             // set the owning side to null (unless already changed)
  98.             if ($personne->getPays() === $this) {
  99.                 $personne->setPays(null);
  100.             }
  101.         }
  102.         return $this;
  103.     }
  104.     /**
  105.      * @return Collection<int, Etablissement>
  106.      */
  107.     public function getEtablissements(): Collection
  108.     {
  109.         return $this->etablissements;
  110.     }
  111.     public function addEtablissement(Etablissement $etablissement): self
  112.     {
  113.         if (!$this->etablissements->contains($etablissement)) {
  114.             $this->etablissements->add($etablissement);
  115.             $etablissement->setPays($this);
  116.         }
  117.         return $this;
  118.     }
  119.     public function removeEtablissement(Etablissement $etablissement): self
  120.     {
  121.         if ($this->etablissements->removeElement($etablissement)) {
  122.             // set the owning side to null (unless already changed)
  123.             if ($etablissement->getPays() === $this) {
  124.                 $etablissement->setPays(null);
  125.             }
  126.         }
  127.         return $this;
  128.     }
  129. }