1 |
<?php
|
1 |
<?php
|
2 |
|
2 |
|
3 |
/**
|
3 |
/**
|
4 |
* @category PHP
|
4 |
* @category PHP
|
5 |
* @package jrest
|
5 |
* @package jrest
|
6 |
* @author Raphaël Droz <raphael@tela-botania.org>
|
6 |
* @author Raphaël Droz <raphael@tela-botania.org>
|
7 |
* @copyright 2013 Tela-Botanica
|
7 |
* @copyright 2013 Tela-Botanica
|
8 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
8 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
9 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
9 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
10 |
*/
|
10 |
*/
|
11 |
define('SEPARATEUR_IMAGES', ",");
|
11 |
define('SEPARATEUR_IMAGES', ",");
|
12 |
|
12 |
|
13 |
Class FormateurGroupeColonne {
|
13 |
Class FormateurGroupeColonne {
|
14 |
|
14 |
|
15 |
// cache pour les données des fonctions
|
15 |
// cache pour les données des fonctions
|
16 |
static $cache = Array();
|
16 |
static $cache = Array();
|
17 |
|
17 |
|
18 |
// test sur la table cel_references, mis à TRUE si la table existe
|
18 |
// test sur la table cel_references, mis à TRUE si la table existe
|
19 |
static $is_table = false;
|
19 |
static $is_table = false;
|
20 |
|
20 |
|
21 |
// les groupes de champs utilisables
|
21 |
// les groupes de champs utilisables
|
22 |
static $fieldGroups = array(
|
22 |
static $fieldGroups = array(
|
23 |
'standard',
|
23 |
'standard',
|
24 |
'avance',
|
24 |
'avance',
|
25 |
'etendu',
|
25 |
'etendu',
|
26 |
'baseflor'
|
26 |
'baseflor'
|
27 |
);
|
27 |
);
|
28 |
|
28 |
|
29 |
// les données baseflor à récupérer: colonnes présentes dans cel_references
|
29 |
// les données baseflor à récupérer: colonnes présentes dans cel_references
|
30 |
// et intitulés associés
|
30 |
// et intitulés associés
|
31 |
static $baseflor_col = array(
|
31 |
static $baseflor_col = array(
|
32 |
"ve_lumiere" => "Lumière",
|
32 |
"ve_lumiere" => "Lumière",
|
33 |
"ve_temperature" => "Température",
|
33 |
"ve_temperature" => "Température",
|
34 |
"ve_continentalite" => "Continentalité",
|
34 |
"ve_continentalite" => "Continentalité",
|
35 |
"ve_humidite_atmos" => "Humidité Atmosphérique",
|
35 |
"ve_humidite_atmos" => "Humidité Atmosphérique",
|
36 |
"ve_humidite_edaph" => "Humidité",
|
36 |
"ve_humidite_edaph" => "Humidité",
|
37 |
"ve_reaction_sol" => "Réaction (pH)",
|
37 |
"ve_reaction_sol" => "Réaction (pH)",
|
38 |
"ve_nutriments_sol" => "Nutriments",
|
38 |
"ve_nutriments_sol" => "Nutriments",
|
39 |
"ve_salinite" => "Salinité",
|
39 |
"ve_salinite" => "Salinité",
|
40 |
"ve_texture_sol" => "Texture" ,
|
40 |
"ve_texture_sol" => "Texture" ,
|
41 |
"ve_mat_org_sol" => "Matière Organique",
|
41 |
"ve_mat_org_sol" => "Matière Organique",
|
42 |
"catminat_code" => "Code Catminat",
|
42 |
"catminat_code" => "Code Catminat",
|
43 |
"syntaxon" => "Syntaxon",
|
43 |
"syntaxon" => "Syntaxon",
|
44 |
);
|
44 |
);
|
45 |
|
45 |
|
46 |
static function colGroupsValidation($groupe_de_champs = 'standard,avance') {
|
46 |
static function colGroupsValidation($groupe_de_champs = 'standard,avance') {
|
47 |
if(! $groupe_de_champs) return FALSE;
|
47 |
if(! $groupe_de_champs) return FALSE;
|
48 |
if(is_string($groupe_de_champs)) {
|
48 |
if(is_string($groupe_de_champs)) {
|
49 |
$groupe_de_champs = array_flip(explode(',', $groupe_de_champs));
|
49 |
$groupe_de_champs = array_flip(explode(',', $groupe_de_champs));
|
50 |
}
|
50 |
}
|
51 |
elseif(is_array($groupe_de_champs)) {
|
51 |
elseif(is_array($groupe_de_champs)) {
|
52 |
$groupe_de_champs = array_flip($groupe_de_champs);
|
52 |
$groupe_de_champs = array_flip($groupe_de_champs);
|
53 |
}
|
53 |
}
|
54 |
else {
|
54 |
else {
|
55 |
return NULL;
|
55 |
return NULL;
|
56 |
}
|
56 |
}
|
57 |
$groupe_de_champs = array_intersect_key(array_flip(self::$fieldGroups),
|
57 |
$groupe_de_champs = array_intersect_key(array_flip(self::$fieldGroups),
|
58 |
$groupe_de_champs);
|
58 |
$groupe_de_champs);
|
59 |
if(!$groupe_de_champs) return FALSE;
|
59 |
if(!$groupe_de_champs) return FALSE;
|
60 |
// toujours ajouter standard
|
60 |
// toujours ajouter standard
|
61 |
$groupe_de_champs['standard'] = TRUE;
|
61 |
$groupe_de_champs['standard'] = TRUE;
|
62 |
return implode(',', array_keys($groupe_de_champs));
|
62 |
return implode(',', array_keys($groupe_de_champs));
|
63 |
}
|
63 |
}
|
64 |
|
64 |
|
65 |
/*
|
65 |
/*
|
66 |
* @param $fieldSets: un liste de noms de colonnes ou de sets de colonnes
|
66 |
* @param $fieldSets: un liste de noms de colonnes ou de sets de colonnes
|
67 |
* séparés par des virgules
|
67 |
* séparés par des virgules
|
68 |
* eg: "espece" ou "champs-etendus", ...
|
68 |
* eg: "espece" ou "champs-etendus", ...
|
69 |
*
|
69 |
*
|
70 |
* @return: un tableau associatif déjà ordonné
|
70 |
* @return: un tableau associatif déjà ordonné
|
71 |
* clé: abbrev [machine-name] de la colonne (eg: "espece" ou "mot-clef")
|
71 |
* clé: abbrev [machine-name] de la colonne (eg: "espece" ou "mot-clef")
|
72 |
* valeur: des données relative à cette colonne, cf GenColInfo
|
72 |
* valeur: des données relative à cette colonne, cf GenColInfo
|
73 |
*
|
73 |
*
|
74 |
* @TODO: noms communs à part, gestion des champs étendus
|
74 |
* @TODO: noms communs à part, gestion des champs étendus
|
75 |
*
|
75 |
*
|
76 |
*/
|
76 |
*/
|
77 |
static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
|
77 |
static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
|
78 |
if(! $groupe_de_champs) $groupe_de_champs = 'standard';
|
78 |
if(! $groupe_de_champs) $groupe_de_champs = 'standard';
|
79 |
if(is_string($groupe_de_champs)) {
|
79 |
if(is_string($groupe_de_champs)) {
|
80 |
$groupe_de_champs = array_flip(explode(',', $groupe_de_champs));
|
80 |
$groupe_de_champs = array_flip(explode(',', $groupe_de_champs));
|
81 |
}
|
81 |
}
|
82 |
elseif(is_array($groupe_de_champs)) {
|
82 |
elseif(is_array($groupe_de_champs)) {
|
83 |
$groupe_de_champs = array_flip($groupe_de_champs);
|
83 |
$groupe_de_champs = array_flip($groupe_de_champs);
|
84 |
}
|
84 |
}
|
85 |
else {
|
85 |
else {
|
86 |
return NULL;
|
86 |
return NULL;
|
87 |
}
|
87 |
}
|
88 |
$groupe_de_champs = array_intersect_key(array_flip(self::$fieldGroups),
|
88 |
$groupe_de_champs = array_intersect_key(array_flip(self::$fieldGroups),
|
89 |
$groupe_de_champs);
|
89 |
$groupe_de_champs);
|
90 |
if(!$groupe_de_champs) return NULL;
|
90 |
if(!$groupe_de_champs) return NULL;
|
91 |
|
91 |
|
92 |
$colonnes = Array();
|
92 |
$colonnes = Array();
|
93 |
|
93 |
|
94 |
if(isset($groupe_de_champs['standard'])) {
|
94 |
if(isset($groupe_de_champs['standard'])) {
|
95 |
$colonnes += Array(
|
95 |
$colonnes += Array(
|
96 |
'nom_sel' => self::GenColInfo('nom_sel', 'Espèce'),
|
96 |
'nom_sel' => self::GenColInfo('nom_sel', 'Espèce'),
|
97 |
'nom_sel_nn' => self::GenColInfo('nom_sel_nn', 'Numéro nomenclatural', 0, NULL, NULL, FALSE),
|
97 |
'nom_sel_nn' => self::GenColInfo('nom_sel_nn', 'Numéro nomenclatural', 0, NULL, NULL, FALSE),
|
98 |
'nom_ret' => self::GenColInfo('nom_ret', 'Nom retenu', 0, NULL, NULL, FALSE),
|
98 |
'nom_ret' => self::GenColInfo('nom_ret', 'Nom retenu', 0, NULL, NULL, FALSE),
|
99 |
'nom_ret_nn' => self::GenColInfo('nom_ret_nn', 'Numéro nomenclatural nom retenu', 0, NULL, NULL, FALSE),
|
99 |
'nom_ret_nn' => self::GenColInfo('nom_ret_nn', 'Numéro nomenclatural nom retenu', 0, NULL, NULL, FALSE),
|
100 |
'nt' => self::GenColInfo('nt', 'Numéro taxonomique', 0, NULL, NULL, FALSE),
|
100 |
'nt' => self::GenColInfo('nt', 'Numéro taxonomique', 0, NULL, NULL, FALSE),
|
101 |
'famille' => self::GenColInfo('famille', 'Famille', 0, NULL, NULL, FALSE),
|
101 |
'famille' => self::GenColInfo('famille', 'Famille', 0, NULL, NULL, FALSE),
|
102 |
'nom_referentiel' => self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
|
102 |
'nom_referentiel' => self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
|
103 |
'zone_geo' => self::GenColInfo('zone_geo', 'Commune'),
|
103 |
'zone_geo' => self::GenColInfo('zone_geo', 'Commune'),
|
104 |
'ce_zone_geo' => self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
|
104 |
'ce_zone_geo' => self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
|
105 |
'date_observation' => self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
|
105 |
'date_observation' => self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
|
106 |
'lieudit' => self::GenColInfo('lieudit', 'Lieu-dit'),
|
106 |
'lieudit' => self::GenColInfo('lieudit', 'Lieu-dit'),
|
107 |
'station' => self::GenColInfo('station', 'Station'),
|
107 |
'station' => self::GenColInfo('station', 'Station'),
|
108 |
'milieu' => self::GenColInfo('milieu', 'Milieu'),
|
108 |
'milieu' => self::GenColInfo('milieu', 'Milieu'),
|
109 |
'commentaire' => self::GenColInfo('commentaire', 'Notes'),
|
109 |
'commentaire' => self::GenColInfo('commentaire', 'Notes'),
|
110 |
'latitude' => self::GenColInfo('latitude', 'Latitude', 1),
|
110 |
'latitude' => self::GenColInfo('latitude', 'Latitude', 1),
|
111 |
'longitude' => self::GenColInfo('longitude', 'Longitude', 1),
|
111 |
'longitude' => self::GenColInfo('longitude', 'Longitude', 1),
|
112 |
'altitude' => self::GenColInfo('altitude', 'Altitude', 1),
|
112 |
'altitude' => self::GenColInfo('altitude', 'Altitude', 1),
|
113 |
'geodatum' => self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
|
113 |
'geodatum' => self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
|
114 |
);
|
114 |
);
|
115 |
}
|
115 |
}
|
116 |
|
116 |
|
117 |
if(isset($groupe_de_champs['avance'])) {
|
117 |
if(isset($groupe_de_champs['avance'])) {
|
118 |
$colonnes += array(
|
118 |
$colonnes += array(
|
119 |
// TODO: importable = FALSE car pas de merge de données importées
|
119 |
// TODO: importable = FALSE car pas de merge de données importées
|
120 |
'ordre' => self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
|
120 |
'ordre' => self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
|
121 |
'id_observation' => self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
|
121 |
'id_observation' => self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
|
122 |
|
122 |
|
123 |
'mots_cles_texte' => self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
|
123 |
'mots_cles_texte' => self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
|
124 |
'commentaire' => self::GenColInfo('commentaire', 'Commentaires', 1),
|
124 |
'commentaire' => self::GenColInfo('commentaire', 'Commentaires', 1),
|
125 |
'date_creation' => self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
|
125 |
'date_creation' => self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
|
126 |
'date_modification' => self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),
|
126 |
'date_modification' => self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),
|
127 |
|
127 |
|
128 |
// rappel transmission = 1, signifie simplement "public"
|
128 |
// rappel transmission = 1, signifie simplement "public"
|
129 |
// des données importées peuvent être d'emblée "publiques"
|
129 |
// des données importées peuvent être d'emblée "publiques"
|
130 |
// "importable" = TRUE
|
130 |
// "importable" = TRUE
|
131 |
'transmission' => self::GenColInfo('transmission', 'Transmis', 1),
|
131 |
'transmission' => self::GenColInfo('transmission', 'Transmis', 1),
|
132 |
'date_transmission' => self::GenColInfo('date_transmission', 'Date Transmission', 1, NULL, NULL, FALSE),
|
132 |
'date_transmission' => self::GenColInfo('date_transmission', 'Date Transmission', 1, NULL, NULL, FALSE),
|
133 |
'abondance' => self::GenColInfo('abondance', 'Abondance', 1),
|
133 |
'abondance' => self::GenColInfo('abondance', 'Abondance', 1),
|
134 |
'certitude' => self::GenColInfo('certitude', 'Certitude', 1),
|
134 |
'certitude' => self::GenColInfo('certitude', 'Certitude', 1),
|
135 |
'phenologie' => self::GenColInfo('phenologie', 'Phénologie', 1),
|
135 |
'phenologie' => self::GenColInfo('phenologie', 'Phénologie', 1),
|
136 |
|
136 |
|
137 |
// XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
|
137 |
// XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
|
138 |
// cf ExportXLS::traiterLigneObservation()
|
138 |
// cf ExportXLS::traiterLigneObservation()
|
139 |
'images' => self::GenColInfo('images', 'Image(s)', 1, NULL, NULL /* cas particulier 'getImages' */, TRUE),
|
139 |
'images' => self::GenColInfo('images', 'Image(s)', 1, NULL, NULL /* cas particulier 'getImages' */, TRUE),
|
140 |
|
140 |
|
141 |
/* 'nom_commun' => self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
|
141 |
/* 'nom_commun' => self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
|
142 |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
|
142 |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
|
143 |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
|
143 |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
|
144 |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, NULL /* cas particu 'getNomCommun_v4' */, TRUE, array(__CLASS__, 'getNomCommun_preload')),
|
144 |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, NULL /* cas particu 'getNomCommun_v4' */, TRUE, array(__CLASS__, 'getNomCommun_preload')),
|
145 |
);
|
145 |
);
|
146 |
}
|
146 |
}
|
147 |
|
147 |
|
148 |
if(isset($groupe_de_champs['baseflor'])) {
|
148 |
if(isset($groupe_de_champs['baseflor'])) {
|
149 |
$colonnes += array(
|
149 |
$colonnes += array(
|
150 |
// champ dynamique
|
150 |
// champ dynamique
|
151 |
'baseflor' => self::GenColInfo('baseflor', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'baseflor_preload'), array(__CLASS__, 'baseflor_ligne')),
|
151 |
'baseflor' => self::GenColInfo('baseflor', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'baseflor_preload'), array(__CLASS__, 'baseflor_ligne')),
|
152 |
);
|
152 |
);
|
153 |
}
|
153 |
}
|
154 |
|
154 |
|
155 |
if(isset($groupe_de_champs['etendu'])) {
|
155 |
if(isset($groupe_de_champs['etendu'])) {
|
156 |
$colonnes += array(
|
156 |
$colonnes += array(
|
157 |
// champ dynamique
|
157 |
// champ dynamique
|
158 |
'etendu' => self::GenColInfo('etendu', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'champsEtendus_preload'), array(__CLASS__, 'champsEtendus_ligne')),
|
158 |
'etendu' => self::GenColInfo('etendu', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'champsEtendus_preload'), array(__CLASS__, 'champsEtendus_ligne')),
|
159 |
);
|
159 |
);
|
160 |
}
|
160 |
}
|
161 |
|
161 |
|
162 |
return $colonnes;
|
162 |
return $colonnes;
|
163 |
}
|
163 |
}
|
164 |
|
164 |
|
165 |
static function preload($colonnes, $cel, $ids) {
|
165 |
static function preload($colonnes, $cel, $ids) {
|
166 |
$result = array();
|
166 |
$result = array();
|
167 |
foreach($colonnes as $abbrev => $colonne) {
|
167 |
foreach($colonnes as $abbrev => $colonne) {
|
168 |
if(!$colonne['preload']) continue;
|
168 |
if(!$colonne['preload']) continue;
|
169 |
$result[$abbrev] = call_user_func($colonne['preload'], $cel, $ids);
|
169 |
$result[$abbrev] = call_user_func($colonne['preload'], $cel, $ids);
|
170 |
}
|
170 |
}
|
171 |
return $result;
|
171 |
return $result;
|
172 |
}
|
172 |
}
|
173 |
|
173 |
|
174 |
public static function getIntitulesColonnes($colonnes) {
|
174 |
public static function getIntitulesColonnes($colonnes) {
|
175 |
// array_filter pour supprimer les colonnes "dynamique" n'ayant pas défini $nom (cf GenColInfo())
|
175 |
// array_filter pour supprimer les colonnes "dynamique" n'ayant pas défini $nom (cf GenColInfo())
|
176 |
return array_filter(array_map(array('FormateurGroupeColonne', 'retournerNomItem'), $colonnes));
|
176 |
return array_filter(array_map(array('FormateurGroupeColonne', 'retournerNomItem'), $colonnes));
|
177 |
}
|
177 |
}
|
178 |
|
178 |
|
179 |
public static function retournerNomItem(&$item) {
|
179 |
public static function retournerNomItem(&$item) {
|
180 |
return $item['nom'];
|
180 |
return $item['nom'];
|
181 |
}
|
181 |
}
|
182 |
|
182 |
|
183 |
public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
|
183 |
public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
|
184 |
|
184 |
|
185 |
$ligne_formatee = array();
|
185 |
$ligne_formatee = array();
|
186 |
foreach($colonnes as $abbrev => $colonne) {
|
186 |
foreach($colonnes as $abbrev => $colonne) {
|
187 |
$valeur = null;
|
187 |
$valeur = null;
|
188 |
if($colonne['extra'] == 2 || ! is_null($colonne['dyna'])) continue;
|
188 |
if($colonne['extra'] == 2 || ! is_null($colonne['dyna'])) continue;
|
189 |
|
189 |
|
190 |
// valeur direct depuis cel_obs ?
|
190 |
// valeur direct depuis cel_obs ?
|
191 |
if(isset($obs[$abbrev])) $valeur = $obs[$abbrev];
|
191 |
if(isset($obs[$abbrev])) $valeur = $obs[$abbrev];
|
192 |
|
192 |
|
193 |
// pré-processeur de la champs
|
193 |
// pré-processeur de la champs
|
194 |
if(function_exists($colonne['fonction'])) {
|
194 |
if(function_exists($colonne['fonction'])) {
|
195 |
$valeur = $colonne['fonction']($valeur);
|
195 |
$valeur = $colonne['fonction']($valeur);
|
196 |
} elseif(method_exists(__CLASS__, $colonne['fonction'])) {
|
196 |
} elseif(method_exists(__CLASS__, $colonne['fonction'])) {
|
197 |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction']), $valeur);
|
197 |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction']), $valeur);
|
198 |
} elseif($colonne['fonction']) {
|
198 |
} elseif($colonne['fonction']) {
|
199 |
die("méthode {$colonne['fonction']} introuvable");
|
199 |
die("méthode {$colonne['fonction']} introuvable");
|
200 |
}
|
200 |
}
|
201 |
// fonction pour obtenir des champs (étendus)
|
201 |
// fonction pour obtenir des champs (étendus)
|
202 |
elseif(function_exists($colonne['fonction_data'])) {
|
202 |
elseif(function_exists($colonne['fonction_data'])) {
|
203 |
$valeur = $colonne['fonction_data']($obs);
|
203 |
$valeur = $colonne['fonction_data']($obs);
|
204 |
}
|
204 |
}
|
205 |
elseif(method_exists(__CLASS__, $colonne['fonction_data'])) {
|
205 |
elseif(method_exists(__CLASS__, $colonne['fonction_data'])) {
|
206 |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs);
|
206 |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs);
|
207 |
}
|
207 |
}
|
208 |
|
208 |
|
209 |
// // cette section devrait être vide:
|
209 |
// // cette section devrait être vide:
|
210 |
// // cas particuliers ingérable avec l'architecture actuelle:
|
210 |
// // cas particuliers ingérable avec l'architecture actuelle:
|
211 |
if(false && $abbrev == 'date_observation' && $valeur == "0000-00-00") {
|
211 |
if(false && $abbrev == 'date_observation' && $valeur == "0000-00-00") {
|
212 |
/* blah */
|
212 |
/* blah */
|
213 |
}
|
213 |
}
|
214 |
// ici à cause du passage de $cel ($this), TODO: DB en Singleton !
|
214 |
// ici à cause du passage de $cel ($this), TODO: DB en Singleton !
|
215 |
if($abbrev == 'images') {
|
215 |
if($abbrev == 'images') {
|
216 |
$valeur = FormateurGroupeColonne::getImages($obs, $cel->id_utilisateur, $cel);
|
216 |
$valeur = FormateurGroupeColonne::getImages($obs, $cel->id_utilisateur, $cel);
|
217 |
}
|
217 |
}
|
218 |
if($abbrev == 'nom-commun') {
|
218 |
if($abbrev == 'nom-commun') {
|
219 |
$valeur = FormateurGroupeColonne::getNomCommun_v4($obs, $cel);
|
219 |
$valeur = FormateurGroupeColonne::getNomCommun_v4($obs, $cel);
|
220 |
}
|
220 |
}
|
221 |
|
221 |
|
222 |
if($valeur == null) {
|
222 |
if($valeur == null) {
|
223 |
$valeur = "";
|
223 |
$valeur = "";
|
224 |
}
|
224 |
}
|
225 |
|
225 |
|
226 |
// // fin de section "cas particuliers"
|
226 |
// // fin de section "cas particuliers"
|
227 |
$ligne_formatee[] = $valeur;
|
227 |
$ligne_formatee[] = $valeur;
|
228 |
}
|
228 |
}
|
229 |
|
229 |
|
230 |
// uniquement les champŝ dynamiques
|
230 |
// uniquement les champŝ dynamiques
|
231 |
foreach($colonnes as $abbrev => $colonne) {
|
231 |
foreach($colonnes as $abbrev => $colonne) {
|
232 |
$valeur = null;
|
232 |
$valeur = null;
|
233 |
if(is_null($colonne['dyna'])) continue;
|
233 |
if(is_null($colonne['dyna'])) continue;
|
234 |
// XXX: PHP-5.3
|
234 |
// XXX: PHP-5.3
|
235 |
call_user_func_array($colonne['dyna'],
|
235 |
call_user_func_array($colonne['dyna'],
|
236 |
array($cel, $obs, &$ligne_formatee));
|
236 |
array($cel, $obs, &$ligne_formatee));
|
237 |
}
|
237 |
}
|
238 |
|
238 |
|
239 |
return $ligne_formatee;
|
239 |
return $ligne_formatee;
|
240 |
}
|
240 |
}
|
241 |
|
241 |
|
242 |
/*
|
242 |
/*
|
243 |
* Wrapper générant un tableau associatif:
|
243 |
* Wrapper générant un tableau associatif:
|
244 |
* Ne pas changer les valeurs par défaut du prototype sans réflexion sur l'implication pour nomEnsembleVersListeColonnes()
|
244 |
* Ne pas changer les valeurs par défaut du prototype sans réflexion sur l'implication pour nomEnsembleVersListeColonnes()
|
245 |
|
245 |
|
246 |
* @param $abbrev (obligatoire): nom court de colonne, largement utilisé lors de l'import.
|
246 |
* @param $abbrev (obligatoire): nom court de colonne, largement utilisé lors de l'import.
|
247 |
* En effet chaque ligne importée est accessible à l'aide du `define` de $abbrev en majuscule, préfixé de "C_"
|
247 |
* En effet chaque ligne importée est accessible à l'aide du `define` de $abbrev en majuscule, préfixé de "C_"
|
248 |
* Exemple: $ligne[C_LONGITUDE] pour "longitude".
|
248 |
* Exemple: $ligne[C_LONGITUDE] pour "longitude".
|
249 |
* cf: ImportXLS::detectionEntete()
|
249 |
* cf: ImportXLS::detectionEntete()
|
250 |
|
250 |
|
251 |
* @param $nom (obligatoire): nom complet de colonne (utilisé pour la ligne d'en-tête)
|
251 |
* @param $nom (obligatoire): nom complet de colonne (utilisé pour la ligne d'en-tête)
|
252 |
* Les définition de champs dynamique (correspondant à de multiples colonnes) doivent laisser cette valeur
|
252 |
* Les définition de champs dynamique (correspondant à de multiples colonnes) doivent laisser cette valeur
|
253 |
* vide afin de ne pas créer une colonne supplémentaire erronée.
|
253 |
* vide afin de ne pas créer une colonne supplémentaire erronée.
|
254 |
|
254 |
|
255 |
* @param $is_extra:
|
255 |
* @param $is_extra:
|
256 |
* Si 0, la colonne est une colonne standard
|
256 |
* Si 0, la colonne est une colonne standard
|
257 |
* Si 1, la colonne est extra [le plus souvent générée automatiquement]
|
257 |
* Si 1, la colonne est extra [le plus souvent générée automatiquement]
|
258 |
* (auquel cas une bordure bleue entoure son nom dans la ligne d'entête)
|
258 |
* (auquel cas une bordure bleue entoure son nom dans la ligne d'entête)
|
259 |
* Si 2, la colonne n'est pas traité à l'export, mais une définition peut lui être donnée
|
259 |
* Si 2, la colonne n'est pas traité à l'export, mais une définition peut lui être donnée
|
260 |
* qui pourra être utilisée à l'import, exemple: "image"
|
260 |
* qui pourra être utilisée à l'import, exemple: "image"
|
261 |
|
261 |
|
262 |
* @param $fonction (optionnel): un nom d'un fonction de préprocessing
|
262 |
* @param $fonction (optionnel): un nom d'un fonction de préprocessing
|
263 |
* $fonction doit prendre comme seul argument la valeur d'origine et retourner la valeur transformée
|
263 |
* $fonction doit prendre comme seul argument la valeur d'origine et retourner la valeur transformée
|
264 |
|
264 |
|
265 |
* @param $fonction_data (optionnel): une *méthode* d'obtention de donnée
|
265 |
* @param $fonction_data (optionnel): une *méthode* d'obtention de donnée
|
266 |
* $fonction_data doit prendre comme premier argument le tableau des champs de l'enregistrement existant
|
266 |
* $fonction_data doit prendre comme premier argument le tableau des champs de l'enregistrement existant
|
267 |
* $fonction_data doit retourner une valeur
|
267 |
* $fonction_data doit retourner une valeur
|
268 |
|
268 |
|
269 |
* @param $importable (optionnel): défini si la colonne est traitée (ou absolument ignorée par PHPExcel) lors de
|
269 |
* @param $importable (optionnel): défini si la colonne est traitée (ou absolument ignorée par PHPExcel) lors de
|
270 |
* l'import.
|
270 |
* l'import.
|
271 |
|
271 |
|
272 |
* @param $preload (optionnel): défini une fonction de préchargement massif de donnée potentiellement utilisable par $fonction_data.
|
272 |
* @param $preload (optionnel): défini une fonction de préchargement massif de donnée potentiellement utilisable par $fonction_data.
|
273 |
* Utile, notamment, dans le cadre de l'export
|
273 |
* Utile, notamment, dans le cadre de l'export
|
274 |
|
274 |
|
275 |
* @param $fonction_dynamique (optionnel): défini une fonction ajoutant un nombre arbitraire de colonnes à une ligne donnée
|
275 |
* @param $fonction_dynamique (optionnel): défini une fonction ajoutant un nombre arbitraire de colonnes à une ligne donnée
|
276 |
* Utile, notamment, dans le cadre de l'export des champs étendus ou des données baseflor
|
276 |
* Utile, notamment, dans le cadre de l'export des champs étendus ou des données baseflor
|
277 |
* La fonction doit TOUJOURS alterer la ligne en lui ajoutant une nombre CONSTANT d'éléments (NULL ou non)
|
277 |
* La fonction doit TOUJOURS alterer la ligne en lui ajoutant une nombre CONSTANT d'éléments (NULL ou non)
|
278 |
* La fonction doit prendre comme arguments ($cel, $obs, &$ligne_formatee)
|
278 |
* La fonction doit prendre comme arguments ($cel, $obs, &$ligne_formatee)
|
279 |
*/
|
279 |
*/
|
280 |
static function GenColInfo($abbrev, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL, $importable = TRUE, $preload = NULL, $fonction_dynamique = NULL) {
|
280 |
static function GenColInfo($abbrev, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL, $importable = TRUE, $preload = NULL, $fonction_dynamique = NULL) {
|
281 |
return Array('abbrev' => $abbrev,
|
281 |
return Array('abbrev' => $abbrev,
|
282 |
'nom' => $nom,
|
282 |
'nom' => $nom,
|
283 |
'extra' => $is_extra ? 1 : 0,
|
283 |
'extra' => $is_extra ? 1 : 0,
|
284 |
'fonction' => $fonction,
|
284 |
'fonction' => $fonction,
|
285 |
'fonction_data' => $fonction_data,
|
285 |
'fonction_data' => $fonction_data,
|
286 |
'importable' => $importable,
|
286 |
'importable' => $importable,
|
287 |
'preload' => $preload,
|
287 |
'preload' => $preload,
|
288 |
'dyna' => $fonction_dynamique,
|
288 |
'dyna' => $fonction_dynamique,
|
289 |
);
|
289 |
);
|
290 |
}
|
290 |
}
|
291 |
|
291 |
|
292 |
static function formaterDate($date_heure_mysql) {
|
292 |
static function formaterDate($date_heure_mysql) {
|
293 |
//return "";
|
293 |
//return "";
|
294 |
if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return NULL;
|
294 |
if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return NULL;
|
295 |
// malheureusement pas disponible en php < 5.3
|
295 |
// malheureusement pas disponible en php < 5.3
|
296 |
//$date_format = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql);
|
296 |
//$date_format = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql);
|
297 |
$val = explode(' ', $date_heure_mysql);
|
297 |
$val = explode(' ', $date_heure_mysql);
|
298 |
$date = explode('-', $val[0]);
|
298 |
$date = explode('-', $val[0]);
|
299 |
$heure = explode(':', $val[1]);
|
299 |
$heure = explode(':', $val[1]);
|
300 |
$timestamp = mktime((int) $heure[0], (int) $heure[1], (int) $heure[2], (int) $date[1], (int) $date[2], (int) $date[0]);
|
300 |
$timestamp = mktime((int) $heure[0], (int) $heure[1], (int) $heure[2], (int) $date[1], (int) $date[2], (int) $date[0]);
|
301 |
if(!$timestamp) return NULL;
|
301 |
if(!$timestamp) return NULL;
|
302 |
// TODO: les widgets ne font malheureusement pas usage de l'heure dans le CEL
|
302 |
// TODO: les widgets ne font malheureusement pas usage de l'heure dans le CEL
|
303 |
// TODO: si modification, ne pas oublier de modifier le format d'import correspondant
|
303 |
// TODO: si modification, ne pas oublier de modifier le format d'import correspondant
|
304 |
// dans ImportXLS, traiterDateObs() (actuellement: "Y/m/d" car utilisation de strtotime() qui ne lit pas tout)
|
304 |
// dans ImportXLS, traiterDateObs() (actuellement: "Y/m/d" car utilisation de strtotime() qui ne lit pas tout)
|
305 |
// $date_formatee = strftime('%d/%m/%Y', $timestamp);
|
305 |
// $date_formatee = strftime('%d/%m/%Y', $timestamp);
|
306 |
$date_formatee = strftime('%Y/%m/%d', $timestamp);
|
306 |
$date_formatee = strftime('%Y/%m/%d', $timestamp);
|
307 |
if(!$date_formatee) return "00/00/0000";
|
307 |
if(!$date_formatee) return "00/00/0000";
|
308 |
return $date_formatee;
|
308 |
return $date_formatee;
|
309 |
}
|
309 |
}
|
310 |
|
310 |
|
311 |
static function getImages($obs, $id_utilisateur, $cel) {
|
311 |
static function getImages($obs, $id_utilisateur, $cel) {
|
312 |
if(! $id_utilisateur) return NULL;
|
312 |
if(! $id_utilisateur) return NULL;
|
313 |
$rec = $cel->requeter(
|
313 |
$rec = $cel->requeter(
|
314 |
sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
|
314 |
sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
|
315 |
." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
|
315 |
." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
|
316 |
." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
|
316 |
." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
|
317 |
." WHERE ce_utilisateur = %d",
|
317 |
." WHERE ce_utilisateur = %d",
|
318 |
SEPARATEUR_IMAGES,
|
318 |
SEPARATEUR_IMAGES,
|
319 |
$id_utilisateur));
|
319 |
$id_utilisateur));
|
320 |
return $rec ? array_pop($rec) : NULL;
|
320 |
return $rec ? array_pop($rec) : NULL;
|
321 |
}
|
321 |
}
|
322 |
|
322 |
|
323 |
public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {
|
323 |
public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {
|
324 |
$code_departement = '';
|
324 |
$code_departement = '';
|
325 |
if(self::estUnCodeInseeDepartement($code_zone_geo)) {
|
325 |
if(self::estUnCodeInseeDepartement($code_zone_geo)) {
|
326 |
$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2);
|
326 |
$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2);
|
327 |
}
|
327 |
}
|
328 |
|
328 |
|
329 |
return $code_departement;
|
329 |
return $code_departement;
|
330 |
}
|
330 |
}
|
331 |
|
331 |
|
332 |
public static function estUnCodeInseeDepartement($code_a_tester) {
|
332 |
public static function estUnCodeInseeDepartement($code_a_tester) {
|
333 |
return preg_match('/^INSEE-C:[0-9]{5}/',$code_a_tester);
|
333 |
return preg_match('/^INSEE-C:[0-9]{5}/',$code_a_tester);
|
334 |
}
|
334 |
}
|
335 |
|
335 |
|
336 |
|
336 |
|
337 |
// TODO: référentiel ne devrait pas être généré au moment d'un Config::get,
|
337 |
// TODO: référentiel ne devrait pas être généré au moment d'un Config::get,
|
338 |
// comme dans Config::get('nomsVernaRechercheLimiteeTpl')
|
338 |
// comme dans Config::get('nomsVernaRechercheLimiteeTpl')
|
339 |
// Par exemple, la variable pour "nva" ?
|
339 |
// Par exemple, la variable pour "nva" ?
|
340 |
function getNomCommun($obs) {
|
340 |
function getNomCommun($obs) {
|
341 |
$langue = 'fra';
|
341 |
$langue = 'fra';
|
342 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
342 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
343 |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
|
343 |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
|
344 |
else return '';
|
344 |
else return '';
|
345 |
|
345 |
|
346 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
346 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
347 |
if(isset(self::$cache['getNomCommun'][$cache_id])) {
|
347 |
if(isset(self::$cache['getNomCommun'][$cache_id])) {
|
348 |
//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")");
|
348 |
//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")");
|
349 |
return self::$cache['getNomCommun'][$cache_id];
|
349 |
return self::$cache['getNomCommun'][$cache_id];
|
350 |
}
|
350 |
}
|
351 |
// pas de cache:
|
351 |
// pas de cache:
|
352 |
//debug: error_log("require url_service_nom_attribution pour \"{$obs['nom_ret']}\"");
|
352 |
//debug: error_log("require url_service_nom_attribution pour \"{$obs['nom_ret']}\"");
|
353 |
|
353 |
|
354 |
// pour bdtfx:
|
354 |
// pour bdtfx:
|
355 |
// /service:eflore:0.1/nvjfl/noms-vernaculaires/attributions?masque.nt=X&masque.lg=fra&retour.champs=num_statut
|
355 |
// /service:eflore:0.1/nvjfl/noms-vernaculaires/attributions?masque.nt=X&masque.lg=fra&retour.champs=num_statut
|
356 |
// /projet/services/modules/0.1/nvjfl/NomsVernaculaires.php
|
356 |
// /projet/services/modules/0.1/nvjfl/NomsVernaculaires.php
|
357 |
$url = str_replace(Array('{referentiel}', '{valeur}', '{langue}'),
|
357 |
$url = str_replace(Array('{referentiel}', '{valeur}', '{langue}'),
|
358 |
Array($referentiel, $obs['nt'], $langue),
|
358 |
Array($referentiel, $obs['nt'], $langue),
|
359 |
self::$config['eflore']['url_service_nom_attribution']) . // TODO !
|
359 |
self::$config['eflore']['url_service_nom_attribution']) . // TODO !
|
360 |
"&retour.champs=num_statut";
|
360 |
"&retour.champs=num_statut";
|
361 |
$noms = @json_decode(file_get_contents($url));
|
361 |
$noms = @json_decode(file_get_contents($url));
|
362 |
if(! $noms) return '';
|
362 |
if(! $noms) return '';
|
363 |
$noms = array_filter((array)($noms->resultat), array($this, retournerNumStatutUn)); // XXX: php 5.3
|
363 |
$noms = array_filter((array)($noms->resultat), array($this, retournerNumStatutUn)); // XXX: php 5.3
|
364 |
$nom = array_pop($noms)->nom_vernaculaire;
|
364 |
$nom = array_pop($noms)->nom_vernaculaire;
|
365 |
|
365 |
|
366 |
// cache
|
366 |
// cache
|
367 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
367 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
368 |
return $nom;
|
368 |
return $nom;
|
369 |
}
|
369 |
}
|
370 |
|
370 |
|
371 |
private function retournerNumStatutUn(&$item) {
|
371 |
private function retournerNumStatutUn(&$item) {
|
372 |
return ($item->num_statut == 1);
|
372 |
return ($item->num_statut == 1);
|
373 |
}
|
373 |
}
|
374 |
|
374 |
|
375 |
private function retournerNumStatutUnArr(&$item) {
|
375 |
private function retournerNumStatutUnArr(&$item) {
|
376 |
return ($item['num_statut'] == 1);
|
376 |
return ($item['num_statut'] == 1);
|
377 |
}
|
377 |
}
|
378 |
|
378 |
|
379 |
// si getNomCommun_v2 ou getNomCommun_v3 sont utilisés
|
379 |
// si getNomCommun_v2 ou getNomCommun_v3 sont utilisés
|
380 |
/* require_once('/home/raphael/eflore/framework/framework/Framework.php');
|
380 |
/* require_once('/home/raphael/eflore/framework/framework/Framework.php');
|
381 |
Framework::setCheminAppli("/home/raphael/eflore/projets/services/index.php");
|
381 |
Framework::setCheminAppli("/home/raphael/eflore/projets/services/index.php");
|
382 |
Framework::setInfoAppli(Config::get('info'));
|
382 |
Framework::setInfoAppli(Config::get('info'));
|
383 |
require_once('/home/raphael/eflore/projets/services/modules/0.1/Projets.php');*/
|
383 |
require_once('/home/raphael/eflore/projets/services/modules/0.1/Projets.php');*/
|
384 |
|
384 |
|
385 |
/* Tente de bootstraper le framework au plus court et d'initialiser une instance de
|
385 |
/* Tente de bootstraper le framework au plus court et d'initialiser une instance de
|
386 |
NomsVernaculaires pour obtenir le nom commun */
|
386 |
NomsVernaculaires pour obtenir le nom commun */
|
387 |
function getNomCommun_v2($obs) {
|
387 |
function getNomCommun_v2($obs) {
|
388 |
static $service;
|
388 |
static $service;
|
389 |
$service = new Projets();
|
389 |
$service = new Projets();
|
390 |
|
390 |
|
391 |
$langue = 'fra';
|
391 |
$langue = 'fra';
|
392 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
392 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
393 |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
|
393 |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
|
394 |
else return '';
|
394 |
else return '';
|
395 |
|
395 |
|
396 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
396 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
397 |
if(isset(self::$cache['getNomCommun'][$cache_id])) {
|
397 |
if(isset(self::$cache['getNomCommun'][$cache_id])) {
|
398 |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
|
398 |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
|
399 |
return self::$cache['getNomCommun'][$cache_id];
|
399 |
return self::$cache['getNomCommun'][$cache_id];
|
400 |
}
|
400 |
}
|
401 |
// pas de cache:
|
401 |
// pas de cache:
|
402 |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
|
402 |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
|
403 |
|
403 |
|
404 |
$donnees = Array('masque.nt' => $obs['nt'],
|
404 |
$donnees = Array('masque.nt' => $obs['nt'],
|
405 |
'masque.lg' => $langue,
|
405 |
'masque.lg' => $langue,
|
406 |
'retour.champs' => 'num_statut');
|
406 |
'retour.champs' => 'num_statut');
|
407 |
$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $donnees);
|
407 |
$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $donnees);
|
408 |
|
408 |
|
409 |
if(! $noms) return '';
|
409 |
if(! $noms) return '';
|
410 |
$noms = array_filter((array)($noms->resultat), array($this, retournerNumStatutUn)); // XXX: php 5.3
|
410 |
$noms = array_filter((array)($noms->resultat), array($this, retournerNumStatutUn)); // XXX: php 5.3
|
411 |
$nom = array_pop($noms)->nom_vernaculaire;
|
411 |
$nom = array_pop($noms)->nom_vernaculaire;
|
412 |
|
412 |
|
413 |
// cache
|
413 |
// cache
|
414 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
414 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
415 |
return $nom;
|
415 |
return $nom;
|
416 |
}
|
416 |
}
|
417 |
|
417 |
|
418 |
|
418 |
|
419 |
/* Effectue un bootstraping plus sage que ci-dessus, mais le gain d'efficacité
|
419 |
/* Effectue un bootstraping plus sage que ci-dessus, mais le gain d'efficacité
|
420 |
n'est pas aussi retentissant qu'espéré */
|
420 |
n'est pas aussi retentissant qu'espéré */
|
421 |
static $service;
|
421 |
static $service;
|
422 |
function getNomCommun_v3($obs) {
|
422 |
function getNomCommun_v3($obs) {
|
423 |
if(! $this->service) $this->service = new Projets();
|
423 |
if(! $this->service) $this->service = new Projets();
|
424 |
|
424 |
|
425 |
$langue = 'fra';
|
425 |
$langue = 'fra';
|
426 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
426 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
427 |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
|
427 |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
|
428 |
else return '';
|
428 |
else return '';
|
429 |
|
429 |
|
430 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
430 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
431 |
if(isset(self::$cache['getNomCommun'][$cache_id])) {
|
431 |
if(isset(self::$cache['getNomCommun'][$cache_id])) {
|
432 |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
|
432 |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
|
433 |
return self::$cache['getNomCommun'][$cache_id];
|
433 |
return self::$cache['getNomCommun'][$cache_id];
|
434 |
}
|
434 |
}
|
435 |
// pas de cache:
|
435 |
// pas de cache:
|
436 |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
|
436 |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
|
437 |
|
437 |
|
438 |
$donnees = Array('masque.nt' => $obs['nt'],
|
438 |
$donnees = Array('masque.nt' => $obs['nt'],
|
439 |
'masque.lg' => $langue,
|
439 |
'masque.lg' => $langue,
|
440 |
'retour.champs' => 'conseil_emploi');
|
440 |
'retour.champs' => 'conseil_emploi');
|
441 |
$this->service->initialiserRessourcesEtParametres(Array('nvjfl', 'noms-vernaculaires', 'attributions'), $donnees);
|
441 |
$this->service->initialiserRessourcesEtParametres(Array('nvjfl', 'noms-vernaculaires', 'attributions'), $donnees);
|
442 |
try {
|
442 |
try {
|
443 |
$noms = $this->service->traiterRessources();
|
443 |
$noms = $this->service->traiterRessources();
|
444 |
} catch(Exception $e) {
|
444 |
} catch(Exception $e) {
|
445 |
return '';
|
445 |
return '';
|
446 |
}
|
446 |
}
|
447 |
if(! $noms) return '';
|
447 |
if(! $noms) return '';
|
448 |
$noms = array_filter($noms['resultat'], array($this, retournerNumStatutUnArr)); // XXX: php 5.3
|
448 |
$noms = array_filter($noms['resultat'], array($this, retournerNumStatutUnArr)); // XXX: php 5.3
|
449 |
$premier_nom = array_pop($noms);
|
449 |
$premier_nom = array_pop($noms);
|
450 |
$nom = $premier_nom['nom_vernaculaire'];
|
450 |
$nom = $premier_nom['nom_vernaculaire'];
|
451 |
|
451 |
|
452 |
// cache
|
452 |
// cache
|
453 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
453 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
454 |
return $nom;
|
454 |
return $nom;
|
455 |
}
|
455 |
}
|
456 |
|
456 |
|
457 |
/* Cette fonction initialise le cache des noms communs en 1 fois, sur la liste des observations à exporter.
|
457 |
/* Cette fonction initialise le cache des noms communs en 1 fois, sur la liste des observations à exporter.
|
458 |
Ainsi, les appels successifs à getNomCommun_v4() ne sont pas couteux (pas de requête SQL) */
|
458 |
Ainsi, les appels successifs à getNomCommun_v4() ne sont pas couteux (pas de requête SQL) */
|
459 |
static function getNomCommun_preload($cel, $obsids) {
|
459 |
static function getNomCommun_preload($cel, $obsids) {
|
460 |
if(!$obsids) return;
|
460 |
if(!$obsids) return;
|
461 |
if(!self::referenceTableExiste($cel)) return NULL;
|
461 |
if(!self::referenceTableExiste($cel)) return NULL;
|
462 |
|
462 |
|
463 |
// CREATE INDEX i_nom_referentiel ON cel_obs (nom_referentiel(5));
|
463 |
// CREATE INDEX i_nom_referentiel ON cel_obs (nom_referentiel(5));
|
464 |
$req = sprintf("SELECT r.referentiel, r.num_taxon, r.nom_commun FROM cel_references r" .
|
464 |
$req = sprintf("SELECT r.referentiel, r.num_taxon, r.nom_commun FROM cel_references r" .
|
465 |
" INNER JOIN cel_obs c ON (r.referentiel = substring_index(c.nom_referentiel, ':', 1) and r.num_taxon = c.nt)" .
|
465 |
" INNER JOIN cel_obs c ON (r.referentiel = substring_index(c.nom_referentiel, ':', 1) and r.num_taxon = c.nt)" .
|
466 |
" WHERE c.id_observation IN (%s)",
|
466 |
" WHERE c.id_observation IN (%s)",
|
467 |
implode(',', $obsids));
|
467 |
implode(',', $obsids));
|
468 |
$res = $cel->requeter($req);
|
468 |
$res = $cel->requeter($req);
|
469 |
foreach($res as $v) {
|
469 |
foreach($res as $v) {
|
470 |
self::$cache['getNomCommun'][$v['referentiel'] . '-' . $v['num_taxon'] . '-' . 'fra'] = $v['nom_commun'];
|
470 |
self::$cache['getNomCommun'][$v['referentiel'] . '-' . $v['num_taxon'] . '-' . 'fra'] = $v['nom_commun'];
|
471 |
}
|
471 |
}
|
472 |
return NULL;
|
472 |
return NULL;
|
473 |
}
|
473 |
}
|
474 |
|
474 |
|
475 |
static function referenceTableExiste($cel) {
|
475 |
static function referenceTableExiste($cel) {
|
476 |
if(!self::$is_table) {
|
476 |
if(!self::$is_table) {
|
477 |
// une seule fois
|
477 |
// une seule fois
|
478 |
if(! $cel->executerRequete("SHOW TABLES LIKE 'cel_references'", Cel::SQL_RETOUR_LIGNE)) return FALSE;
|
478 |
if(! $cel->executerRequete("SHOW TABLES LIKE 'cel_references'", Cel::SQL_RETOUR_LIGNE)) return FALSE;
|
479 |
self::$is_table = TRUE;
|
479 |
self::$is_table = TRUE;
|
480 |
}
|
480 |
}
|
481 |
return TRUE;
|
481 |
return TRUE;
|
482 |
}
|
482 |
}
|
483 |
|
483 |
|
484 |
static function getNomCommun_v4($obs, $cel) {
|
484 |
static function getNomCommun_v4($obs, $cel) {
|
485 |
if(! $obs['nt']) return NULL;
|
485 |
if(! $obs['nt']) return NULL;
|
486 |
if(! self::referenceTableExiste($cel)) return NULL;
|
486 |
if(! self::referenceTableExiste($cel)) return NULL;
|
487 |
|
487 |
|
488 |
$langue = 'fra';
|
488 |
$langue = 'fra';
|
489 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
489 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
490 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
490 |
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
|
491 |
|
491 |
|
492 |
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
|
492 |
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
|
493 |
// XXX: problème de valeurs NULL ?
|
493 |
// XXX: problème de valeurs NULL ?
|
494 |
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
|
494 |
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
|
495 |
|
495 |
|
496 |
// pas de cache:
|
496 |
// pas de cache:
|
497 |
$nom = $cel->executerRequete(sprintf("SELECT nom_commun FROM cel_references " .
|
497 |
$nom = $cel->executerRequete(sprintf("SELECT nom_commun FROM cel_references " .
|
498 |
"WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1",
|
498 |
"WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1",
|
499 |
$referentiel,
|
499 |
$referentiel,
|
500 |
$obs['nt']),
|
500 |
$obs['nt']),
|
501 |
Cel::SQL_RETOUR_LIGNE);
|
501 |
Cel::SQL_RETOUR_LIGNE);
|
502 |
|
502 |
|
503 |
if(! $nom) return NULL;
|
503 |
if(! $nom) return NULL;
|
504 |
$nom = $nom["nom_commun"];
|
504 |
$nom = $nom["nom_commun"];
|
505 |
|
505 |
|
506 |
// cache
|
506 |
// cache
|
507 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
507 |
self::$cache['getNomCommun'][$cache_id] = $nom;
|
508 |
return $nom;
|
508 |
return $nom;
|
509 |
}
|
509 |
}
|
510 |
|
510 |
|
511 |
|
511 |
|
512 |
/* Cette fonction initialise le cache des données baseflor en 1 fois, sur la liste des observations à exporter.
|
512 |
/* Cette fonction initialise le cache des données baseflor en 1 fois, sur la liste des observations à exporter.
|
513 |
Ainsi, les appels successifs à baseflor_ligne() ne sont pas couteux (pas de requête SQL) */
|
513 |
Ainsi, les appels successifs à baseflor_ligne() ne sont pas couteux (pas de requête SQL) */
|
514 |
static function baseflor_preload($cel, $obsids) {
|
514 |
static function baseflor_preload($cel, $obsids) {
|
515 |
if(!$obsids) return;
|
515 |
if(!$obsids) return;
|
516 |
if(!self::referenceTableExiste($cel)) return NULL;
|
516 |
if(!self::referenceTableExiste($cel)) return NULL;
|
517 |
|
517 |
|
518 |
$req = sprintf("SELECT referentiel, num_nom_retenu, %s FROM cel_references r" .
|
518 |
$req = sprintf("SELECT referentiel, num_nom_retenu, %s FROM cel_references r" .
|
519 |
" INNER JOIN cel_obs c ON (r.num_nom_retenu = c.nom_ret_nn)" .
|
519 |
" INNER JOIN cel_obs c ON (r.num_nom_retenu = c.nom_ret_nn)" .
|
520 |
" WHERE c.id_observation IN (%s)",
|
520 |
" WHERE c.id_observation IN (%s)",
|
521 |
//" AND catminat_code IS NOT NULL", // TODO: suppression des NULL ici signifie que le cache sera partiel...
|
521 |
//" AND catminat_code IS NOT NULL", // TODO: suppression des NULL ici signifie que le cache sera partiel...
|
522 |
implode(',', array_keys(self::$baseflor_col)),
|
522 |
implode(',', array_keys(self::$baseflor_col)),
|
523 |
implode(',', $obsids));
|
523 |
implode(',', $obsids));
|
524 |
$res = $cel->requeter($req);
|
524 |
$res = $cel->requeter($req);
|
525 |
if(!$res) return NULL;
|
525 |
if(!$res) return NULL;
|
526 |
|
526 |
|
527 |
foreach($res as $v) {
|
527 |
foreach($res as $v) {
|
528 |
$data = $v;
|
528 |
$data = $v;
|
529 |
unset($data['referentiel']); // non nécessaire
|
529 |
unset($data['referentiel']); // non nécessaire
|
530 |
unset($data['num_nom_retenu']); // non nécessaire
|
530 |
unset($data['num_nom_retenu']); // non nécessaire
|
531 |
self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']] = $data;
|
531 |
self::$cache['getBaseflor'][$v['referentiel'] . '-' . $v['num_nom_retenu']] = $data;
|
532 |
}
|
532 |
}
|
533 |
|
533 |
|
534 |
return NULL;
|
534 |
return NULL;
|
535 |
}
|
535 |
}
|
536 |
|
536 |
|
537 |
|
537 |
|
538 |
static function baseflor_ligne($cel, $obs, &$ligne) {
|
538 |
static function baseflor_ligne($cel, $obs, &$ligne) {
|
539 |
if(! $obs['nom_ret_nn']) {
|
539 |
if(! $obs['nom_ret_nn']) {
|
540 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
540 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
541 |
return;
|
541 |
return;
|
542 |
}
|
542 |
}
|
543 |
|
543 |
|
544 |
if(! self::referenceTableExiste($cel)) {
|
544 |
if(! self::referenceTableExiste($cel)) {
|
545 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
545 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
546 |
return;
|
546 |
return;
|
547 |
}
|
547 |
}
|
548 |
|
548 |
|
549 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
549 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
|
550 |
$cache_id = $referentiel . '-' . $obs['nom_ret_nn'];
|
550 |
$cache_id = $referentiel . '-' . $obs['nom_ret_nn'];
|
551 |
|
551 |
|
552 |
// XXX: problème de valeurs NULL pour utiliser simplement isset() ?
|
552 |
// XXX: problème de valeurs NULL pour utiliser simplement isset() ?
|
553 |
// @ car getBaseflor[] n'est peut-être pas encore initialisé
|
553 |
// @ car getBaseflor[] n'est peut-être pas encore initialisé
|
554 |
if(@array_key_exists($cache_id, self::$cache['getBaseflor'])) {
|
554 |
if(@array_key_exists($cache_id, self::$cache['getBaseflor'])) {
|
555 |
$ligne = array_merge($ligne, self::$cache['getBaseflor'][$cache_id]);
|
555 |
$ligne = array_merge($ligne, self::$cache['getBaseflor'][$cache_id]);
|
556 |
return;
|
556 |
return;
|
557 |
}
|
557 |
}
|
558 |
|
558 |
|
559 |
// pas de cache:
|
559 |
// pas de cache:
|
560 |
$data = $cel->executerRequete(sprintf("SELECT %s FROM cel_references " .
|
560 |
$data = $cel->executerRequete(sprintf("SELECT %s FROM cel_references " .
|
561 |
"WHERE referentiel = '%s' AND num_nom_retenu = %d LIMIT 1",
|
561 |
"WHERE referentiel = '%s' AND num_nom_retenu = %d LIMIT 1",
|
562 |
implode(', ', array_keys(self::$baseflor_col)),
|
562 |
implode(', ', array_keys(self::$baseflor_col)),
|
563 |
$referentiel,
|
563 |
$referentiel,
|
564 |
$obs['nom_ret_nn']),
|
564 |
$obs['nom_ret_nn']),
|
565 |
Cel::SQL_RETOUR_LIGNE);
|
565 |
Cel::SQL_RETOUR_LIGNE);
|
566 |
|
566 |
|
567 |
if(! $data) {
|
567 |
if(! $data) {
|
568 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
568 |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL));
|
569 |
return;
|
569 |
return;
|
570 |
}
|
570 |
}
|
571 |
|
571 |
|
572 |
// cache
|
572 |
// cache
|
573 |
self::$cache['getBaseflor'][$cache_id] = $data;
|
573 |
self::$cache['getBaseflor'][$cache_id] = $data;
|
574 |
$ligne = array_merge($ligne, $data);
|
574 |
$ligne = array_merge($ligne, $data);
|
575 |
}
|
575 |
}
|
576 |
|
576 |
|
577 |
static function champsEtendus_preload($cel, $obsids) {
|
577 |
static function champsEtendus_preload($cel, $obsids) {
|
578 |
$gestion_champs_etendus = new GestionChampsEtendus($cel->config, 'obs');
|
578 |
$gestion_champs_etendus = new GestionChampsEtendus($cel->config, 'obs');
|
579 |
$colonnes_champs_supp_par_obs = $gestion_champs_etendus->consulterClesParLots($obsids);
|
579 |
$colonnes_champs_supp_par_obs = $gestion_champs_etendus->consulterClesParLots($obsids);
|
580 |
// si le SELECT des clefs ne retourne rien, une autre requêtes est inutile
|
580 |
// si le SELECT des clefs ne retourne rien, une autre requêtes est inutile
|
581 |
// TODO: optimize, 1 seule requête
|
581 |
// TODO: optimize, 1 seule requête
|
582 |
if(!$colonnes_champs_supp_par_obs) return Array('header' => array(), 'data' => array());
|
582 |
if(!$colonnes_champs_supp_par_obs) return Array('header' => array(), 'data' => array());
|
583 |
|
583 |
|
584 |
$champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($obsids);
|
584 |
$champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($obsids);
|
585 |
self::$cache['champsEtendus']['header'] = $colonnes_champs_supp_par_obs;
|
585 |
self::$cache['champsEtendus']['header'] = $colonnes_champs_supp_par_obs;
|
586 |
foreach($champs_supp_par_obs as &$v) {
|
586 |
foreach($champs_supp_par_obs as &$v) {
|
587 |
$v = self::champsEtendus_aplatir($v);
|
587 |
$v = self::champsEtendus_aplatir($v);
|
588 |
}
|
588 |
}
|
589 |
self::$cache['champsEtendus']['data'] = $champs_supp_par_obs;
|
589 |
self::$cache['champsEtendus']['data'] = $champs_supp_par_obs;
|
590 |
// ce return est temporaire,
|
590 |
// ce return est temporaire,
|
591 |
// le temps que toutes les fonctions bougent ici et utilise plutôt le cache statique
|
591 |
// le temps que toutes les fonctions bougent ici et utilise plutôt le cache statique
|
592 |
// encore utilisé pour les entêtes (self::$cache['champsEtendus']['header'])
|
592 |
// encore utilisé pour les entêtes (self::$cache['champsEtendus']['header'])
|
593 |
return self::$cache['champsEtendus'];
|
593 |
return self::$cache['champsEtendus'];
|
594 |
}
|
594 |
}
|
595 |
|
595 |
|
596 |
// XXX: PHP-5.3, fonction anonyme + array_map
|
596 |
// XXX: PHP-5.3, fonction anonyme + array_map
|
597 |
static function champsEtendus_aplatir($ligne_champs_etendus) {
|
597 |
static function champsEtendus_aplatir($ligne_champs_etendus) {
|
598 |
$champs_etendus_fmt = array();
|
598 |
$champs_etendus_fmt = array();
|
599 |
if(!$ligne_champs_etendus) return $champs_etendus_fmt;
|
599 |
if(!$ligne_champs_etendus) return $champs_etendus_fmt;
|
600 |
foreach($ligne_champs_etendus as $champ) {
|
600 |
foreach($ligne_champs_etendus as $champ) {
|
601 |
$champs_etendus_fmt[$champ->cle] = $champ->valeur;
|
601 |
$champs_etendus_fmt[$champ->cle] = $champ->valeur;
|
602 |
}
|
602 |
}
|
603 |
return $champs_etendus_fmt;
|
603 |
return $champs_etendus_fmt;
|
604 |
}
|
604 |
}
|
605 |
|
605 |
|
606 |
static function champsEtendus_ligne($cel, $obs, &$ligne) {
|
606 |
static function champsEtendus_ligne($cel, $obs, &$ligne) {
|
607 |
// si header n'est pas défini, aucune observation ne possède de champ étendu
|
607 |
// si header n'est pas défini, aucune observation ne possède de champ étendu
|
608 |
// et nous n'ajoutons ni colonnes, ni valeurs.
|
608 |
// et nous n'ajoutons ni colonnes, ni valeurs.
|
609 |
if(! isset(self::$cache['champsEtendus']['header'])) return;
|
609 |
if(! isset(self::$cache['champsEtendus']['header'])) return;
|
610 |
var_dump(self::$cache['champsEtendus']['header']);die;
|
- |
|
611 |
$ligne_etendue_aplatie = @self::$cache['champsEtendus']['data'][$ligne['id_observation']];
|
610 |
$ligne_etendue_aplatie = @self::$cache['champsEtendus']['data'][$obs['id_observation']];
|
612 |
|
611 |
|
613 |
$ligne_supp = array_fill(0, count(self::$cache['champsEtendus']['header']), '');
|
612 |
$ligne_supp = array_fill(0, count(self::$cache['champsEtendus']['header']), '');
|
614 |
$ligne_etendue_fmt = array();
|
613 |
$ligne_etendue_fmt = array();
|
615 |
|
614 |
|
616 |
// si, cependant cette seule observation n'a pas de champs étendus,
|
615 |
// si, cependant cette seule observation n'a pas de champs étendus,
|
617 |
// nous devons rajouter des blancs (notamment dans le cas ou d'autres
|
616 |
// nous devons rajouter des blancs (notamment dans le cas ou d'autres
|
618 |
// champs viennent à être ajoutés en aval à l'avenir
|
617 |
// champs viennent à être ajoutés en aval à l'avenir
|
619 |
// cf: $fonction_dynamique dans FormateurGroupeColonne::GenColInfo()
|
618 |
// cf: $fonction_dynamique dans FormateurGroupeColonne::GenColInfo()
|
620 |
if(! $ligne_etendue_aplatie) {
|
619 |
if(! $ligne_etendue_aplatie) {
|
621 |
$ligne = array_merge($ligne, $ligne_supp);
|
620 |
$ligne = array_merge($ligne, $ligne_supp);
|
622 |
return;
|
621 |
return;
|
623 |
}
|
622 |
}
|
624 |
|
623 |
|
625 |
foreach(self::$cache['champsEtendus']['header'] as $colonne) {
|
624 |
foreach(self::$cache['champsEtendus']['header'] as $colonne) {
|
626 |
if(!isset($ligne_etendue_aplatie[$colonne])) {
|
625 |
if(!isset($ligne_etendue_aplatie[$colonne])) {
|
627 |
$ligne_etendue_fmt[$colonne] = '';
|
626 |
$ligne_etendue_fmt[$colonne] = '';
|
628 |
} else {
|
627 |
} else {
|
629 |
$ligne_etendue_fmt[$colonne] = $ligne_etendue_aplatie[$colonne];
|
628 |
$ligne_etendue_fmt[$colonne] = $ligne_etendue_aplatie[$colonne];
|
630 |
}
|
629 |
}
|
631 |
}
|
630 |
}
|
632 |
|
631 |
|
633 |
// XXX/ array_merge() ?
|
632 |
// XXX/ array_merge() ?
|
634 |
$ligne += $ligne_etendue_fmt;
|
633 |
$ligne += $ligne_etendue_fmt;
|
635 |
}
|
634 |
}
|
636 |
}
|
635 |
}
|