| Line 649... |
Line 649... |
| 649 |
}
|
649 |
}
|
| 650 |
return TRUE;
|
650 |
return TRUE;
|
| 651 |
}
|
651 |
}
|
| Line 652... |
Line 652... |
| 652 |
|
652 |
|
| - |
|
653 |
static function getNomCommun_v4($obs) {
|
| - |
|
654 |
// Attention la fonction suppose que l'on ait fait appel à getNomCommun_preload avant
|
| 653 |
static function getNomCommun_v4($obs) {
|
655 |
// d'être appelée
|
| 654 |
if(! $obs['nt']) return NULL;
|
656 |
if(! $obs['nt']) return NULL;
|
| Line 655... |
Line 657... |
| 655 |
if(! self::referenceTableExiste()) return NULL;
|
657 |
if(! self::referenceTableExiste()) return NULL;
|
| 656 |
|
658 |
|
| 657 |
$langue = 'fra';
|
659 |
$langue = 'fra';
|
| Line -... |
Line 660... |
| - |
|
660 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
| 658 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
661 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
| 659 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
662 |
|
| 660 |
|
663 |
$nom = null;
|
| 661 |
// cache:
|
664 |
// cache:
|
| 662 |
if(isset($cache['getNomCommun'])) {
|
665 |
if(isset(self::$cache['getNomCommun'])) {
|
| - |
|
666 |
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
|
| - |
|
667 |
// XXX: problème de valeurs NULL ?
|
| 663 |
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
|
668 |
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) {
|
| Line 664... |
Line -... |
| 664 |
// XXX: problème de valeurs NULL ?
|
- |
|
| 665 |
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
|
- |
|
| 666 |
}
|
- |
|
| 667 |
|
- |
|
| 668 |
// pas de cache:
|
- |
|
| 669 |
$nom = Cel::db()->requeterLigne(sprintf("SELECT nom_commun FROM cel_references " .
|
- |
|
| 670 |
"WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1",
|
- |
|
| 671 |
$referentiel,
|
- |
|
| 672 |
$obs['nt']));
|
- |
|
| 673 |
|
- |
|
| 674 |
if(! $nom) return NULL;
|
- |
|
| 675 |
$nom = $nom["nom_commun"];
|
669 |
$nom = self::$cache['getNomCommun'][$cache_id];
|
| 676 |
|
670 |
}
|
| Line 677... |
Line 671... |
| 677 |
// cache
|
671 |
}
|
| 678 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
672 |
|
| 679 |
return $nom;
|
673 |
return $nom;
|
| 680 |
}
|
674 |
}
|
| 681 |
|
675 |
|
| Line -... |
Line 676... |
| - |
|
676 |
|
| 682 |
|
677 |
/* Cette fonction initialise le cache des données baseflor en 1 fois, sur la liste des observations à exporter.
|
| 683 |
/* Cette fonction initialise le cache des données baseflor en 1 fois, sur la liste des observations à exporter.
|
678 |
Ainsi, les appels successifs à baseflor_ligne() ne sont pas couteux (pas de requête SQL) */
|
| - |
|
679 |
static function baseflor_preload($cel, $obsids) {
|
| 684 |
Ainsi, les appels successifs à baseflor_ligne() ne sont pas couteux (pas de requête SQL) */
|
680 |
if(!$obsids) return;
|
| 685 |
static function baseflor_preload($cel, $obsids) {
|
681 |
if(!self::referenceTableExiste()) return NULL;
|
| 686 |
if(!$obsids) return;
|
682 |
|
| 687 |
if(!self::referenceTableExiste()) return NULL;
|
683 |
// Attention (en attendant de faire une meilleure table et une meilleure requete) le distinct est très important
|
| 688 |
|
684 |
$req = sprintf("SELECT DISTINCT referentiel, num_nom_retenu, %s FROM cel_references r" .
|
| 689 |
$req = sprintf("SELECT referentiel, num_nom_retenu, %s FROM cel_references r" .
|
685 |
" INNER JOIN cel_obs c ON (r.num_nom_retenu = c.nom_ret_nn)" .
|
| Line 690... |
Line 686... |
| 690 |
" INNER JOIN cel_obs c ON (r.num_nom_retenu = c.nom_ret_nn)" .
|
686 |
" AND r.referentiel = IF(LOCATE(':', c.nom_referentiel) = 0, c.nom_referentiel, SUBSTR(c.nom_referentiel FROM 1 FOR LOCATE(':', c.nom_referentiel) - 1))" .
|
| 691 |
" WHERE c.id_observation IN (%s)",
|
687 |
" WHERE c.id_observation IN (%s)",
|
| 692 |
//" AND catminat_code IS NOT NULL", // TODO: suppression des NULL ici signifie que le cache sera partiel...
|
688 |
//" AND catminat_code IS NOT NULL", // TODO: suppression des NULL ici signifie que le cache sera partiel...
|
| 693 |
implode(',', array_keys(self::$baseflor_col)),
|
689 |
implode(',', array_keys(self::$baseflor_col)),
|
| - |
|
690 |
implode(',', $obsids));
|
| - |
|
691 |
$res = Cel::db()->requeter($req);
|
| - |
|
692 |
if(!$res) return NULL;
|
| - |
|
693 |
|
| - |
|
694 |
foreach($res as $v) {
|
| - |
|
695 |
$data = $v;
|
| - |
|
696 |
unset($data['referentiel']); // non nécessaire
|
| - |
|
697 |
unset($data['num_nom_retenu']); // non nécessaire
|
| - |
|
698 |
|
| 694 |
implode(',', $obsids));
|
699 |
// Des fois les synonymes ont des valeurs pour baseflor et pas le nom retenu et vice versa
|
| 695 |
$res = Cel::db()->requeter($req);
|
700 |
// on les fusionne pour avoir le maximum d'infos, en attendant de repenser la table référence
|
| Line 696... |
Line 701... |
| 696 |
if(!$res) return NULL;
|
701 |
if(isset(self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']])) {
|
| 697 |
|
702 |
$orig = array_filter(self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']], 'strlen');
|
| Line 698... |
Line -... |
| 698 |
foreach($res as $v) {
|
- |
|
| 699 |
$data = $v;
|
703 |
$data = array_filter($data , 'strlen');
|
| - |
|
704 |
$data = array_merge($orig, $data);
|
| - |
|
705 |
}
|
| 700 |
unset($data['referentiel']); // non nécessaire
|
706 |
|
| 701 |
unset($data['num_nom_retenu']); // non nécessaire
|
707 |
self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']] = $data;
|
| 702 |
self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']] = $data;
|
708 |
}
|
| 703 |
}
|
709 |
|
| Line 704... |
Line 710... |
| 704 |
|
710 |
return NULL;
|
| 705 |
return NULL;
|
711 |
}
|
| 706 |
}
|
712 |
|
| 707 |
|
713 |
static function baseflor_ligne($obs, &$ligne) {
|
| Line 708... |
Line 714... |
| 708 |
|
714 |
// Attention la fonction suppose que l'on ait fait appel à baseflor_preload avant
|
| 709 |
static function baseflor_ligne($obs, &$ligne) {
|
715 |
// d'être appelée
|
| Line 723... |
Line 729... |
| 723 |
// XXX: problème de valeurs NULL pour utiliser simplement isset() ?
|
729 |
// XXX: problème de valeurs NULL pour utiliser simplement isset() ?
|
| 724 |
// @ car getBaseflor[] n'est peut-être pas encore initialisé
|
730 |
// @ car getBaseflor[] n'est peut-être pas encore initialisé
|
| 725 |
if(@array_key_exists($cache_id, self::$cache['getBaseflor'])) {
|
731 |
if(@array_key_exists($cache_id, self::$cache['getBaseflor'])) {
|
| 726 |
$ligne = array_merge($ligne, self::$cache['getBaseflor'][$cache_id]);
|
732 |
$ligne = array_merge($ligne, self::$cache['getBaseflor'][$cache_id]);
|
| 727 |
return;
|
733 |
return;
|
| 728 |
}
|
- |
|
| 729 |
|
- |
|
| 730 |
// pas de cache:
|
- |
|
| 731 |
$data = Cel::db()->requeterLigne(sprintf("SELECT %s FROM cel_references " .
|
- |
|
| 732 |
"WHERE referentiel = '%s' AND num_nom_retenu = %d LIMIT 1",
|
- |
|
| 733 |
implode(', ', array_keys(self::$baseflor_col)),
|
- |
|
| 734 |
$referentiel,
|
- |
|
| 735 |
$obs['nom_ret_nn']));
|
- |
|
| 736 |
|
- |
|
| 737 |
if(! $data) {
|
734 |
} else {
|
| 738 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
735 |
$ligne = array_merge($ligne, array_fill("", count(self::$baseflor_col), NULL));
|
| 739 |
return;
|
736 |
return;
|
| 740 |
}
|
737 |
}
|
| 741 |
|
- |
|
| 742 |
// cache
|
- |
|
| 743 |
self::$cache['getBaseflor'][$cache_id] = $data;
|
- |
|
| 744 |
$ligne = array_merge($ligne, $data);
|
- |
|
| 745 |
}
|
738 |
}
|
| Line 746... |
Line 739... |
| 746 |
|
739 |
|
| 747 |
static function champsEtendus_preload($cel, $obsids) {
|
740 |
static function champsEtendus_preload($cel, $obsids) {
|
| 748 |
$gestion_champs_etendus = new GestionChampsEtendus($cel->config, 'obs');
|
741 |
$gestion_champs_etendus = new GestionChampsEtendus($cel->config, 'obs');
|