<?php
namespace App\Entity\Master;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_m_city")
* @ORM\Entity(repositoryClass="App\Repository\Master\CityRepository")
*/
class City
{
public function __toString(){
return $this->name.' ('.$this->province->getSign().')';
}
public function displayZips(){
$first = true;
$zips = '';
foreach($this->getZips() as $zip){
if($first) $first = false; else $zips.= ',';
$zips .= $zip->getCode();
}
return $zips;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=191)
*/
protected $name;
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Master\Province", inversedBy="cities")
* @ORM\JoinColumn(name="province_id", referencedColumnName="id")
*/
private $province;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Master\Region", inversedBy="cities")
* @ORM\JoinColumn(name="region_id", referencedColumnName="id")
*/
private $region;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\Address", mappedBy="city")
*/
private $addresses;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\CityAlias", mappedBy="city")
*/
private $aliases;
//
// ManyToMany
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Master\Zip", mappedBy="cities")
*/
private $zips;
public function __construct()
{
$this->addresses = new ArrayCollection();
$this->aliases = new ArrayCollection();
$this->zips = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getProvince(): ?Province
{
return $this->province;
}
public function setProvince(?Province $province): self
{
$this->province = $province;
return $this;
}
public function getRegion(): ?Region
{
return $this->region;
}
public function setRegion(?Region $region): self
{
$this->region = $region;
return $this;
}
/**
* @return Collection<int, Address>
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function addAddress(Address $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses->add($address);
$address->setCity($this);
}
return $this;
}
public function removeAddress(Address $address): self
{
if ($this->addresses->removeElement($address)) {
// set the owning side to null (unless already changed)
if ($address->getCity() === $this) {
$address->setCity(null);
}
}
return $this;
}
/**
* @return Collection<int, CityAlias>
*/
public function getAliases(): Collection
{
return $this->aliases;
}
public function addAlias(CityAlias $alias): self
{
if (!$this->aliases->contains($alias)) {
$this->aliases->add($alias);
$alias->setCity($this);
}
return $this;
}
public function removeAlias(CityAlias $alias): self
{
if ($this->aliases->removeElement($alias)) {
// set the owning side to null (unless already changed)
if ($alias->getCity() === $this) {
$alias->setCity(null);
}
}
return $this;
}
/**
* @return Collection<int, Zip>
*/
public function getZips(): Collection
{
return $this->zips;
}
public function addZip(Zip $zip): self
{
if (!$this->zips->contains($zip)) {
$this->zips->add($zip);
$zip->addCity($this);
}
return $this;
}
public function removeZip(Zip $zip): self
{
if ($this->zips->removeElement($zip)) {
$zip->removeCity($this);
}
return $this;
}
}