Subversion Repositories eFlore/Applications.cel

Rev

Rev 1740 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1740 Rev 1762
Line 6... Line 6...
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', " / ");
Line 12... Line 12...
12
 
12
 
Line 13... Line 13...
13
Class FormateurGroupeColonne {
13
Class FormateurGroupeColonne {
14
 
14
 
Line 41... Line 41...
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
	);
Line -... Line 45...
-
 
45
 
-
 
46
	// TODO: dirty, ordre des champs étendus... souhaité pour florilèges:
-
 
47
	static $ordre_champ_etendus_Florileges = array(
-
 
48
		"personneStructure",
-
 
49
		"personneService",
-
 
50
		"personneFonction",
-
 
51
		"adresse",
-
 
52
		"latitudeDebutRue",
-
 
53
		"longitudeDebutRue",
-
 
54
		"latitudeFinRue",
-
 
55
		"longitudeFinRue",
-
 
56
		"typoUrbaine",
-
 
57
		"revetementSol",
-
 
58
		"presenceZoneVegetalise",
-
 
59
		"hauteurBatimentAvoisinant",
-
 
60
		"intensiteGestion",
-
 
61
		"periodiciteTraitementPhyto",
-
 
62
		"dateArretTraitementPhyto",
-
 
63
		"itineraireGestion",
-
 
64
		"dateDerniereIntervention",
-
 
65
		"hauteurPlante",
-
 
66
		"resistanceTraitementPhyto",
-
 
67
		"vitesseCroissance",
-
 
68
		"perceptionTechnicien",
-
 
69
		"perceptionRiverainMauvaise",
-
 
70
	);
45
 
71
 
46
	static function colGroupsValidation($groupe_de_champs = 'standard,avance') {
72
	static function colGroupsValidation($groupe_de_champs = 'standard,avance') {
47
		if(! $groupe_de_champs) return FALSE;
73
		if(! $groupe_de_champs) return FALSE;
48
		if(is_string($groupe_de_champs)) {
74
		if(is_string($groupe_de_champs)) {
49
			$groupe_de_champs = array_flip(explode(',', $groupe_de_champs));
75
			$groupe_de_champs = array_flip(explode(',', $groupe_de_champs));
Line 69... Line 95...
69
	*
95
	*
70
	* @return: un tableau associatif déjà ordonné
96
	* @return: un tableau associatif déjà ordonné
71
	* 		clé: abbrev [machine-name] de la colonne (eg: "espece" ou "mot-clef")
97
	* 		clé: abbrev [machine-name] de la colonne (eg: "espece" ou "mot-clef")
72
	* 		valeur: des données relative à cette colonne, cf GenColInfo
98
	* 		valeur: des données relative à cette colonne, cf GenColInfo
73
	*
99
	*
74
	* @TODO: noms communs à part, gestion des champs étendus
100
	* Si la colonne n'utilise pas de fonction de récupération particulière
-
 
101
	* (ie: si le champ exportés [ou importé] correspond exactement au champ dans la base de donnée)
-
 
102
	* Alors 'abbrev' doit avoir la même valeur que le nom de la colonne dans la table mysql `cel_obs`.
75
	*
103
	*
76
	*/
104
	*/
77
	static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
105
	static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
78
		if(! $groupe_de_champs) $groupe_de_champs = 'standard';
106
		if(! $groupe_de_champs) $groupe_de_champs = 'standard';
79
		if(is_string($groupe_de_champs)) {
107
		if(is_string($groupe_de_champs)) {
Line 91... Line 119...
91
 
119
 
Line 92... Line 120...
92
		$colonnes = Array();
120
		$colonnes = Array();
93
		
121
		
94
		if(isset($groupe_de_champs['standard'])) {
122
		if(isset($groupe_de_champs['standard'])) {
-
 
123
			$colonnes += Array(
95
			$colonnes += Array(
124
				'nom_sel'			=> self::GenColInfo(Array('abbrev' => 'nom_sel',
-
 
125
															  'nom' => 'Espèce')),
-
 
126
				'nom_sel_nn'		=> self::GenColInfo(Array('abbrev' => 'nom_sel_nn',
96
				'nom_sel'			=> self::GenColInfo('nom_sel', 'Espèce'),
127
															  'nom' => 'Numéro nomenclatural',
-
 
128
															  'importable' => FALSE)),
-
 
129
				'nom_ret'			=> self::GenColInfo(Array('abbrev' => 'nom_ret',
97
				'nom_sel_nn'		=> self::GenColInfo('nom_sel_nn', 'Numéro nomenclatural', 0, NULL, NULL, FALSE),
130
															  'nom' => 'Nom retenu',
-
 
131
															  'importable' => FALSE)),
-
 
132
				'nom_ret_nn'		=> self::GenColInfo(Array('abbrev' => 'nom_ret_nn',
98
				'nom_ret'			=> self::GenColInfo('nom_ret', 'Nom retenu', 0, NULL, NULL, FALSE),
133
															  'nom' => 'Numéro nomenclatural nom retenu',
-
 
134
															  'importable' => FALSE)),
-
 
135
				'nt'				=> self::GenColInfo(Array('abbrev' => 'nt',
99
				'nom_ret_nn'		=> self::GenColInfo('nom_ret_nn', 'Numéro nomenclatural nom retenu', 0, NULL, NULL, FALSE),
136
															  'nom' => 'Numéro taxonomique',
-
 
137
															  'importable' => FALSE)),
-
 
138
				'famille'			=> self::GenColInfo(Array('abbrev' => 'famille',
100
				'nt'				=> self::GenColInfo('nt', 'Numéro taxonomique', 0, NULL, NULL, FALSE),
139
															  'nom' => 'Famille',
-
 
140
															  'importable' => FALSE)),
101
				'famille'			=> self::GenColInfo('famille', 'Famille', 0, NULL, NULL, FALSE),
141
				'nom_referentiel'	=> self::GenColInfo(Array('abbrev' => 'nom_referentiel',
-
 
142
															  'nom' => 'Referentiel taxonomique')),
-
 
143
				'zone_geo'			=> self::GenColInfo(Array('abbrev' => 'zone_geo',
-
 
144
															  'nom' => 'Commune')),
102
				'nom_referentiel'	=> self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
145
				'ce_zone_geo'		=> self::GenColInfo(Array('abbrev' => 'ce_zone_geo',
103
				'zone_geo'			=> self::GenColInfo('zone_geo', 'Commune'),
146
															  'nom' => 'Identifiant Commune',
-
 
147
															  'fonction' => 'convertirCodeZoneGeoVersDepartement')),
-
 
148
				'date_observation'	=> self::GenColInfo(Array('abbrev' => 'date_observation',
104
				'ce_zone_geo'		=> self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
149
															  'nom' => 'Date',
-
 
150
															  'fonction' => 'formaterDate')),
105
				'date_observation'	=> self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
151
				'lieudit'			=> self::GenColInfo(Array('abbrev' => 'lieudit',
-
 
152
															  'nom' => 'Lieu-dit')),
106
				'lieudit'			=> self::GenColInfo('lieudit', 'Lieu-dit'),
153
				'station'			=> self::GenColInfo(Array('abbrev' => 'station',
-
 
154
															  'nom' => 'Station')),
107
				'station'			=> self::GenColInfo('station', 'Station'),
155
				'milieu'			=> self::GenColInfo(Array('abbrev' => 'milieu',
-
 
156
															  'nom' => 'Milieu')),
108
				'milieu'			=> self::GenColInfo('milieu', 'Milieu'),
157
				'commentaire'		=> self::GenColInfo(Array('abbrev' => 'commentaire',
-
 
158
															  'nom' => 'Notes')),
-
 
159
				'latitude'			=> self::GenColInfo(Array('abbrev' => 'latitude',
-
 
160
															  'nom' => 'Latitude',
109
				'commentaire'		=> self::GenColInfo('commentaire', 'Notes'),
161
															  'extra' => 1,
-
 
162
															  'fonction' => 'trim0')),
-
 
163
				'longitude'			=> self::GenColInfo(Array('abbrev' => 'longitude',
-
 
164
															  'nom' => 'Longitude',
110
				'latitude'			=> self::GenColInfo('latitude', 'Latitude', 1),
165
															  'extra' => 1,
-
 
166
															  'fonction' => 'trim0')),
-
 
167
				'altitude'			=> self::GenColInfo(Array('abbrev' => 'altitude',
-
 
168
															  'nom' => 'Altitude',
111
				'longitude'			=> self::GenColInfo('longitude', 'Longitude', 1),
169
															  'extra' => 1,
-
 
170
															  'fonction' => 'trim0')),
-
 
171
				'geodatum'			=> self::GenColInfo(Array('abbrev' => 'geodatum',
-
 
172
															  'nom' => 'Référentiel Géographique',
112
				'altitude'			=> self::GenColInfo('altitude', 'Altitude', 1),
173
															  'extra' => 1,
113
				'geodatum'			=> self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
174
															  'importable' => FALSE)),
Line 114... Line 175...
114
			);
175
			);
115
		}
176
		}
116
		
177
		
117
		if(isset($groupe_de_champs['avance'])) {
178
		if(isset($groupe_de_champs['avance'])) {
-
 
179
			$colonnes += array(
-
 
180
				// TODO: importable = FALSE car pas de merge de données importées
-
 
181
				'ordre'				=> self::GenColInfo(Array('abbrev' => 'ordre',
118
			$colonnes += array(
182
															  'nom' => 'Ordre',
-
 
183
															  'extra' => 1,
-
 
184
															  'importable' => FALSE)),
-
 
185
				'id_observation'	=> self::GenColInfo(Array('abbrev' => 'id_observation',
119
			   // TODO: importable = FALSE car pas de merge de données importées
186
															  'nom' => 'Identifiant',
120
			   'ordre'				=> self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
187
															  'extra' => 1,
121
			   'id_observation'		=> self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
188
															  'importable' => FALSE)),
-
 
189
 
122
 
190
				'mots_cles_texte'	=> self::GenColInfo(Array('abbrev' => 'mots_cles_texte',
-
 
191
															  'nom' => 'Mots Clés',
-
 
192
															  'extra' => 1)),
-
 
193
				'date_creation'		=> self::GenColInfo(Array('abbrev' => 'date_creation',
123
			   'mots_cles_texte'	=> self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
194
															  'nom' => 'Date Création',
-
 
195
															  'extra' => 1,
-
 
196
															  'importable' => FALSE)),
-
 
197
				'date_modification'	=> self::GenColInfo(Array('abbrev' => 'date_modification',
124
			   'commentaire'		=> self::GenColInfo('commentaire', 'Commentaires', 1),
198
															  'nom' => 'Date Modification',
125
			   'date_creation'		=> self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
199
															  'extra' => 1,
126
			   'date_modification'	=> self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),
200
															  'importable' => FALSE)),
127
 
201
 
128
			   // rappel transmission = 1, signifie simplement "public"
202
				// rappel transmission = 1, signifie simplement "public"
-
 
203
				// des données importées peuvent être d'emblée "publiques"
-
 
204
				// "importable" = TRUE
-
 
205
				'transmission'		=> self::GenColInfo(Array('abbrev' => 'transmission',
129
			   // des données importées peuvent être d'emblée "publiques"
206
															  'nom' => 'Transmis',
-
 
207
															  'extra' => 1,
-
 
208
															  'fonction' => 'boolOuiNon')),
-
 
209
				'date_transmission'	=> self::GenColInfo(Array('abbrev' => 'date_transmission',
130
			   // "importable" = TRUE
210
															  'nom' => 'Date Transmission',
-
 
211
															  'extra' => 1,
-
 
212
															  'importable' => FALSE)),
131
			   'transmission'		=> self::GenColInfo('transmission', 'Transmis', 1),
213
				'abondance'			=> self::GenColInfo(Array('abbrev' => 'abondance',
-
 
214
															  'nom' => 'Abondance',
-
 
215
															  'extra' => 1)),
132
			   'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1, NULL, NULL, FALSE),
216
				'certitude'			=> self::GenColInfo(Array('abbrev' => 'certitude',
-
 
217
															  'nom' => 'Certitude',
-
 
218
															  'extra' => 1)),
133
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
219
				'phenologie'		=> self::GenColInfo(Array('abbrev' => 'phenologie',
134
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
220
															  'nom' => 'Phénologie',
135
			   'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
221
															  'extra' => 1)),
-
 
222
				
-
 
223
				// XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
-
 
224
				// cf ExportXLS::traiterLigneObservation()
136
 
225
				'images'			=> self::GenColInfo(Array('abbrev' => 'images',
-
 
226
															  'nom' => 'Image(s)',
-
 
227
															  'extra' => 1,
-
 
228
															  'fonction_data' => NULL /* cas particulier 'getImages' */,
137
			   // XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
229
															  'importable' => TRUE,
138
			   // cf ExportXLS::traiterLigneObservation()
230
															  //'preload' => array(__CLASS__, 'getImages_preload')//TODO
-
 
231
				)),
-
 
232
 
-
 
233
				/* 'nom_commun'			=> self::GenColInfo(Array('abbrev' => 'nom_commun',
-
 
234
				   'nom' => 'Nom Commun',
-
 
235
				   'extra' => 1,
139
			   'images'				=> self::GenColInfo('images', 'Image(s)', 1, NULL, NULL /* cas particulier 'getImages' */, TRUE),
236
				   'fonction_data' => 'getNomCommun',
-
 
237
				   'importable' => FALSE),
-
 
238
 
-
 
239
				   'nom-commun'			=> self::GenColInfo(Array('abbrev' => 'nom-commun',
-
 
240
				   'nom' => 'Nom Commun',
140
 
241
				   'extra' => 1,
-
 
242
				   'fonction_data' => 'getNomCommun_v2'),
-
 
243
 
-
 
244
				   'nom-commun'			=> self::GenColInfo(Array('abbrev' => 'nom-commun',
-
 
245
				   'nom' => 'Nom Commun',
-
 
246
				   'extra' => 1,
-
 
247
				   'fonction_data' => 'getNomCommun_v3'),
-
 
248
				   'importable' => FALSE), */
141
			   /* 'nom_commun'			=> self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
249
				'nom-commun'		=> self::GenColInfo(Array('abbrev' => 'nom-commun',
-
 
250
															  'nom' => 'Nom Commun',
142
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
251
															  'extra' => 1,
143
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
252
															  'fonction_data' => NULL /* cas particu 'getNomCommun_v4' */,
Line 144... Line 253...
144
			   'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, NULL /* cas particu 'getNomCommun_v4' */, TRUE, array(__CLASS__, 'getNomCommun_preload')),
253
															  'preload' => array(__CLASS__, 'getNomCommun_preload')))
145
			);
254
			);
146
		}
255
		}
147
 
256
 
-
 
257
		if(isset($groupe_de_champs['baseflor'])) {
-
 
258
			$colonnes += array(
-
 
259
				// champ dynamique
-
 
260
				'baseflor'			=> self::GenColInfo(Array('abbrev' => 'baseflor',
-
 
261
															  'nom' => '',
148
		if(isset($groupe_de_champs['baseflor'])) {
262
															  'extra' => 1,
149
			$colonnes += array(
263
															  'importable' => FALSE,
Line 150... Line 264...
150
				// champ dynamique
264
															  'preload' => array(__CLASS__, 'baseflor_preload'),
151
				'baseflor'			=> self::GenColInfo('baseflor', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'baseflor_preload'), array(__CLASS__, 'baseflor_ligne')),
265
															  'dyna' => array(__CLASS__, 'baseflor_ligne'))),
152
			);
266
			);
-
 
267
		}
-
 
268
 
-
 
269
		if(isset($groupe_de_champs['etendu'])) {
-
 
270
			$colonnes += array(
153
		}
271
				// champ dynamique
-
 
272
				'etendu'			=> self::GenColInfo(Array('abbrev' => 'etendu',
154
 
273
															  'nom' => '',
155
		if(isset($groupe_de_champs['etendu'])) {
274
															  'extra' => 1,
156
			$colonnes += array(
-
 
157
				// champ dynamique
275
															  'importable' => FALSE,
158
				'etendu'			=> self::GenColInfo('etendu', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'champsEtendus_preload'), array(__CLASS__, 'champsEtendus_ligne')),
276
															  'preload' => array(__CLASS__, 'champsEtendus_preload'),
Line 159... Line 277...
159
			);
277
															  'dyna' => array(__CLASS__, 'champsEtendus_ligne'))),
160
		}
278
			);
Line 179... Line 297...
179
	public static function retournerNomItem(&$item) {
297
	public static function retournerNomItem(&$item) {
180
		return $item['nom'];
298
		return $item['nom'];
181
	}
299
	}
Line 182... Line 300...
182
 
300
 
183
	public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
301
	public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
184
		
302
 
185
		$ligne_formatee = array();
303
		$ligne_formatee = array();
186
		foreach($colonnes as $abbrev => $colonne) {
304
		foreach($colonnes as $abbrev => $colonne) {
187
			$valeur = null;
305
			$valeur = null;
Line 275... Line 393...
275
	* @param $fonction_dynamique (optionnel): défini une fonction ajoutant un nombre arbitraire de colonnes à une ligne donnée
393
	* @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
394
	*		  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)
395
	*		  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 ($obs, &$ligne_formatee)
396
	*		  La fonction doit prendre comme arguments ($obs, &$ligne_formatee)
279
	*/
397
	*/
280
	static function GenColInfo($abbrev, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL, $importable = TRUE, $preload = NULL, $fonction_dynamique = NULL) {
398
	static function GenColInfo($args) {
281
		return Array('abbrev' => $abbrev,
399
		$default = Array('abbrev' => NULL,
282
					 'nom' => $nom,
400
						 'nom' => NULL,
283
					 'extra' => $is_extra ? 1 : 0,
401
						 'extra' => 0,
284
					 'fonction' => $fonction,
402
						 'fonction' => NULL,
285
					 'fonction_data' => $fonction_data,
403
						 'fonction_data' => NULL,
286
					 'importable' => $importable,
404
						 'importable' => TRUE,
287
					 'preload' => $preload,
405
						 'preload' => NULL,
288
					 'dyna' => $fonction_dynamique,
406
						 'dyna' => NULL);
-
 
407
		$ret = array_intersect_key($args, $default);
289
		);
408
		return array_merge($default, $ret);
290
	}
409
	}
Line 291... Line 410...
291
	
410
	
292
	static function formaterDate($date_heure_mysql) {
411
	static function formaterDate($date_heure_mysql) {
293
		//return "";
412
		//return "";
Line 305... Line 424...
305
		// $date_formatee = strftime('%d/%m/%Y', $timestamp);
424
		// $date_formatee = strftime('%d/%m/%Y', $timestamp);
306
		$date_formatee = strftime('%Y/%m/%d', $timestamp);
425
		$date_formatee = strftime('%Y/%m/%d', $timestamp);
307
		if(!$date_formatee) return "00/00/0000";
426
		if(!$date_formatee) return "00/00/0000";
308
		return $date_formatee;
427
		return $date_formatee;
309
	}
428
	}
310
	
429
 
-
 
430
	static function getImages_preload($cel, $obsids) {
-
 
431
		if(!$obsids) return;
-
 
432
		$rec = $cel->requeter(
-
 
433
			sprintf("SELECT o.id_observation, GROUP_CONCAT(nom_original ORDER BY nom_original ASC SEPARATOR '%s') AS i " .
-
 
434
					"FROM cel_images i LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image) LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation) " .
-
 
435
					"WHERE o.ce_utilisateur = %d AND o.id_observation IN (%s) " .
-
 
436
					"GROUP BY id_observation",
-
 
437
					SEPARATEUR_IMAGES,
-
 
438
					$cel->id_utilisateur,
-
 
439
					implode(',', $obsids)));
-
 
440
		foreach($rec as $v) {
-
 
441
			self::$cache['getImages'][$v['id_observation']] = $v['i'];
-
 
442
		}
-
 
443
		return NULL;
-
 
444
	}
-
 
445
 
311
	static function getImages($obs, $id_utilisateur) {
446
	static function getImages($obs, $id_utilisateur) {
312
		if(! $id_utilisateur) return NULL;
447
		if(! $id_utilisateur) return NULL;
-
 
448
		if(isset(self::$cache['getImages'][$obs['id_observation']]))
-
 
449
			return self::$cache['getImages'][$obs['id_observation']];
-
 
450
 
313
		$rec = Cel::db()->requeter(
451
		$rec = Cel::db()->requeter(
314
			sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
452
			sprintf("SELECT GROUP_CONCAT(nom_original ORDER BY nom_original ASC SEPARATOR '%s') AS i FROM cel_images i"
315
					." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
453
					." 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)"
454
					." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
317
					." WHERE ce_utilisateur = %d",
455
					." WHERE o.ce_utilisateur = %d AND o.id_observation = %d LIMIT 1",
318
					SEPARATEUR_IMAGES,
456
					SEPARATEUR_IMAGES,
319
					$id_utilisateur));
457
					$id_utilisateur,
-
 
458
					$obs['id_observation']));
320
		return $rec ? array_pop($rec) : NULL;
459
		return $rec ? $rec[0]['i'] : NULL;
321
	}
460
	}
Line 322... Line 461...
322
	
461
	
323
	public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {	
462
	public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {	
324
		$code_departement = '';
463
		$code_departement = '';
325
		if(self::estUnCodeInseeDepartement($code_zone_geo)) {
464
		if(self::estUnCodeInseeDepartement($code_zone_geo)) {
326
			$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2);
465
			$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2);
Line 327... Line 466...
327
		}
466
		}
328
	
467
	
-
 
468
		return $code_departement;
-
 
469
	}
-
 
470
 
-
 
471
	public static function trim0($lonlat) {
-
 
472
		return trim(trim($lonlat, "0"), ".");
-
 
473
	}
-
 
474
 
-
 
475
	public static function boolOuiNon($transmission) {
Line 329... Line 476...
329
		return $code_departement;
476
		return $transmission ? 'oui' : '';
330
	}
477
	}
331
	
478
	
Line 487... Line 634...
487
 
634
 
488
		$langue = 'fra';
635
		$langue = 'fra';
489
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
636
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
Line -... Line 637...
-
 
637
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
-
 
638
 
490
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
639
		// cache:
491
 
640
		if(isset($cache['getNomCommun'])) {
492
		if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
641
			if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
-
 
642
			// XXX: problème de valeurs NULL ?
Line 493... Line 643...
493
		// XXX: problème de valeurs NULL ?
643
			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];
644
		}
495
 
645
 
496
		// pas de cache:
646
		// pas de cache:
Line 575... Line 725...
575
	}
725
	}
Line 576... Line 726...
576
 
726
 
577
	static function champsEtendus_preload($cel, $obsids) {
727
	static function champsEtendus_preload($cel, $obsids) {
578
		$gestion_champs_etendus = new GestionChampsEtendus($cel->config, 'obs');
728
		$gestion_champs_etendus = new GestionChampsEtendus($cel->config, 'obs');
-
 
729
		$colonnes_champs_supp_par_obs = $gestion_champs_etendus->consulterClesParLots($obsids);
-
 
730
		// ces deux lignes réordonnent l'ordre des colonnes des champs étendus en fonction de l'ordre (très spécifique)
-
 
731
		// de self::$ordre_champ_etendus_Florileges, les champs non-mentionnés sont ajoutés à la fin.
-
 
732
		$colonnes_champs_supp_par_obs = self::sortArrayByArray(array_flip($colonnes_champs_supp_par_obs),
-
 
733
															   self::$ordre_champ_etendus_Florileges);
-
 
734
		$colonnes_champs_supp_par_obs = array_keys($colonnes_champs_supp_par_obs);
579
		$colonnes_champs_supp_par_obs = $gestion_champs_etendus->consulterClesParLots($obsids);
735
 
580
		// si le SELECT des clefs ne retourne rien, une autre requêtes est inutile
736
		// si le SELECT des clefs ne retourne rien, une autre requêtes est inutile
581
		// TODO: optimize, 1 seule requête
737
		// TODO: optimize, 1 seule requête
Line 582... Line 738...
582
		if(!$colonnes_champs_supp_par_obs) return Array('header' => array(), 'data' => array());
738
		if(!$colonnes_champs_supp_par_obs) return Array('header' => array(), 'data' => array());
-
 
739
 
583
 
740
		$champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($obsids);
584
		$champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($obsids);
741
 
585
		self::$cache['champsEtendus']['header'] = $colonnes_champs_supp_par_obs;
742
		self::$cache['champsEtendus']['header'] = $colonnes_champs_supp_par_obs;
586
		foreach($champs_supp_par_obs as &$v) {
743
		foreach($champs_supp_par_obs as &$v) {
587
			$v = self::champsEtendus_aplatir($v);
744
			$v = self::champsEtendus_aplatir($v);
Line 630... Line 787...
630
		}
787
		}
Line 631... Line 788...
631
 
788
 
632
		// XXX/ array_merge() ?
789
		// XXX/ array_merge() ?
633
		$ligne += $ligne_etendue_fmt;
790
		$ligne += $ligne_etendue_fmt;
-
 
791
	}
-
 
792
 
-
 
793
	/* HELPERS */
-
 
794
 
-
 
795
	// http://stackoverflow.com/questions/348410/sort-an-array-based-on-another-array
-
 
796
	// XXX; redéfinition, utilisé aussi par ExportXLS
-
 
797
	static function sortArrayByArray($array, $orderArray) {
-
 
798
		$ordered = array();
-
 
799
		foreach($orderArray as $key) {
-
 
800
			if(array_key_exists($key, $array)) {
-
 
801
				$ordered[$key] = $array[$key];
-
 
802
				unset($array[$key]);
-
 
803
			}
-
 
804
		}
-
 
805
		return $ordered + $array;
-
 
806
	}
634
	}
807