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'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); private $caracteresNormaux = array( 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); public function executer() { // Lancement de l'action demandée try { $this->initialiserProjet('sauvages'); $cmd = $this->getParametre('a'); switch ($cmd) { case 'chargerTous' : $this->creerXmlTaxons(); $this->creerXmlCriteres(); break; case 'creerXmlCriteres' : $this->creerXmlCriteres(); break; case 'creerXmlTaxons' : $this->creerXmlTaxons(); break; default : throw new Exception("Erreur : la commande '$cmd' n'existe pas!"); } } catch (Exception $e) { $this->traiterErreur($e->getMessage()); } } public function creerXmlCriteres() { $this->recupererContenuFichier(); $criteres_nom = $this->contenu_fichier[0]; unset($this->contenu_fichier[0]); $criteres_label = $this->contenu_fichier[1]; unset($this->contenu_fichier[1]); $description_label = $this->contenu_fichier[2]; unset($this->contenu_fichier[2]); $criteres_valeurs = $this->extraireValeurs(); $xml = $this->formerXmlCriteres($criteres_nom, $criteres_label, $description_label, $criteres_valeurs);//print_r($xml); file_put_contents("./xml_criteres.xml", $xml); } public function formerXmlCriteres($nom, $label, $description, $valeurs) { $xml=' Arbres images/pictos/icone_arbre.png '; foreach ($label as $id=>$criteres) { if ($id > 2) { $xml .= ' '.$description[$id].' '; foreach ($valeurs[$id] as $id_val=>$valeur) { if ($valeur != "0") { $crit = str_replace(" ", "_", $this->supprimerAccents($nom[$id])); $val = str_replace(" ", "_", $this->supprimerAccents($valeur)); $image = $crit."_".$val; $xml .= ''.$valeur.''; } } $xml .= ''; } } $xml .= " "; return $xml; } private function extraireValeurs() { $valeurs = array(); foreach ($this->contenu_fichier as $ligne) { $i = 0; foreach ($ligne as $critere) { if (!isset($valeurs[$i]) || !in_array(trim($critere), $valeurs[$i])) { $valeurs[$i][] = trim($critere); } $i++; } } return $valeurs; } public function creerXmlTaxons() { $this->recupererContenuFichier(); $criteres_label = array_flip($this->contenu_fichier[0]); unset($this->contenu_fichier[0]); unset($this->contenu_fichier[1]); unset($this->contenu_fichier[2]); $criteres_valeurs = $this->extraireValeurs(); $xml = $this->formerXmlTaxons($criteres_label, $criteres_valeurs); //print_r($xml); file_put_contents("./xml_taxons.xml", $xml); } public function formerXmlTaxons($criteres_label, $criteres_valeurs) { $xml=''; $rest = new RestClient(); foreach ($this->contenu_fichier as $id=>$taxon) { $infos_taxon = $this->rechercherInfosTaxon($rest, $taxon[$criteres_label["nom scientifique"]]); $xml .= ' '.$infos_taxon["description"].' '; if ($infos_taxon["images"] != array()) { foreach ($infos_taxon["images"] as $image) { $xml .= ''.$image["auteur.libelle"].''; } } $xml .= ''; for ($i=3; $i < count($taxon); $i++) { if (trim($taxon[$i]) !== "0") { $xml .= ''; } } $xml .= ''; } $xml .= ""; return $xml; } private function rechercherInfosTaxon($rest, $ns) { $info = array("description" => "", "images" => array()); $reponse = $this->consulterWebService($rest, "bdtfx", "taxons", "?masque=".urlencode(rtrim($ns))); if (is_array($reponse["resultat"])) { $id = key($reponse["resultat"]); } else { $reponse = $this->consulterWebService($rest, "bdtfx", "noms", "?retour.champs=nom_retenu.id&masque=".urlencode(rtrim($ns))); if (is_array($reponse["resultat"])) { $id = $reponse["resultat"][key($reponse["resultat"])]["nom_retenu.id"]; } } $reponse = $this->consulterWebService($rest, "coste", "textes", "/bdtfx.nn:".$id); if ($reponse['texte'] != ""){ $texte = str_replace("**", "", $reponse['texte']); $texte = str_replace("//", "", $texte); $texte = explode(" – ", $texte); unset($texte[0],$texte[1]); if (strpos($texte[2], ";") === false) {unset($texte[2]);} else {print_r($texte[2]);} if (preg_match('/^[\w|\s|\-|,]*\.*\s*$/', $texte[2]) == true) {print_r($texte[2]); unset($texte[2]);} $info["description"] = implode(" – ", $texte); } else { $reponse = $this->consulterWebService($rest, "baseflor", "informations", "/bdtfx.nn:".$id); $info["description"] = $this->formaterBaseflor($reponse); } $reponse = $this->consulterWebService($rest, "cel", "images", "?navigation.limite=5&retour.format=CRS&masque.nn=".$id); $info["images"] = $reponse["resultats"]; return $info; } private function formaterBaseflor($reponse) { $description = "En cours de rédaction."; if ($reponse["idiotaxon"] != "") { $description = "Formation végétale : ".$reponse["form_vegetale"]."; ". "Inflorescence : ".$reponse["inflorescence"]."; ". "Couleur de la fleur : ".$reponse["couleur_fleur"]."; ". "Sexualité : ".$reponse["sexualite"]."; ". "Fruit : ".$reponse["fruit"]."; ". "Pollinisation : ".$reponse["pollinisation"]."; ". "Dissémination : ".$reponse["dissemination"]."; ". "Ecologie : ".$reponse["carac_ecolo"]." – ". "Chorologie : ".$reponse["chorologie"]."; ". "Floraison : ".$reponse["floraison"]; } return $description; } private function consulterWebService($rest, $projet,$resssource,$parametres) { $url_id = "http://www.tela-botanica.org/service:eflore:0.1/".$projet."/".$resssource.$parametres; $reponse = $rest->consulter($url_id); return json_decode($reponse, true); } private function recupererContenuFichier() { $nomFichier = Config::get('dossierCsv').Config::get('projet'); if ($nomFichier && file_exists($nomFichier) ){ $extensionFichier = strtolower(strrchr($nomFichier, '.')); if ($extensionFichier === ".csv"){ $file = new SplFileObject($nomFichier); $file->setFlags(SplFileObject::SKIP_EMPTY); $i = 0; echo "Traitement du fichier : "; while (!$file->eof()){ $ligne_csv = $file->fgetcsv($delimiter = ';'); $this->contenu_fichier[$i] = $ligne_csv; echo str_repeat(chr(8), ( strlen( $i ) + 1 ))."\t".$i++; } echo "\n"; } else { $this->traiterErreur("Le fichier : $nomFichier n'est pas au format csv."); } } else { $this->traiterErreur("Le fichier : $nomFichier n'existe pas."); } } public function supprimerAccents($chaine) { return str_replace($this->caracteresAccentues, $this->caracteresNormaux, $chaine); } } ?>