Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2290 → Rev 2301

/branches/v2.3-faux/jrest/lib/FormateurGroupeColonne.php
651,6 → 651,8
}
 
static function getNomCommun_v4($obs) {
// Attention la fonction suppose que l'on ait fait appel à getNomCommun_preload avant
// d'être appelée
if(! $obs['nt']) return NULL;
if(! self::referenceTableExiste()) return NULL;
 
658,24 → 660,16
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
 
$nom = null;
// cache:
if(isset($cache['getNomCommun'])) {
if(isset(self::$cache['getNomCommun'])) {
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
// XXX: problème de valeurs NULL ?
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) {
$nom = self::$cache['getNomCommun'][$cache_id];
}
}
 
// pas de cache:
$nom = Cel::db()->requeterLigne(sprintf("SELECT nom_commun FROM cel_references " .
"WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1",
$referentiel,
$obs['nt']));
 
if(! $nom) return NULL;
$nom = $nom["nom_commun"];
 
// cache
self::$cache['getNomCommun'][$cache_id] = $nom;
return $nom;
}
 
686,12 → 680,14
if(!$obsids) return;
if(!self::referenceTableExiste()) return NULL;
 
$req = sprintf("SELECT referentiel, num_nom_retenu, %s FROM cel_references r" .
" INNER JOIN cel_obs c ON (r.num_nom_retenu = c.nom_ret_nn)" .
" WHERE c.id_observation IN (%s)",
//" AND catminat_code IS NOT NULL", // TODO: suppression des NULL ici signifie que le cache sera partiel...
implode(',', array_keys(self::$baseflor_col)),
implode(',', $obsids));
// Attention (en attendant de faire une meilleure table et une meilleure requete) le distinct est très important
$req = sprintf("SELECT DISTINCT referentiel, num_nom_retenu, %s FROM cel_references r" .
" INNER JOIN cel_obs c ON (r.num_nom_retenu = c.nom_ret_nn)" .
" AND r.referentiel = IF(LOCATE(':', c.nom_referentiel) = 0, c.nom_referentiel, SUBSTR(c.nom_referentiel FROM 1 FOR LOCATE(':', c.nom_referentiel) - 1))" .
" WHERE c.id_observation IN (%s)",
//" AND catminat_code IS NOT NULL", // TODO: suppression des NULL ici signifie que le cache sera partiel...
implode(',', array_keys(self::$baseflor_col)),
implode(',', $obsids));
$res = Cel::db()->requeter($req);
if(!$res) return NULL;
 
699,6 → 695,15
$data = $v;
unset($data['referentiel']); // non nécessaire
unset($data['num_nom_retenu']); // non nécessaire
// Des fois les synonymes ont des valeurs pour baseflor et pas le nom retenu et vice versa
// on les fusionne pour avoir le maximum d'infos, en attendant de repenser la table référence
if(isset(self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']])) {
$orig = array_filter(self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']], 'strlen');
$data = array_filter($data , 'strlen');
$data = array_merge($orig, $data);
}
self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']] = $data;
}
 
705,15 → 710,16
return NULL;
}
 
 
static function baseflor_ligne($obs, &$ligne) {
// Attention la fonction suppose que l'on ait fait appel à baseflor_preload avant
// d'être appelée
if(! $obs['nom_ret_nn']) {
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
$ligne = array_merge($ligne, array_fill("", count(self::$baseflor_col), NULL));
return;
}
 
if(! self::referenceTableExiste()) {
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
$ligne = array_merge($ligne, array_fill("", count(self::$baseflor_col), NULL));
return;
}
 
725,23 → 731,10
if(@array_key_exists($cache_id, self::$cache['getBaseflor'])) {
$ligne = array_merge($ligne, self::$cache['getBaseflor'][$cache_id]);
return;
}
 
// pas de cache:
$data = Cel::db()->requeterLigne(sprintf("SELECT %s FROM cel_references " .
"WHERE referentiel = '%s' AND num_nom_retenu = %d LIMIT 1",
implode(', ', array_keys(self::$baseflor_col)),
$referentiel,
$obs['nom_ret_nn']));
 
if(! $data) {
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
} else {
$ligne = array_merge($ligne, array_fill("", count(self::$baseflor_col), NULL));
return;
}
 
// cache
self::$cache['getBaseflor'][$cache_id] = $data;
$ligne = array_merge($ligne, $data);
}
 
static function champsEtendus_preload($cel, $obsids) {