21,8 → 21,11 |
class Saisie extends WidgetCommun { |
|
const DS = DIRECTORY_SEPARATOR; |
const PROJET_DEFAUT = 'biodiversite34'; |
const PROJET_DEFAUT = 'defaut'; |
const WS_SAISIE = "CelWidgetSaisie"; |
const WS_NOM = "noms"; |
const NS_PROJET = "bdtfx"; |
const EFLORE_API_VERSION = "0.1"; |
|
private $projet = null; |
private $configProjet = null; |
34,14 → 37,10 |
$retour = null; |
extract($this->parametres); |
|
if (!isset($projet)) { |
$this->projet = self::PROJET_DEFAUT; |
} else { |
$this->projet = $projet; |
} |
$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT; |
$this->chargerConfigProjet(); |
|
$service = (isset($service)) ? $service : $this->projet; |
$service = isset($service) ? $service : 'widget'; |
$methode = $this->traiterNomMethodeExecuter($service); |
if (method_exists($this, $methode)) { |
$retour = $this->$methode(); |
77,12 → 76,28 |
} |
} |
|
public function executerWidget() { |
$widget['squelette'] = $this->projet; |
$widget['donnees'] = array(); |
$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], ''); |
$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE); |
|
if ($this->projet == 'defaut') { |
$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl']; |
$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, self::NS_PROJET, self::WS_NOM); |
$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs; |
} else { |
$widget['donnees']['taxons'] = $this->recupererListeTaxon(); |
$widget['donnees']['milieux'] = $this->parserMilieux(); |
} |
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 = $this->recupererListeTaxon(); |
$taxons_tries = array(); |
foreach ($taxons as $taxon) { |
$taxons_tries[$taxon['num_nom_sel']] = $taxon; |
91,6 → 106,49 |
return $widget; |
} |
|
private function recupererListeTaxon() { |
$taxons = null; |
$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_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'."; |
} |
$taxons_tries = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC)); |
return $taxons_tries; |
} |
|
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; |
} |
|
private function parserMilieux() { |
$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]] = ''; |
} |
} |
ksort($infosMilieux); |
return $infosMilieux; |
} |
|
public function executerUploadImage() { |
$retour = array( |
'squelette' => $this->projet.'_image', |
171,96 → 229,5 |
$retour['donnees']['debogage'] = $debogage; |
return $retour; |
} |
|
public function executerBiodiversite34() { |
$widget['squelette'] = $this->projet; |
$widget['donnees'] = array(); |
$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], ''); |
$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE); |
|
$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34(); |
$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34(); |
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]] = ''; |
} |
} |
ksort($infosMilieux); |
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'."; |
} |
|
$taxons_tries = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC)); |
|
return $taxons_tries; |
} |
|
public function executerSauvages() { |
$widget['squelette'] = $this->projet; |
$widget['donnees'] = array(); |
$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], ''); |
$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE); |
|
$widget['donnees']['taxons'] = $this->recupererListeTaxonSauvages(); |
$widget['donnees']['milieux'] = $this->parserMilieuxSauvages(); |
return $widget; |
} |
|
private function parserMilieuxSauvages() { |
$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 recupererListeTaxonSauvages() { |
$taxons = null; |
$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'sauvages_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; |
} |
} |
?> |