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.         public function getId(): ?string
  67.         {
  68.             return $this->id;
  69.         }
  70.         public function getName(): ?string
  71.         {
  72.             return $this->name;
  73.         }
  74.         public function setName(string $name): static
  75.         {
  76.             $this->name $name;
  77.             return $this;
  78.         }
  79.         /**
  80.          * @return Collection<int, City>
  81.          */
  82.         public function getCities(): Collection
  83.         {
  84.             return $this->cities;
  85.         }
  86.         public function addCity(City $city): static
  87.         {
  88.             if (!$this->cities->contains($city)) {
  89.                 $this->cities->add($city);
  90.                 $city->setRegion($this);
  91.             }
  92.             return $this;
  93.         }
  94.         public function removeCity(City $city): static
  95.         {
  96.             if ($this->cities->removeElement($city)) {
  97.                 // set the owning side to null (unless already changed)
  98.                 if ($city->getRegion() === $this) {
  99.                     $city->setRegion(null);
  100.                 }
  101.             }
  102.             return $this;
  103.         }
  104.         /**
  105.          * @return Collection<int, Province>
  106.          */
  107.         public function getProvinces(): Collection
  108.         {
  109.             return $this->provinces;
  110.         }
  111.         public function addProvince(Province $province): static
  112.         {
  113.             if (!$this->provinces->contains($province)) {
  114.                 $this->provinces->add($province);
  115.                 $province->setRegion($this);
  116.             }
  117.             return $this;
  118.         }
  119.         public function removeProvince(Province $province): static
  120.         {
  121.             if ($this->provinces->removeElement($province)) {
  122.                 // set the owning side to null (unless already changed)
  123.                 if ($province->getRegion() === $this) {
  124.                     $province->setRegion(null);
  125.                 }
  126.             }
  127.             return $this;
  128.         }
  129.         /**
  130.          * @return Collection<int, Company>
  131.          */
  132.         public function getCompanies(): Collection
  133.         {
  134.             return $this->companies;
  135.         }
  136.         public function addCompany(Company $company): static
  137.         {
  138.             if (!$this->companies->contains($company)) {
  139.                 $this->companies->add($company);
  140.                 $company->addRegion($this);
  141.             }
  142.             return $this;
  143.         }
  144.         public function removeCompany(Company $company): static
  145.         {
  146.             if ($this->companies->removeElement($company)) {
  147.                 $company->removeRegion($this);
  148.             }
  149.             return $this;
  150.         }
  151. }