libreenfete-squelettes/lef_fonctions.php

143 lines
3.5 KiB
PHP

<?php
class LefInternet {
private $internet_id;
private $code = "internet";
private $evenementArray = array();
public function __construct($json_region) {
$this->pays_id = $json_region["id"];
}
public function populate( $evenementParRegionMap) {
$pays_key = "id_".$this->pays_id;
if (array_key_exists($pays_key, $evenementParRegionMap)) {
$this->evenementArray = $evenementParRegionMap[$pays_key];
}
}
public function toArray() {
return array("evenements" => $this->evenementArray, "total" => count($this->evenementArray));
}
}
class LefPays {
private $pays_id;
private $name = "";
private $code = "";
private $regions = array();
private $total_pays = 0;
private $lieuxnationaux;
private $key_array = array();
public function __construct($json_region) {
$this->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();
$region["total"] = $total_region;
$this->total_pays += $total_region;
$this->regions[] = $region;
}
}
}
}
public function getTotal() {
return $this->total_pays;
}
public function getKeyArray() {
return $this->key_array;
}
public function getCode() {
return $this->code;
}
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;
}
}