1,17 → 1,15 |
<?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 |
* Widget fournissant des interfaces de saisie simplifiée pour différent projets |
* |
* Cas d'utilisation et documentation : |
* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetSaisie |
* @link http://www.tela-botanica.org/wikini/AideCarnetEnLigne/wakka.php?wiki=AideCELWidgetSaisie |
* |
* Paramètres : |
* ===> projet = chaine [par défaut : defaut] : indique le widgetde saisie à charger. |
* ===> mission = chaine [par défaut : vide] : permet de charger un "sous-widget" vis à vis du projet. |
* Indique quel projet nous voulons charger |
* - projet [par défaut : defaut] : indique le mot-clé à associer aux obs saisies; si un widget de saisie personnalisé |
* portant ce nom existe, il sera chargé |
* - mission [par défaut : vide] : permet de charger un "sous-widget", dans le cas où un widget personnalisé |
* est associé au projet, et ce widget accepte des sous-widgets (ex: "missions-flore") |
* |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
18,7 → 16,7 |
* @author Aurelien PERONNET <aurelien@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> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
* @copyright 1999-2015 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class Saisie extends WidgetCommun { |
|
29,34 → 27,41 |
const WS_OBS = 'CelObs'; |
const WS_NOM = 'noms'; |
const EFLORE_API_VERSION = '0.1'; |
const REFERENTIEL_DEFAUT = 'bdtfx'; |
|
private $ns_referentiel = 'bdtfx'; |
private $projet = null; |
private $configProjet = null; |
private $configMission = null; |
/** référentiel utilisé pour al complétion des noms scientifiques */ |
protected $ns_referentiel; |
/** mot-clé associé aux saisies, et template personnalisé si appliquable */ |
protected $projet = null; |
protected $configProjet = null; |
protected $configMission = null; |
|
/** |
* Méthode appelée par défaut pour charger ce widget. |
* Amorçage du widget |
*/ |
public function executer() { |
$retour = null; |
extract($this->parametres); |
// paramètres par défaut |
$this->ns_referentiel = self::REFERENTIEL_DEFAUT; |
$this->projet = self::PROJET_DEFAUT; |
|
$this->projet = self::PROJET_DEFAUT; |
if (isset($projet) && trim($projet) != "") { |
$projets = explode(',', $projet); |
// définition du projet / mission |
if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") { |
$projets = explode(',', $this->parametres['projet']); |
$this->projet = strtolower($projets[0]); |
} |
$this->chargerConfigProjet(); |
|
$service = isset($service) ? $service : 'widget'; |
// exécution du service (le widget entier ou une sous-partie, par ex "Taxons") |
$retour = null; |
$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget'; |
$methode = $this->traiterNomMethodeExecuter($service); |
if (method_exists($this, $methode)) { |
$retour = $this->$methode(); |
} else { |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible."; |
$this->messages[] = "Le service '$methode' n'est pas disponible."; |
} |
|
// injection des données dans le squelette |
$contenu = null; |
$mime = null; |
if (is_array($retour) && array_key_exists('squelette', $retour)) { |
70,15 → 75,21 |
$mime = isset($retour['mime']) ? $retour['mime'] : null; |
} else { |
if (count($this->messages) == 0) { |
$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format."; |
$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format"; |
} |
$contenu = 'Un problème est survenu : '.print_r($this->messages, true); |
$contenu = 'Un problème est survenu : ' . print_r($this->messages, true); |
} |
|
// envoi de la page |
$this->envoyer($contenu, $mime); |
} |
|
private function chargerConfigProjet() { |
/** |
* Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini |
* Si une mission est définie, charge séparément la section de la configuration concernant |
* cette mission : [nommission] |
*/ |
protected 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, true)) { |
87,25 → 98,31 |
if (isset($this->configProjet[$mission])) { |
$this->configMission = $this->configProjet[$mission]; |
} |
} |
} |
} else { |
$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé."; |
$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé."; |
} |
} else { |
$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas."; |
$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas."; |
} |
} |
|
private function projetASquelette() { |
// fonction très simple qui ne teste que si le dossier du projet courant |
// existe, mais elle suffit pour le moment. |
/** |
* Retourne true si le dossier du projet courant existe, false sinon |
* @return boolean |
*/ |
protected function projetASquelette() { |
return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet); |
} |
|
/** |
* Exécution du widget complet |
* @return Ambigous <string, unknown, multitype:string unknown > |
*/ |
public function executerWidget() { |
$referentiel_impose = false; |
if (isset($_GET['referentiel']) && $_GET['referentiel'] != '' && $_GET['referentiel'] != "autre") { |
$this->ns_referentiel = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->ns_referentiel; |
$this->ns_referentiel = $_GET['referentiel']; |
$referentiel_impose = true; |
} |
|
138,7 → 155,7 |
|
if ($this->especeEstImposee()) { |
$nnEspeceImposee = $this->getNnEspeceImposee(); |
$nom = $this->executerChargementInfosTaxon($nnEspeceImposee); |
$nom = $this->chargerInfosTaxon($nnEspeceImposee); |
$widget['donnees']['espece_imposee'] = true; |
$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee; |
$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci']; |
164,7 → 181,7 |
return $widget; |
} |
|
private function getTitrePage() { |
protected function getTitrePage() { |
$titre = 'defaut'; |
if (isset($this->configProjet['titre_page'])) { |
$titre = $this->configProjet['titre_page']; |
181,6 → 198,11 |
return $titre; |
} |
|
/** |
* Remplit un fichier JS avec une variable contenant une liste restreinte de taxons, |
* pour certains projets |
* @return string |
*/ |
public function executerTaxons() { |
$widget['squelette'] = $this->projet.'_taxons'; |
$widget['squelette_ext'] = '.tpl.js'; |
194,7 → 216,10 |
return $widget; |
} |
|
private function recupererListeNomsSci() { |
/** |
* Trie par nom français les taxons lus dans le fichier tsv |
*/ |
protected function recupererListeNomsSci() { |
$taxons = $this->recupererListeTaxon(); |
if (is_array($taxons)) { |
$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC)); |
202,7 → 227,11 |
return $taxons; |
} |
|
private function recupererListeNoms() { |
/** |
* @TODO documenter |
* @return array |
*/ |
protected function recupererListeNoms() { |
$taxons = $this->recupererListeTaxon(); |
$nomsAAfficher = array(); |
$nomsSpeciaux = array(); |
243,8 → 272,11 |
return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher); |
} |
|
private function recupererListeTaxon() { |
$taxons = null; |
/** |
* Lit une liste de taxons depuis un fichier tsv fourni |
*/ |
protected function recupererListeTaxon() { |
$taxons = array(); |
$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); |
254,7 → 286,10 |
return $taxons; |
} |
|
private function decomposerFichierTsv($fichier, $delimiter = "\t"){ |
/** |
* Découpe un fihcier tsv |
*/ |
protected function decomposerFichierTsv($fichier, $delimiter = "\t"){ |
$header = null; |
$data = array(); |
if (($handle = fopen($fichier, 'r')) !== FALSE) { |
270,7 → 305,12 |
return $data; |
} |
|
private function parserMilieux() { |
/** |
* Récupère la liste des milieux depuis la section [milieux] de la configuration |
* du projet, si elle existe |
* @return array |
*/ |
protected function parserMilieux() { |
$infosMilieux = array(); |
if (isset($this->configProjet['milieux'])) { |
$milieux = explode('|', $this->configProjet['milieux']); |
288,12 → 328,21 |
return $infosMilieux; |
} |
|
private function especeEstImposee() { |
return (isset($_GET['num_nom']) && $_GET['num_nom'] != '' |
/** |
* Retourne true si le widget est restreint à une espèce, false sinon |
* @return boolean |
*/ |
protected function especeEstImposee() { |
return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '') |
|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee'])); |
} |
|
private function getNnEspeceImposee() { |
/** |
* Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est |
* le cas, null sinon |
* @return string |
*/ |
protected function getNnEspeceImposee() { |
$nn = null; |
if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) { |
$nn = $_GET['num_nom']; |
305,10 → 354,17 |
return $nn; |
} |
|
private function executerChargementInfosTaxon($num_nom) { |
/** |
* Consulte un webservice pour obtenir des informations sur le taxon dont le |
* numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom |
* et non le taxon?) |
* @param string|int $num_nom |
* @return array |
*/ |
protected function chargerInfosTaxon($num_nom) { |
$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom); |
$infos = json_decode(file_get_contents($url_service_infos)); |
// trop de champs injectés dans les infos espèces peut |
// trop de champs injectés dans les infos espèces peuvent |
// faire planter javascript |
$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', |
'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique'); |
323,7 → 379,13 |
return $resultat; |
} |
|
private function array2js($array,$show_keys) { |
/** |
* Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ? |
* @param array $array |
* @param boolean $show_keys |
* @return une portion de JSON représentant le tableau |
*/ |
protected function array2js($array,$show_keys) { |
$tableauJs = '{}'; |
if (!empty($array)) { |
$total = count($array) - 1; |