<?php
declare(strict_types=1);
namespace Crea\ToolsBundle\Entity\Geographic;
use Crea\ToolsBundle\Repository\Geographic\CityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CityRepository::class)
*
* @ORM\Table(
* name="geographic_city",
* indexes={
*
* @ORM\Index(name="geographic_city_place", columns={"country_id", "place"}),
* @ORM\Index(name="geographic_city_zipcode", columns={"country_id", "zipcode"})
* }
* )
*/
class City implements \Stringable
{
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id;
/**
* @ORM\ManyToOne(targetEntity="Crea\ToolsBundle\Entity\Geographic\Country", inversedBy="cities")
*
* @ORM\JoinColumn(nullable=false)
*/
private Country $country;
/**
* @ORM\Column(type="string", nullable=false)
*/
private string $zipcode;
/**
* @ORM\Column(type="string", nullable=false)
*/
private string $place;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $state = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $stateCode = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $province = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $provinceCode = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $community = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $communityCode = null;
/**
* @ORM\Column(type="string", nullable=false)
*/
private string $latitude;
/**
* @ORM\Column(type="string", nullable=false)
*/
private string $longitude;
/**
* @var Collection<int, Address>
*
* @ORM\OneToMany(targetEntity=Address::class, mappedBy="city")
*/
private Collection $addresses;
public function __construct()
{
$this->addresses = new ArrayCollection();
}
public function __toString(): string
{
return $this->getZipcode().' '.$this->getPlace().' - '.$this->getCountry();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(?int $id): self
{
$this->id = $id;
return $this;
}
public function getCountry(): Country
{
return $this->country;
}
public function setCountry(Country $country): self
{
$this->country = $country;
return $this;
}
public function getZipcode(): string
{
return $this->zipcode;
}
public function setZipcode(string $zipcode): self
{
$this->zipcode = $zipcode;
return $this;
}
public function getPlace(): string
{
return $this->place;
}
public function setPlace(string $place): self
{
$this->place = $place;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
public function getStateCode(): ?string
{
return $this->stateCode;
}
public function setStateCode(?string $stateCode): self
{
$this->stateCode = $stateCode;
return $this;
}
public function getProvince(): ?string
{
return $this->province;
}
public function setProvince(?string $province): self
{
$this->province = $province;
return $this;
}
public function getProvinceCode(): ?string
{
return $this->provinceCode;
}
public function setProvinceCode(?string $provinceCode): self
{
$this->provinceCode = $provinceCode;
return $this;
}
public function getCommunity(): ?string
{
return $this->community;
}
public function setCommunity(?string $community): self
{
$this->community = $community;
return $this;
}
public function getCommunityCode(): ?string
{
return $this->communityCode;
}
public function setCommunityCode(?string $communityCode): self
{
$this->communityCode = $communityCode;
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, Address>
*/
public function getAddresses()
{
return $this->addresses;
}
/**
* @param Collection<int, Address> $addresses
*/
public function setAddresses(Collection $addresses): self
{
$this->addresses = $addresses;
return $this;
}
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
{
if ($this->addresses->removeElement($address)) {
if ($address->getCity() === $this) {
$address->setCity(null);
}
}
return $this;
}
}