<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\CountryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"country:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"country:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
* },
* attributes={
* "pagination_enabled"=false,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
* @ApiFilter(SearchFilter::class, properties={
* "name": "exact"
* })
* @ORM\Entity(repositoryClass=CountryRepository::class)
*
*/
class Country
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "country:read",
* "candidate:read",
* "property:read",
* "agent:read",
* "city:read",
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({
* "country:read",
* "candidate:read",
* "property:read",
* "agent:read",
* "city:read",
* })
*/
private ?string $name;
/**
* @ORM\ManyToOne(targetEntity=Language::class, inversedBy="countries")
* @ORM\JoinColumn(nullable=true)
*/
private ?Language $language;
/**
* @ORM\ManyToOne(targetEntity=Currency::class, inversedBy="countries")
* @ORM\JoinColumn(nullable=true)
*/
private ?Currency $currency;
/**
* @ORM\OneToMany(targetEntity=City::class, mappedBy="country")
*/
private $cities;
public function __construct()
{
$this->cities = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLanguage(): ?Language
{
return $this->language;
}
public function setLanguage(?Language $language): self
{
$this->language = $language;
return $this;
}
public function getCurrency(): ?Currency
{
return $this->currency;
}
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
/**
* @return Collection<int, City>
*/
public function getCities(): Collection
{
return $this->cities;
}
public function addCity(City $city): self
{
if (!$this->cities->contains($city)) {
$this->cities[] = $city;
$city->setCountry($this);
}
return $this;
}
public function removeCity(City $city): self
{
if ($this->cities->removeElement($city)) {
// set the owning side to null (unless already changed)
if ($city->getCountry() === $this) {
$city->setCountry(null);
}
}
return $this;
}
}