src/Entity/Country.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use App\Repository\CountryRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. /**
  12.  * @ApiResource(
  13.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  14.  *     normalizationContext={"groups"={"country:read"}, "swagger_definition_name"="Read"},
  15.  *     denormalizationContext={"groups"={"country:write"}, "swagger_definition_name"="Write"},
  16.  *     itemOperations={
  17.  *          "get"
  18.  *     },
  19.  *     collectionOperations={
  20.  *          "get",
  21.  *     },
  22.  *     attributes={
  23.  *          "pagination_enabled"=false,
  24.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  25.  *     }
  26.  * )
  27.  * @ApiFilter(SearchFilter::class, properties={
  28.  *     "name": "exact"
  29.  * })
  30.  * @ORM\Entity(repositoryClass=CountryRepository::class)
  31.  *
  32.  */
  33. class Country
  34. {
  35.     /**
  36.      * @ORM\Id
  37.      * @ORM\GeneratedValue
  38.      * @ORM\Column(type="integer")
  39.      * @Groups({
  40.      *     "country:read",
  41.      *     "candidate:read",
  42.      *     "property:read",
  43.      *     "agent:read",
  44.      *     "city:read",
  45.      * })
  46.      */
  47.     private $id;
  48.     /**
  49.      * @ORM\Column(type="string", length=255)
  50.      * @Groups({
  51.      *     "country:read",
  52.      *     "candidate:read",
  53.      *     "property:read",
  54.      *     "agent:read",
  55.      *     "city:read",
  56.      * })
  57.      */
  58.     private ?string $name;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=Language::class, inversedBy="countries")
  61.      * @ORM\JoinColumn(nullable=true)
  62.      */
  63.     private ?Language $language;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=Currency::class, inversedBy="countries")
  66.      * @ORM\JoinColumn(nullable=true)
  67.      */
  68.     private ?Currency $currency;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity=City::class, mappedBy="country")
  71.      */
  72.     private $cities;
  73.     public function __construct()
  74.     {
  75.         $this->cities = new ArrayCollection();
  76.     }
  77.     public function getId(): ?int
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getName(): ?string
  82.     {
  83.         return $this->name;
  84.     }
  85.     public function setName(string $name): self
  86.     {
  87.         $this->name $name;
  88.         return $this;
  89.     }
  90.     public function getLanguage(): ?Language
  91.     {
  92.         return $this->language;
  93.     }
  94.     public function setLanguage(?Language $language): self
  95.     {
  96.         $this->language $language;
  97.         return $this;
  98.     }
  99.     public function getCurrency(): ?Currency
  100.     {
  101.         return $this->currency;
  102.     }
  103.     public function setCurrency(?Currency $currency): self
  104.     {
  105.         $this->currency $currency;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection<int, City>
  110.      */
  111.     public function getCities(): Collection
  112.     {
  113.         return $this->cities;
  114.     }
  115.     public function addCity(City $city): self
  116.     {
  117.         if (!$this->cities->contains($city)) {
  118.             $this->cities[] = $city;
  119.             $city->setCountry($this);
  120.         }
  121.         return $this;
  122.     }
  123.     public function removeCity(City $city): self
  124.     {
  125.         if ($this->cities->removeElement($city)) {
  126.             // set the owning side to null (unless already changed)
  127.             if ($city->getCountry() === $this) {
  128.                 $city->setCountry(null);
  129.             }
  130.         }
  131.         return $this;
  132.     }
  133. }