Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1754 Rev 1757
Line 95... Line 95...
95
	*
95
	*
96
	* @return: un tableau associatif déjà ordonné
96
	* @return: un tableau associatif déjà ordonné
97
	* 		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")
98
	* 		valeur: des données relative à cette colonne, cf GenColInfo
98
	* 		valeur: des données relative à cette colonne, cf GenColInfo
99
	*
99
	*
100
	* @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`.
101
	*
103
	*
102
	*/
104
	*/
103
	static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
105
	static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
104
		if(! $groupe_de_champs) $groupe_de_champs = 'standard';
106
		if(! $groupe_de_champs) $groupe_de_champs = 'standard';
105
		if(is_string($groupe_de_champs)) {
107
		if(is_string($groupe_de_champs)) {
Line 117... Line 119...
117
 
119
 
Line 118... Line 120...
118
		$colonnes = Array();
120
		$colonnes = Array();
119
		
121
		
120
		if(isset($groupe_de_champs['standard'])) {
122
		if(isset($groupe_de_champs['standard'])) {
-
 
123
			$colonnes += Array(
121
			$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',
122
				'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',
123
				'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',
124
				'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',
125
				'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',
126
				'nt'				=> self::GenColInfo('nt', 'Numéro taxonomique', 0, NULL, NULL, FALSE),
139
															  'nom' => 'Famille',
-
 
140
															  'importable' => FALSE)),
127
				'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')),
128
				'nom_referentiel'	=> self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
145
				'ce_zone_geo'		=> self::GenColInfo(Array('abbrev' => 'ce_zone_geo',
129
				'zone_geo'			=> self::GenColInfo('zone_geo', 'Commune'),
146
															  'nom' => 'Identifiant Commune',
-
 
147
															  'fonction' => 'convertirCodeZoneGeoVersDepartement')),
-
 
148
				'date_observation'	=> self::GenColInfo(Array('abbrev' => 'date_observation',
130
				'ce_zone_geo'		=> self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
149
															  'nom' => 'Date',
-
 
150
															  'fonction' => 'formaterDate')),
131
				'date_observation'	=> self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
151
				'lieudit'			=> self::GenColInfo(Array('abbrev' => 'lieudit',
-
 
152
															  'nom' => 'Lieu-dit')),
132
				'lieudit'			=> self::GenColInfo('lieudit', 'Lieu-dit'),
153
				'station'			=> self::GenColInfo(Array('abbrev' => 'station',
-
 
154
															  'nom' => 'Station')),
133
				'station'			=> self::GenColInfo('station', 'Station'),
155
				'milieu'			=> self::GenColInfo(Array('abbrev' => 'milieu',
-
 
156
															  'nom' => 'Milieu')),
134
				'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',
135
				'commentaire'		=> self::GenColInfo('commentaire', 'Notes'),
161
															  'extra' => 1,
-
 
162
															  'fonction' => 'trim0')),
-
 
163
				'longitude'			=> self::GenColInfo(Array('abbrev' => 'longitude',
-
 
164
															  'nom' => 'Longitude',
136
				'latitude'			=> self::GenColInfo('latitude', 'Latitude', 1),
165
															  'extra' => 1,
-
 
166
															  'fonction' => 'trim0')),
-
 
167
				'altitude'			=> self::GenColInfo(Array('abbrev' => 'altitude',
-
 
168
															  'nom' => 'Altitude',
137
				'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',
138
				'altitude'			=> self::GenColInfo('altitude', 'Altitude', 1),
173
															  'extra' => 1,
139
				'geodatum'			=> self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
174
															  'importable' => FALSE)),
Line 140... Line 175...
140
			);
175
			);
141
		}
176
		}
142
		
177
		
143
		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',
144
			$colonnes += array(
182
															  'nom' => 'Ordre',
-
 
183
															  'extra' => 1,
-
 
184
															  'importable' => FALSE)),
-
 
185
				'id_observation'	=> self::GenColInfo(Array('abbrev' => 'id_observation',
145
			   // TODO: importable = FALSE car pas de merge de données importées
186
															  'nom' => 'Identifiant',
146
			   'ordre'				=> self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
187
															  'extra' => 1,
-
 
188
															  'importable' => FALSE)),
-
 
189
 
147
			   'id_observation'		=> self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
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',
148
 
194
															  'nom' => 'Date Création',
-
 
195
															  'extra' => 1,
-
 
196
															  'importable' => FALSE)),
-
 
197
				'date_modification'	=> self::GenColInfo(Array('abbrev' => 'date_modification',
149
			   'mots_cles_texte'	=> self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
198
															  'nom' => 'Date Modification',
150
			   'date_creation'		=> self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
199
															  'extra' => 1,
151
			   'date_modification'	=> self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),
200
															  'importable' => FALSE)),
152
 
201
 
153
			   // 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',
154
			   // 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',
155
			   // "importable" = TRUE
210
															  'nom' => 'Date Transmission',
-
 
211
															  'extra' => 1,
-
 
212
															  'importable' => FALSE)),
156
			   'transmission'		=> self::GenColInfo('transmission', 'Transmis', 1),
213
				'abondance'			=> self::GenColInfo(Array('abbrev' => 'abondance',
-
 
214
															  'nom' => 'Abondance',
-
 
215
															  'extra' => 1)),
157
			   '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)),
158
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
219
				'phenologie'		=> self::GenColInfo(Array('abbrev' => 'phenologie',
159
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
220
															  'nom' => 'Phénologie',
160
			   '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()
161
 
225
				'images'			=> self::GenColInfo(Array('abbrev' => 'images',
-
 
226
															  'nom' => 'Image(s)',
-
 
227
															  'extra' => 1,
-
 
228
															  'fonction_data' => NULL /* cas particulier 'getImages' */,
162
			   // XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
229
															  'importable' => TRUE,
163
			   // 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,
164
			   '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',
165
 
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), */
166
			   /* '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',
167
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
251
															  'extra' => 1,
168
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
252
															  'fonction_data' => NULL /* cas particu 'getNomCommun_v4' */,
Line 169... Line 253...
169
			   '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')))
170
			);
254
			);
171
		}
255
		}
172
 
256
 
-
 
257
		if(isset($groupe_de_champs['baseflor'])) {
-
 
258
			$colonnes += array(
-
 
259
				// champ dynamique
-
 
260
				'baseflor'			=> self::GenColInfo(Array('abbrev' => 'baseflor',
-
 
261
															  'nom' => '',
173
		if(isset($groupe_de_champs['baseflor'])) {
262
															  'extra' => 1,
174
			$colonnes += array(
263
															  'importable' => FALSE,
Line 175... Line 264...
175
				// champ dynamique
264
															  'preload' => array(__CLASS__, 'baseflor_preload'),
176
				'baseflor'			=> self::GenColInfo('baseflor', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'baseflor_preload'), array(__CLASS__, 'baseflor_ligne')),
265
															  'dyna' => array(__CLASS__, 'baseflor_ligne'))),
177
			);
266
			);
-
 
267
		}
-
 
268
 
-
 
269
		if(isset($groupe_de_champs['etendu'])) {
-
 
270
			$colonnes += array(
178
		}
271
				// champ dynamique
-
 
272
				'etendu'			=> self::GenColInfo(Array('abbrev' => 'etendu',
179
 
273
															  'nom' => '',
180
		if(isset($groupe_de_champs['etendu'])) {
274
															  'extra' => 1,
181
			$colonnes += array(
-
 
182
				// champ dynamique
275
															  'importable' => FALSE,
183
				'etendu'			=> self::GenColInfo('etendu', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'champsEtendus_preload'), array(__CLASS__, 'champsEtendus_ligne')),
276
															  'preload' => array(__CLASS__, 'champsEtendus_preload'),
Line 184... Line 277...
184
			);
277
															  'dyna' => array(__CLASS__, 'champsEtendus_ligne'))),
185
		}
278
			);
Line 204... Line 297...
204
	public static function retournerNomItem(&$item) {
297
	public static function retournerNomItem(&$item) {
205
		return $item['nom'];
298
		return $item['nom'];
206
	}
299
	}
Line 207... Line 300...
207
 
300
 
208
	public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
301
	public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
209
		
302
 
210
		$ligne_formatee = array();
303
		$ligne_formatee = array();
211
		foreach($colonnes as $abbrev => $colonne) {
304
		foreach($colonnes as $abbrev => $colonne) {
212
			$valeur = null;
305
			$valeur = null;
Line 300... Line 393...
300
	* @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
301
	*		  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
302
	*		  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)
303
	*		  La fonction doit prendre comme arguments ($cel, $obs, &$ligne_formatee)
396
	*		  La fonction doit prendre comme arguments ($cel, $obs, &$ligne_formatee)
304
	*/
397
	*/
305
	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) {
306
		return Array('abbrev' => $abbrev,
399
		$default = Array('abbrev' => NULL,
307
					 'nom' => $nom,
400
						 'nom' => NULL,
308
					 'extra' => $is_extra,
401
						 'extra' => 0,
309
					 'fonction' => $fonction,
402
						 'fonction' => NULL,
310
					 'fonction_data' => $fonction_data,
403
						 'fonction_data' => NULL,
311
					 'importable' => $importable,
404
						 'importable' => TRUE,
312
					 'preload' => $preload,
405
						 'preload' => NULL,
313
					 'dyna' => $fonction_dynamique,
406
						 'dyna' => NULL);
-
 
407
		$ret = array_intersect_key($args, $default);
314
		);
408
		return array_merge($default, $ret);
315
	}
409
	}
Line 316... Line 410...
316
	
410
	
317
	static function formaterDate($date_heure_mysql) {
411
	static function formaterDate($date_heure_mysql) {
318
		//return "";
412
		//return "";
Line 330... Line 424...
330
		// $date_formatee = strftime('%d/%m/%Y', $timestamp);
424
		// $date_formatee = strftime('%d/%m/%Y', $timestamp);
331
		$date_formatee = strftime('%Y/%m/%d', $timestamp);
425
		$date_formatee = strftime('%Y/%m/%d', $timestamp);
332
		if(!$date_formatee) return "00/00/0000";
426
		if(!$date_formatee) return "00/00/0000";
333
		return $date_formatee;
427
		return $date_formatee;
334
	}
428
	}
335
	
429
 
336
	static function getImages($obs, $id_utilisateur, $cel) {
430
	static function getImages($obs, $id_utilisateur, $cel) {
337
		if(! $id_utilisateur) return NULL;
431
		if(! $id_utilisateur) return NULL;
338
		$rec = $cel->requeter(
432
		$rec = $cel->requeter(
339
			sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
433
			sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') AS i FROM cel_images i"
340
					." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
434
					." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
341
					." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
435
					." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
342
					." WHERE ce_utilisateur = %d",
436
					." WHERE o.ce_utilisateur = %d AND o.id_observation = %d LIMIT 1",
343
					SEPARATEUR_IMAGES,
437
					SEPARATEUR_IMAGES,
344
					$id_utilisateur));
438
					$id_utilisateur,
-
 
439
					$obs['id_observation']));
345
		return $rec ? array_pop($rec) : NULL;
440
		return $rec ? $rec[0]['i'] : NULL;
346
	}
441
	}
Line 347... Line 442...
347
	
442
	
348
	public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {	
443
	public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {	
349
		$code_departement = '';
444
		$code_departement = '';
350
		if(self::estUnCodeInseeDepartement($code_zone_geo)) {
445
		if(self::estUnCodeInseeDepartement($code_zone_geo)) {
351
			$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2);
446
			$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2);
Line 352... Line 447...
352
		}
447
		}
353
	
448
	
-
 
449
		return $code_departement;
-
 
450
	}
-
 
451
 
-
 
452
	public static function trim0($lonlat) {
-
 
453
		return trim(trim($lonlat, "0"), ".");
-
 
454
	}
-
 
455
 
-
 
456
	public static function boolOuiNon($transmission) {
Line 354... Line 457...
354
		return $code_departement;
457
		return $transmission ? 'oui' : '';
355
	}
458
	}
356
	
459
	
Line 512... Line 615...
512
 
615
 
513
		$langue = 'fra';
616
		$langue = 'fra';
514
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
617
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
Line -... Line 618...
-
 
618
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
-
 
619
 
515
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
620
		// cache:
516
 
621
		if(isset($cache['getNomCommun'])) {
517
		if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
622
			if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
-
 
623
			// XXX: problème de valeurs NULL ?
Line 518... Line 624...
518
		// XXX: problème de valeurs NULL ?
624
			if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
519
		if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
625
		}
520
 
626
 
521
		// pas de cache:
627
		// pas de cache: