src/Entity/Master/Zip.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_zip")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Master\ZipRepository"))
  10.  */
  11. class Zip
  12. {    
  13.     public function displayCodeAndCities(){
  14.         $cities '';
  15.         $first true;
  16.         foreach($this->getCities() as $city){
  17.             if($first$first false; else $cities.= ', ';
  18.             $cities.= $city->getName();
  19.         }
  20.         return $this->code.' - '.$cities;
  21.     }
  22.     /**
  23.      * @ORM\Column(name="id", type="bigint")
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      */
  27.     protected $id;
  28.     
  29.     /**
  30.      * @ORM\Column(name="code", type="string", length=191)
  31.      */
  32.     protected $code;
  33.     
  34.     // ManyToMany
  35.         /**
  36.          * @ORM\ManyToMany(targetEntity="App\Entity\Master\City", inversedBy="zips")
  37.          * @ORM\JoinTable(name="eposm_m_join_table_city_zip")
  38.          */
  39.         private $cities;
  40.         public function __construct()
  41.         {
  42.             $this->cities = new ArrayCollection();
  43.         }
  44.     //
  45.     public function getId(): ?string
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getCode(): ?string
  50.     {
  51.         return $this->code;
  52.     }
  53.     public function setCode(string $code): self
  54.     {
  55.         $this->code $code;
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection<int, City>
  60.      */
  61.     public function getCities(): Collection
  62.     {
  63.         return $this->cities;
  64.     }
  65.     public function addCity(City $city): self
  66.     {
  67.         if (!$this->cities->contains($city)) {
  68.             $this->cities->add($city);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeCity(City $city): self
  73.     {
  74.         $this->cities->removeElement($city);
  75.         return $this;
  76.     }
  77. }