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.         public function getId(): ?string
  45.         {
  46.             return $this->id;
  47.         }
  48.         public function getCode(): ?string
  49.         {
  50.             return $this->code;
  51.         }
  52.         public function setCode(string $code): static
  53.         {
  54.             $this->code $code;
  55.             return $this;
  56.         }
  57.         /**
  58.          * @return Collection<int, City>
  59.          */
  60.         public function getCities(): Collection
  61.         {
  62.             return $this->cities;
  63.         }
  64.         public function addCity(City $city): static
  65.         {
  66.             if (!$this->cities->contains($city)) {
  67.                 $this->cities->add($city);
  68.             }
  69.             return $this;
  70.         }
  71.         public function removeCity(City $city): static
  72.         {
  73.             $this->cities->removeElement($city);
  74.             return $this;
  75.         }
  76. }