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.         public function getId(): ?string
  73.         {
  74.             return $this->id;
  75.         }
  76.         public function getName(): ?string
  77.         {
  78.             return $this->name;
  79.         }
  80.         public function setName(string $name): static
  81.         {
  82.             $this->name $name;
  83.             return $this;
  84.         }
  85.         public function getProvince(): ?Province
  86.         {
  87.             return $this->province;
  88.         }
  89.         public function setProvince(?Province $province): static
  90.         {
  91.             $this->province $province;
  92.             return $this;
  93.         }
  94.         public function getRegion(): ?Region
  95.         {
  96.             return $this->region;
  97.         }
  98.         public function setRegion(?Region $region): static
  99.         {
  100.             $this->region $region;
  101.             return $this;
  102.         }
  103.         /**
  104.          * @return Collection<int, Address>
  105.          */
  106.         public function getAddresses(): Collection
  107.         {
  108.             return $this->addresses;
  109.         }
  110.         public function addAddress(Address $address): static
  111.         {
  112.             if (!$this->addresses->contains($address)) {
  113.                 $this->addresses->add($address);
  114.                 $address->setCity($this);
  115.             }
  116.             return $this;
  117.         }
  118.         public function removeAddress(Address $address): static
  119.         {
  120.             if ($this->addresses->removeElement($address)) {
  121.                 // set the owning side to null (unless already changed)
  122.                 if ($address->getCity() === $this) {
  123.                     $address->setCity(null);
  124.                 }
  125.             }
  126.             return $this;
  127.         }
  128.         /**
  129.          * @return Collection<int, CityAlias>
  130.          */
  131.         public function getAliases(): Collection
  132.         {
  133.             return $this->aliases;
  134.         }
  135.         public function addAlias(CityAlias $alias): static
  136.         {
  137.             if (!$this->aliases->contains($alias)) {
  138.                 $this->aliases->add($alias);
  139.                 $alias->setCity($this);
  140.             }
  141.             return $this;
  142.         }
  143.         public function removeAlias(CityAlias $alias): static
  144.         {
  145.             if ($this->aliases->removeElement($alias)) {
  146.                 // set the owning side to null (unless already changed)
  147.                 if ($alias->getCity() === $this) {
  148.                     $alias->setCity(null);
  149.                 }
  150.             }
  151.             return $this;
  152.         }
  153.         /**
  154.          * @return Collection<int, Zip>
  155.          */
  156.         public function getZips(): Collection
  157.         {
  158.             return $this->zips;
  159.         }
  160.         public function addZip(Zip $zip): static
  161.         {
  162.             if (!$this->zips->contains($zip)) {
  163.                 $this->zips->add($zip);
  164.                 $zip->addCity($this);
  165.             }
  166.             return $this;
  167.         }
  168.         public function removeZip(Zip $zip): static
  169.         {
  170.             if ($this->zips->removeElement($zip)) {
  171.                 $zip->removeCity($this);
  172.             }
  173.             return $this;
  174.         }
  175. }