src/Entity/Master/City.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Master;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Table(name="eposm_m_city")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Master\CityRepository")
  10.  */
  11. class City
  12. {    
  13.     public function __toString(){
  14.         return $this->name.' ('.$this->province->getSign().')';
  15.     }
  16.     public function displayZips(){
  17.         $first true;
  18.         $zips '';
  19.         foreach($this->getZips() as $zip){
  20.             if($first$first false; else $zips.= ',';
  21.             $zips .= $zip->getCode();
  22.         }
  23.         return $zips;
  24.     }
  25.     
  26.     /**
  27.      * @ORM\Column(name="id", type="bigint")
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue(strategy="AUTO")
  30.      */
  31.     protected $id;
  32.     
  33.     /**
  34.      * @ORM\Column(name="name", type="string", length=191)
  35.      */
  36.     protected $name;
  37.     // ManyToOne
  38.         /**
  39.          * @ORM\ManyToOne(targetEntity="App\Entity\Master\Province", inversedBy="cities")
  40.          * @ORM\JoinColumn(name="province_id", referencedColumnName="id")
  41.          */
  42.         private $province;
  43.         
  44.         /**
  45.          * @ORM\ManyToOne(targetEntity="App\Entity\Master\Region", inversedBy="cities")
  46.          * @ORM\JoinColumn(name="region_id", referencedColumnName="id")
  47.          */
  48.         private $region;
  49.     //
  50.     // OneToMany
  51.         /**
  52.          * @ORM\OneToMany(targetEntity="App\Entity\Master\Address", mappedBy="city")
  53.          */
  54.         private $addresses;
  55.         
  56.         /**
  57.          * @ORM\OneToMany(targetEntity="App\Entity\Master\CityAlias", mappedBy="city")
  58.          */
  59.         private $aliases;
  60.     //
  61.     // ManyToMany
  62.         /**
  63.          * @ORM\ManyToMany(targetEntity="App\Entity\Master\Zip", mappedBy="cities")
  64.          */
  65.         private $zips;
  66.         public function __construct()
  67.         {
  68.             $this->addresses = new ArrayCollection();
  69.             $this->aliases = new ArrayCollection();
  70.             $this->zips = new ArrayCollection();
  71.         }
  72.     //
  73.     public function getId(): ?string
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getName(): ?string
  78.     {
  79.         return $this->name;
  80.     }
  81.     public function setName(string $name): self
  82.     {
  83.         $this->name $name;
  84.         return $this;
  85.     }
  86.     public function getProvince(): ?Province
  87.     {
  88.         return $this->province;
  89.     }
  90.     public function setProvince(?Province $province): self
  91.     {
  92.         $this->province $province;
  93.         return $this;
  94.     }
  95.     public function getRegion(): ?Region
  96.     {
  97.         return $this->region;
  98.     }
  99.     public function setRegion(?Region $region): self
  100.     {
  101.         $this->region $region;
  102.         return $this;
  103.     }
  104.     /**
  105.      * @return Collection<int, Address>
  106.      */
  107.     public function getAddresses(): Collection
  108.     {
  109.         return $this->addresses;
  110.     }
  111.     public function addAddress(Address $address): self
  112.     {
  113.         if (!$this->addresses->contains($address)) {
  114.             $this->addresses->add($address);
  115.             $address->setCity($this);
  116.         }
  117.         return $this;
  118.     }
  119.     public function removeAddress(Address $address): self
  120.     {
  121.         if ($this->addresses->removeElement($address)) {
  122.             // set the owning side to null (unless already changed)
  123.             if ($address->getCity() === $this) {
  124.                 $address->setCity(null);
  125.             }
  126.         }
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return Collection<int, CityAlias>
  131.      */
  132.     public function getAliases(): Collection
  133.     {
  134.         return $this->aliases;
  135.     }
  136.     public function addAlias(CityAlias $alias): self
  137.     {
  138.         if (!$this->aliases->contains($alias)) {
  139.             $this->aliases->add($alias);
  140.             $alias->setCity($this);
  141.         }
  142.         return $this;
  143.     }
  144.     public function removeAlias(CityAlias $alias): self
  145.     {
  146.         if ($this->aliases->removeElement($alias)) {
  147.             // set the owning side to null (unless already changed)
  148.             if ($alias->getCity() === $this) {
  149.                 $alias->setCity(null);
  150.             }
  151.         }
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection<int, Zip>
  156.      */
  157.     public function getZips(): Collection
  158.     {
  159.         return $this->zips;
  160.     }
  161.     public function addZip(Zip $zip): self
  162.     {
  163.         if (!$this->zips->contains($zip)) {
  164.             $this->zips->add($zip);
  165.             $zip->addCity($this);
  166.         }
  167.         return $this;
  168.     }
  169.     public function removeZip(Zip $zip): self
  170.     {
  171.         if ($this->zips->removeElement($zip)) {
  172.             $zip->removeCity($this);
  173.         }
  174.         return $this;
  175.     }
  176. }