Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Regard whitespace Rev 1108 → Rev 1109

/trunk/services/modules/0.1/nvjfl/NomsVernaculaires.php
8,6 → 8,9
* Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
* L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
*
* ATTENTION : /attributions groupe par taxon, le nombre de résultats est donc
* inférieur ou égal au nombre demandé par navigation.limite
*
* Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
* distinct, retour.format, navigation.depart et navigation.limite.
*
211,14 → 214,19
}
 
public function analyserChamp() {
$this->requete_champ = array();
$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
$champs = explode(' ', $this->ressources[1]);
//$this->requete_champ = array(); // * car absence de mappings
foreach ($champs as $champ) {
preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
if (isset($this->champs_possibles[$match[1]])) {
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
// wtf?
//$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
// marche pas, pour chaque champ il faut en retourner un qui a un
// autre nom etc. , pas le temps de faire des mappings
$this->requete_champ[] = $match[1];
} elseif (isset($this->champs_possibles[$match[0]])) {
// wtf ?
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
} else {
$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
252,7 → 260,6
$count,
$this->limite_requete['limite']
);
 
$req = sprintf(
'SELECT %s, group_concat(num_taxon) as num_taxon, IF(num_statut="",1,0) AS is_null' .
' FROM %s WHERE %s GROUP BY id ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
263,7 → 270,6
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
$limiteClause,
__FILE__, __LINE__);
//echo "REQ: $req\n";
return $req;
}
 
281,7 → 287,6
$count,
$this->limite_requete['limite']);
}
 
$req = sprintf(
'SELECT %s, IF(num_statut="",1,0) AS is_null' .
' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
292,7 → 297,6
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
$nolimit ? '' : $limiteClause,
__FILE__, __LINE__);
//echo "REQ 2: $req\n";
return $req;
}
 
349,7 → 353,6
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break;
default : break;
}
//echo "\nCOMPTE: " . count($reponse['resultat']) . "\n\n";
return $reponse;
}
373,7 → 376,6
* évite d'écraser des clefs etc.)
*/
public function ajouterJsonResultatNV($resultat) {
//echo "CPT RES: " . count($resultat) . "\n\n";
$resultat_json = array();
foreach ($resultat as $tab) {
$this->table_retour = array();
454,6 → 456,7
if (!empty($url['suivant'])) {
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
}
$resultat_json = array();
foreach ($resultat as &$tab) {
$nnv = $tab['num_nom_vernaculaire'];
$resultat_json[$nnv]['id'] = $tab['id'];
466,8 → 469,7
//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
// simple initialisation par copie de la référence de l'original
$resultat_json[$nnv] = &$tab;
}
else {
} else {
$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
484,7 → 486,7
}
 
if ($this->retour_format == 'max') {
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
// Deuxième boucle pour demander tous lestaxons présents en une
// fois et les attribuer aux noms car c'est beaucoup plus rapide
$noms_sci = $this->recupererNomTaxons();
foreach ($resultat_json as $num_nom => &$tab) {
797,6 → 799,10
return $valeur;
}
 
/**
* Apparemment, regroupe les noms vernaculaires par taxons (élimine donc
* certains noms) - j'ai bon ?
*/
public function afficherTaxons() {
$resultat = $this->recupererNomTaxons();
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
812,6 → 818,7
public function recupererNomTaxons() {
$taxons = array_unique($this->taxons);
// @TODO attention à la limite de taille de l'URL - faire un POST plutôt
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
$res = $this->consulterHref($url);
foreach ($res->resultat as $id=>$taxon) {
846,8 → 853,12
return $this->table_retour;
}
 
/**
* Quelqu'un sait-il ce que fait cette foutue fonction ? :-/
*/
public function afficherPoint($champ, $valeur, $langue, $num_nom) {
preg_match('/^(.*)\.code$/', $champ, $match);
$aMatche = preg_match('/^(.*)\.code$/', $champ, $match);
if ($aMatche !== false && $aMatche !== 0) {
$champ = $match[1];
if (isset(self::$champ_infos[$champ])) {
extract(self::$champ_infos[$champ]);
874,6 → 885,7
}
}
}
}
 
public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
if ($this->retour_format == 'max') {