pays_id = $json_region["id"]; $this->code = $json_region["code"]; $this->name = $json_region["name"]; } public function populate($json_regions, $evenementParRegionMap) { $pays_key = "id_".$this->pays_id; $this->key_array[] = $pays_key; if (array_key_exists($pays_key, $evenementParRegionMap)) { $evenementNationalArray = $evenementParRegionMap[$pays_key]; $total_national = count($evenementNationalArray); $this->total_pays += $total_national; $this->lieuxnationaux = new LefLieux($evenementNationalArray); } foreach($json_regions as $region) { if ($region["region_id"] == $this->pays_id) { $region_key = "id_".$region["id"]; $this->key_array[] = $region_key; if (array_key_exists($region_key, $evenementParRegionMap)) { $evenementParRegionArray = $evenementParRegionMap[$region_key]; $total_region = count($evenementParRegionArray); $lieux = new LefLieux($evenementParRegionArray); $region["evenements"] = $lieux->toArray(); $this->total_pays += $total_region; $this->regions[] = $region; } } } } public function getTotal() { return $this->total_pays; } public function getKeyArray() { return $this->key_array; } public function toArray() { $evenementsnationaux; $totalevenementsnationaux = 0; if ($this->lieuxnationaux) { $evenementsnationaux = $this->lieuxnationaux->toArray(); foreach($evenementsnationaux as $key => $array) { $totalevenementsnationaux = $totalevenementsnationaux + count($array); } } else { $evenementsnationaux = array(); } return array("name" => $this->name, "code" => $this->code, "sousregions" => $this->regions, "evenementsnationaux" => $evenementsnationaux, "totalevenementsnationaux" => $totalevenementsnationaux); } } class LefLieux { public $lieux = array(); public function __construct($evenementArray) { foreach($evenementArray as $evenement) { $city = $evenement["city"]; if (!$city) { $city = ""; } $lieu = null; if (array_key_exists($city, $this->lieux)) { $lieu = $this->lieux[$city]; } else { $lieu = new LefLieu($city); $this->lieux[$city] = $lieu; } $lieu->addEvenement($evenement); } ksort($this->lieux); } public function toArray() { $result = array(); foreach($this->lieux as $key => $lieu) { $result[$lieu->name] = $lieu->evenementArray; } return $result; } } class LefLieu { public $name = ""; public $evenementArray = array(); public function __construct($name) { $this->name = $name; } public function addEvenement($evenement) { $this->evenementArray[] = $evenement; } }