src/Entity/Master/Region.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_region")
  9.  * @ORM\Entity
  10.  */
  11. class Region
  12. {    
  13.     public function __toString(){
  14.         return $this->name;
  15.     }
  16.     function displayProvinces(){
  17.         $result '<table class="table table_no_padding b_none m_b_none font_12"><thead><tr><th class="td_w_150p"><label class="l_s_none font_12 m_b_none">Provincia</label></th><th class="td_w_50p txt_a_c"><label class="l_s_none font_12 m_b_none">Sigla</label></th><th class="td_w_50p txt_a_c"><label class="l_s_none font_12 m_b_none">CAP</label></th><th class="td_w_50p txt_a_c"><label class="l_s_none font_12 m_b_none">Città</label></th></tr></thead><tbody>';
  18.         foreach($this->getProvinces() as $province){
  19.             $zips = array();
  20.             foreach($province->getCities() as $city){
  21.                 foreach($city->getZips() as $zip){
  22.                     if(!in_array($zip->getCode(), $zips)){
  23.                         array_push($zips$zip->getCode());
  24.                     }
  25.                 }
  26.             }
  27.             $result.= '<tr><td>'.$province->getName().'</td><td class="txt_a_c">'.$province->getSign().'</td><td class="txt_a_c">'.sizeof($zips).'</td><td class="txt_a_c">'.sizeof($province->getCities()).'</td></tr>';
  28.         }
  29.         $result .= '</tbody></table>';
  30.         return $result;
  31.     }
  32.     /**
  33.      * @ORM\Column(name="id", type="bigint")
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue(strategy="AUTO")
  36.      */
  37.     protected $id;
  38.     
  39.     /**
  40.      * @ORM\Column(name="name", type="string")
  41.      */
  42.     protected $name;
  43.     
  44.     // OneToMany
  45.         /**
  46.          * @ORM\OneToMany(targetEntity="App\Entity\Master\City", mappedBy="region")
  47.          */
  48.         private $cities;
  49.         /**
  50.          * @ORM\OneToMany(targetEntity="App\Entity\Master\Province", mappedBy="region")
  51.          */
  52.         private $provinces;
  53.     //
  54.     
  55.     // ManyToMany
  56.         /**
  57.          * @ORM\ManyToMany(targetEntity="App\Entity\Master\Company", mappedBy="regions")
  58.          */
  59.         private $companies;
  60.         public function __construct()
  61.         {
  62.             $this->cities = new ArrayCollection();
  63.             $this->provinces = new ArrayCollection();
  64.             $this->companies = new ArrayCollection();
  65.         }
  66.     //
  67.     public function getId(): ?string
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getName(): ?string
  72.     {
  73.         return $this->name;
  74.     }
  75.     public function setName(string $name): self
  76.     {
  77.         $this->name $name;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection<int, City>
  82.      */
  83.     public function getCities(): Collection
  84.     {
  85.         return $this->cities;
  86.     }
  87.     public function addCity(City $city): self
  88.     {
  89.         if (!$this->cities->contains($city)) {
  90.             $this->cities->add($city);
  91.             $city->setRegion($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeCity(City $city): self
  96.     {
  97.         if ($this->cities->removeElement($city)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($city->getRegion() === $this) {
  100.                 $city->setRegion(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection<int, Province>
  107.      */
  108.     public function getProvinces(): Collection
  109.     {
  110.         return $this->provinces;
  111.     }
  112.     public function addProvince(Province $province): self
  113.     {
  114.         if (!$this->provinces->contains($province)) {
  115.             $this->provinces->add($province);
  116.             $province->setRegion($this);
  117.         }
  118.         return $this;
  119.     }
  120.     public function removeProvince(Province $province): self
  121.     {
  122.         if ($this->provinces->removeElement($province)) {
  123.             // set the owning side to null (unless already changed)
  124.             if ($province->getRegion() === $this) {
  125.                 $province->setRegion(null);
  126.             }
  127.         }
  128.         return $this;
  129.     }
  130.     /**
  131.      * @return Collection<int, Company>
  132.      */
  133.     public function getCompanies(): Collection
  134.     {
  135.         return $this->companies;
  136.     }
  137.     public function addCompany(Company $company): self
  138.     {
  139.         if (!$this->companies->contains($company)) {
  140.             $this->companies->add($company);
  141.             $company->addRegion($this);
  142.         }
  143.         return $this;
  144.     }
  145.     public function removeCompany(Company $company): self
  146.     {
  147.         if ($this->companies->removeElement($company)) {
  148.             $company->removeRegion($this);
  149.         }
  150.         return $this;
  151.     }
  152. }