<?php
namespace App\Entity\Master;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_m_region")
* @ORM\Entity
*/
class Region
{
public function __toString(){
return $this->name;
}
function displayProvinces(){
$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>';
foreach($this->getProvinces() as $province){
$zips = array();
foreach($province->getCities() as $city){
foreach($city->getZips() as $zip){
if(!in_array($zip->getCode(), $zips)){
array_push($zips, $zip->getCode());
}
}
}
$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>';
}
$result .= '</tbody></table>';
return $result;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string")
*/
protected $name;
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\City", mappedBy="region")
*/
private $cities;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\Province", mappedBy="region")
*/
private $provinces;
//
// ManyToMany
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Master\Company", mappedBy="regions")
*/
private $companies;
public function __construct()
{
$this->cities = new ArrayCollection();
$this->provinces = new ArrayCollection();
$this->companies = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, City>
*/
public function getCities(): Collection
{
return $this->cities;
}
public function addCity(City $city): self
{
if (!$this->cities->contains($city)) {
$this->cities->add($city);
$city->setRegion($this);
}
return $this;
}
public function removeCity(City $city): self
{
if ($this->cities->removeElement($city)) {
// set the owning side to null (unless already changed)
if ($city->getRegion() === $this) {
$city->setRegion(null);
}
}
return $this;
}
/**
* @return Collection<int, Province>
*/
public function getProvinces(): Collection
{
return $this->provinces;
}
public function addProvince(Province $province): self
{
if (!$this->provinces->contains($province)) {
$this->provinces->add($province);
$province->setRegion($this);
}
return $this;
}
public function removeProvince(Province $province): self
{
if ($this->provinces->removeElement($province)) {
// set the owning side to null (unless already changed)
if ($province->getRegion() === $this) {
$province->setRegion(null);
}
}
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->addRegion($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
$company->removeRegion($this);
}
return $this;
}
}