<?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_zip")
* @ORM\Entity(repositoryClass="App\Repository\Master\ZipRepository"))
*/
class Zip
{
public function displayCodeAndCities(){
$cities = '';
$first = true;
foreach($this->getCities() as $city){
if($first) $first = false; else $cities.= ', ';
$cities.= $city->getName();
}
return $this->code.' - '.$cities;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="code", type="string", length=191)
*/
protected $code;
// ManyToMany
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Master\City", inversedBy="zips")
* @ORM\JoinTable(name="eposm_m_join_table_city_zip")
*/
private $cities;
public function __construct()
{
$this->cities = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
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->add($city);
}
return $this;
}
public function removeCity(City $city): self
{
$this->cities->removeElement($city);
return $this;
}
}