New file |
0,0 → 1,133 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Widget fournissant des interfaces de saisies simplifiée pour différent projets. |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
* Cas d'utilisation et documentation : |
* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetSaisie |
* |
* Paramètres : |
* ===> projet = chaine [par défaut : Biodiversite34] |
* Indique quel projet nous voulons charger |
* |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org) |
*/ |
class Saisie extends WidgetCommun { |
|
const DS = DIRECTORY_SEPARATOR; |
const PROJET_DEFAUT = 'biodiversite34'; |
private $projet = null; |
private $configProjet = null; |
|
/** |
* Méthode appelée par défaut pour charger ce widget. |
*/ |
public function executer() { |
$retour = null; |
extract($this->parametres); |
|
if (!isset($projet)) { |
$this->projet = self::PROJET_DEFAUT; |
} else { |
$this->projet = $projet; |
} |
$this->chargerConfigProjet(); |
|
$service = (isset($service)) ? $service : $this->projet; |
$methode = $this->traiterNomMethodeExecuter($service); |
if (method_exists($this, $methode)) { |
$retour = $this->$methode(); |
} else { |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible."; |
} |
|
if (is_null($retour)) { |
$contenu = 'Un problème est survenu : '.print_r($this->messages, true); |
} else { |
$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html'; |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext; |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']); |
} |
$this->envoyer($contenu); |
} |
|
private function chargerConfigProjet() { |
$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini'; |
if (file_exists($fichier_config)) { |
if (!$this->configProjet = parse_ini_file($fichier_config)) { |
$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé."; |
} |
} else { |
$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas."; |
} |
} |
|
public function executerBiodiversite34() { |
$widget['squelette'] = $this->projet; |
$widget['donnees'] = array(); |
$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], ''); |
$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34(); |
$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34(); |
return $widget; |
} |
public function executerTaxons() { |
$widget['squelette'] = $this->projet.'_taxons'; |
$widget['squelette_ext'] = '.tpl.js'; |
$widget['donnees'] = array(); |
$methode = 'recupererListeTaxon'.str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower($this->projet)))); |
$taxons = $this->$methode(); |
$taxons_tries = array(); |
foreach ($taxons as $taxon) { |
$taxons_tries[$taxon['num_nom_sel']] = $taxon; |
} |
$widget['donnees']['taxons'] = json_encode($taxons_tries); |
return $widget; |
} |
|
private function parserMilieuxBiodiversite34() { |
$infosMilieux = array(); |
$milieux = explode('|', $this->configProjet['milieux']); |
foreach ($milieux as $milieu) { |
$details = explode(';', $milieu); |
if (isset($details[1])) { |
$infosMilieux[$details[0]] = $details[1]; |
} else { |
$infosMilieux[$details[0]] = ''; |
} |
} |
return $infosMilieux; |
} |
|
private function recupererListeTaxonBiodiversite34() { |
$taxons = null; |
$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv'; |
if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) { |
$taxons = $this->decomposerFichierTsv($fichier_tsv); |
} else { |
$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'."; |
} |
return $taxons; |
} |
|
private function decomposerFichierTsv($fichier, $delimiter = "\t"){ |
$header = NULL; |
$data = array(); |
if (($handle = fopen($fichier, 'r')) !== FALSE) { |
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) { |
if (!$header) { |
$header = $row; |
} else { |
$data[] = array_combine($header, $row); |
} |
} |
fclose($handle); |
} |
return $data; |
} |
} |