Rev 11 | Rev 31 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpclass Carto extends WidgetCommun {const SERVICE_CARTO_NOM = 'carto';const SERVICE_CARTO_ACTION_DEFAUT = 'carto';private $carte = null;private $source = null;private $numeroTaxon = '*';private $auteur = '*';private $referentiel = '*';private $departement = '*';/*** Methode appelee par defaut pour executer ce widget*/public function executer() {$retour = null;// recuperer les parametres de l'URL$this->extraireParametres();// verifier la disponibilite des services et ressources demandees$methode = $this->traiterNomMethodeExecuter($this->carte);if (method_exists($this, $methode)) {$retour = $this->$methode();} else {$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";}if (is_null($retour)) {$info = 'Un problème est survenu : '.print_r($this->messages, true);$this->envoyer($info);} else {$squelette = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'squelettes' . DIRECTORY_SEPARATOR. $retour['squelette'] . '.tpl.html';$html = $this->traiterSquelettePhp($squelette, $retour['donnees']);$this->envoyer($html);}}public function extraireParametres() {extract($this->parametres);$this->carte = (isset($carte) ? $carte : self::SERVICE_CARTO_ACTION_DEFAUT);$this->source = (isset($source) ? $source : $this->config['carto']['sourceParDefaut']);$this->numeroTaxon = (isset($num_taxon) ? $num_taxon : '*');$this->departement = (isset($dept) ? $dept : '*');$this->referentiel = (isset($referentiel) ? $referentiel : '*');$this->auteur = (isset($auteur) ? $auteur : '*');}/*** Carte par défaut*/public function executerCarto() {$widget = null;$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');// Création des infos du widget$widget['donnees']['url_serivce_carto'] = $this->contruireUrlServiceCarto();$widget['donnees']['url_base'] = $url_base;$widget['donnees']['source'] = $this->source;$widget['donnees']['num_taxon'] = $this->numeroTaxon;$widget['donnees']['auteur'] = $this->auteur;$widget['donnees']['departement'] = $this->departement;$widget['donnees']['referentiel'] = $this->referentiel;$widget['donnees']['communeImageUrl'] = $this->config['carto']['communeImageUrl'];$widget['donnees']['pointImageUrl'] = $this->config['carto']['pointImageUrl'];$widget['donnees']['liensVersSources'] = $this->config['carto']['liensVersSources'];$widget['donnees']['sourcesDispo'] = $this->config['carto']['sourcesDispo'];$widget['donnees']['nomSourcesDispo'] = $this->config['carto']['nomSourcesDispo'];$widget['donnees']['titreLegende'] = $this->config['carto']['titreLegende'];$widget['donnees']['urlLimitesCommunales'] = $this->obtenirUrlsLimitesCommunales();$widget['squelette'] = 'carto';return $widget;}private function contruireUrlServiceCarto($action = null) {// Création url données json$url = sprintf($this->config['chemins']['baseURLServicesTpl'], '');if ($action) {$url .= "/$action";$parametres_retenus = array();$parametres_a_tester = array('source', 'utilisateur', 'referentiel', 'dept', 'num_taxon');foreach ($parametres_a_tester as $param) {if (isset($this->$param) && $this->$param != '*') {$parametres_retenus[$param] = $this->$param;}}if (count($parametres_retenus) > 0) {$parametres_url = array();foreach ($parametres_retenus as $cle => $valeur) {$parametres_url[] = $cle.'='.$valeur;}$url .= '?'.implode('&', $parametres_url);}}return $url;}private function obtenirUrlsLimitesCommunales() {$urls = null;if (isset($this->departement)) {// si on veut afficher les limites départementales on va compter et chercher les noms de fichiers$fichiersKml = $this->chercherFichierKml();if (count($fichiersKml) > 0) {foreach ($fichiersKml as $kml => $dossier){$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml);$urls[] = $url_limites_communales;}}}$urls = json_encode($urls);return $urls;}private function chercherFichierKml(){$fichiers = array();$chemins = explode(',', $this->config['carto']['communesKmzChemin']);$departements = explode(',', $this->departement);// plrs code de départements peuvent être demandés séparés par des virgules$departements_trouves = array();foreach ($chemins as $dossier_chemin) {if ($dossier_ressource = opendir($dossier_chemin)) {while ($element = readdir($dossier_ressource)) {if ($element != '.' && $element != '..') {foreach ($departements as $departement) {$nom_dossier = basename($dossier_chemin);if (!isset($departements_trouves[$departement]) || $departements_trouves[$departement] == $nom_dossier) {$dept_protege = preg_quote($departement);if (!is_dir($dossier_chemin.'/'.$element) && preg_match("/^$dept_protege(?:_[0-9]+|)\.kml$/", $element)) {$fichiers[$element] = $nom_dossier;$departements_trouves[$departement] = $nom_dossier;}}}}}closedir($dossier_ressource);}}return $fichiers;}}?>