src/Entity/Language.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\LanguageRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ApiResource(
  10.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  11.  *     normalizationContext={"groups"={"language:read"}, "swagger_definition_name"="Read"},
  12.  *     denormalizationContext={"groups"={"language:write"}, "swagger_definition_name"="Write"},
  13.  *     itemOperations={
  14.  *          "get"
  15.  *     },
  16.  *     collectionOperations={
  17.  *           "get",
  18.  *
  19.  *     },
  20.  *     attributes={
  21.  *          "pagination_items_per_page"=10,
  22.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  23.  *     }
  24.  * )
  25.  * @ORM\Entity(repositoryClass=LanguageRepository::class)
  26.  */
  27. class Language
  28. {
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $name;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity=Country::class, mappedBy="language")
  41.      */
  42.     private $countries;
  43.     public function __construct()
  44.     {
  45.         $this->countries = new ArrayCollection();
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getName(): ?string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function setName(string $name): self
  56.     {
  57.         $this->name $name;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @return Collection|Country[]
  62.      */
  63.     public function getCountries(): Collection
  64.     {
  65.         return $this->countries;
  66.     }
  67.     public function addCountry(Country $country): self
  68.     {
  69.         if (!$this->countries->contains($country)) {
  70.             $this->countries[] = $country;
  71.             $country->setLanguage($this);
  72.         }
  73.         return $this;
  74.     }
  75.     public function removeCountry(Country $country): self
  76.     {
  77.         // set the owning side to null (unless already changed)
  78.         if ($this->countries->removeElement($country) && $country->getLanguage() === $this) {
  79.             $country->setLanguage(null);
  80.         }
  81.         return $this;
  82.     }
  83. }