src/Entity/Langue.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\LangueRepository;
  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. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassLangueRepository::class)]
  11. #[ApiResource(
  12.     normalizationContext: ['groups' => ['read','profile']],
  13.     denormalizationContext: ['groups' => ['profile']],
  14. )]
  15. class Langue
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     #[Groups(["read","profile"])]
  21.     private ?int $id null;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     #[Assert\NotBlank]
  24.     #[Groups(["read","profile"])]
  25.     private ?string $title null;
  26.     
  27.     #[ORM\ManyToMany(targetEntityProfile::class, mappedBy'langues')]
  28.     private Collection $profiles;
  29.     #[ORM\OneToMany(mappedBy'langue'targetEntityLangueTranslation::class, cascade: ["persist"])]
  30.     #[Groups("read")]
  31.     private Collection $translations;
  32.     public function __construct()
  33.     {
  34.         $this->profiles = new ArrayCollection();
  35.         $this->translations = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.    
  42.     public function getTitle(): ?string
  43.     {
  44.         return $this->title;
  45.     }
  46.     public function setTitle(?string $title): self
  47.     {
  48.         $this->title $title;
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return Collection<int, Profile>
  53.      */
  54.     public function getProfiles(): Collection
  55.     {
  56.         return $this->profiles;
  57.     }
  58.     public function addProfile(Profile $profile): self
  59.     {
  60.         if (!$this->profiles->contains($profile)) {
  61.             $this->profiles->add($profile);
  62.             $profile->addLangue($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function removeProfile(Profile $profile): self
  67.     {
  68.         if ($this->profiles->removeElement($profile)) {
  69.             $profile->removeLangue($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function __toString()
  74.     {
  75.         return $this->title;
  76.     }
  77.     /**
  78.      * @return Collection<int, LangueTranslation>
  79.      */
  80.     public function getTranslations(): Collection
  81.     {
  82.         return $this->translations;
  83.     }
  84.     public function addTranslation(LangueTranslation $translation): self
  85.     {
  86.         if (!$this->translations->contains($translation)) {
  87.             $this->translations->add($translation);
  88.             $translation->setLangue($this);
  89.         }
  90.         return $this;
  91.     }
  92.     public function removeTranslation(LangueTranslation $translation): self
  93.     {
  94.         if ($this->translations->removeElement($translation)) {
  95.             // set the owning side to null (unless already changed)
  96.             if ($translation->getLangue() === $this) {
  97.                 $translation->setLangue(null);
  98.             }
  99.         }
  100.         return $this;
  101.     }
  102.  
  103. }