<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiSubresource;
use App\Repository\CityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"city:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"city:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get"
* },
* attributes={
* "pagination_enabled"=false,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} },
* "order"={"rank", "name"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={
* "name":"ipartial",
* "id":"exact",
* })
* @ORM\Entity(repositoryClass=CityRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class City
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "directory:collaborator:search",
* "directory:people:search",
* "city:read",
* "contact:read",
* "candidate:read",
* "property:read",
* "mandate:read",
* "sector:read",
* "prescriber:read",
* "agent:read",
* "transaction-item:read",
* "mandate:read",
* "property-visit:read",
* "milkiya:read",
* "business-indication:item:read",
* "read:matching"
*
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "directory:collaborator:search",
* "directory:people:search",
* "candidate:read",
* "city:read",
* "contact:read",
* "property:read",
* "mandate:read",
* "sector:read",
* "prescriber:read",
* "recommandation:read",
* "agent:read",
* "transaction-item:read",
* "mandate:read",
* "property-visit:read",
* "milkiya:read",
* "business-indication:item:read",
* "read:matching"
* })
*/
private ?string $name;
/**
* @ORM\OneToMany(targetEntity=Address::class, mappedBy="city", orphanRemoval=true)
*/
private $addresses;
/**
* @ORM\OneToMany(targetEntity=PropertyAddress::class, mappedBy="city")
*/
private $propertyAddresses;
/**
* @ORM\ManyToOne(targetEntity=Country::class, inversedBy="cities")
* @Groups({
* "city:read",
* "agent:read"
* })
* @ORM\JoinColumn(nullable=false)
* @ApiProperty(readableLink=true)
*/
private ?Country $country;
/**
* @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
*/
private $latitude;
/**
* @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
*/
private $longitude;
/**
* @Groups({
* "city:read",
* "contact:read",
* "candidate:read",
* "agent:read",
* "abstract-collaborator:read",
* })
* @ORM\OneToMany(targetEntity=Neighborhood::class, mappedBy="city")
* @ApiSubresource()
*/
private $neighborhoods;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $rank;
public function __construct()
{
$this->addresses = new ArrayCollection();
$this->propertyAddresses = new ArrayCollection();
$this->neighborhoods = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id): self
{
$this->id = $id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Address[]
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function addAddress(Address $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses[] = $address;
$address->setCity($this);
}
return $this;
}
public function removeAddress(Address $address): self
{
// set the owning side to null (unless already changed)
if ($this->addresses->removeElement($address) && $address->getCity() === $this) {
$address->setCity(null);
}
return $this;
}
/**
* @return Collection|PropertyAddress[]
*/
public function getPropertyAddresses(): Collection
{
return $this->propertyAddresses;
}
public function addPropertyAddress(PropertyAddress $propertyAddress): self
{
if (!$this->propertyAddresses->contains($propertyAddress)) {
$this->propertyAddresses[] = $propertyAddress;
$propertyAddress->setCity($this);
}
return $this;
}
public function removePropertyAddress(PropertyAddress $propertyAddress): self
{
// set the owning side to null (unless already changed)
if ($this->propertyAddresses->removeElement($propertyAddress) && $propertyAddress->getCity() === $this) {
$propertyAddress->setCity(null);
}
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function getLatitude(): ?string
{
return $this->latitude;
}
public function setLatitude(?string $latitude): self
{
$this->latitude = $latitude;
return $this;
}
public function getLongitude(): ?string
{
return $this->longitude;
}
public function setLongitude(string $longitude): self
{
$this->longitude = $longitude;
return $this;
}
/**
* @return Collection<int, Neighborhood>
*/
public function getNeighborhoods(): Collection
{
return $this->neighborhoods;
}
public function addNeighborhood(Neighborhood $neighborhood): self
{
if (!$this->neighborhoods->contains($neighborhood)) {
$this->neighborhoods[] = $neighborhood;
$neighborhood->setCity($this);
}
return $this;
}
public function removeNeighborhood(Neighborhood $neighborhood): self
{
// set the owning side to null (unless already changed)
if ($this->neighborhoods->removeElement($neighborhood) && $neighborhood->getCity() === $this) {
$neighborhood->setCity(null);
}
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(?int $rank): self
{
$this->rank = $rank;
return $this;
}
}