Subversion Repositories eFlore/Applications.cel

Rev

Rev 1654 | Rev 1657 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1654 Rev 1656
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
 
-
 
3
/**
-
 
4
* @category  PHP
-
 
5
* @package   jrest
-
 
6
* @author    Raphaël Droz <raphael@tela-botania.org>
-
 
7
* @copyright 2013 Tela-Botanica
-
 
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>
-
 
10
*/
-
 
11
 
-
 
12
define('SEPARATEUR_IMAGES', ",");
-
 
13
 
2
Class FormateurGroupeColonne {
14
Class FormateurGroupeColonne {
-
 
15
 
-
 
16
	static $cache = Array();
-
 
17
 
3
	/*
18
	/*
4
	* @param $fieldSets: un liste de noms de colonnes ou de sets de colonnes
19
	* @param $fieldSets: un liste de noms de colonnes ou de sets de colonnes
5
	*		séparés par des virgules
20
	*		séparés par des virgules
6
	* 		eg: "espece" ou "champs-etendus", ...
21
	* 		eg: "espece" ou "champs-etendus", ...
7
	*
22
	*
Line 38... Line 53...
38
				'geodatum'			=> self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
53
				'geodatum'			=> self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
39
			);
54
			);
40
		}
55
		}
Line 41... Line 56...
41
		
56
		
-
 
57
		if(isset($groupe_de_champs['avance'])) {
42
		if(isset($groupe_de_champs['avance'])) {
58
			$colonnes += array(
43
			$colonnes += array(			   // TODO: importable = FALSE car pas de merge de données importées
59
			   // TODO: importable = FALSE car pas de merge de données importées
44
				'ordre'				=> self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
60
			   'ordre'				=> self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
-
 
61
			   'id_observation'		=> self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
45
				'id_observation'		=> self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
62
 
46
				'mots_cles_texte'	=> self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
63
			   'mots_cles_texte'	=> self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
47
				'commentaire'		=> self::GenColInfo('commentaire', 'Commentaires', 1),
64
			   'commentaire'		=> self::GenColInfo('commentaire', 'Commentaires', 1),
48
				'date_creation'		=> self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
65
			   'date_creation'		=> self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
-
 
66
			   'date_modification'	=> self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),
49
				'date_modification'	=> self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),	
67
 
50
				// rappel transmission = 1, signifie simplement "public"
68
			   // rappel transmission = 1, signifie simplement "public"
51
				// des données importées peuvent être d'emblée "publiques"
69
			   // des données importées peuvent être d'emblée "publiques"
52
				// "importable" = TRUE
70
			   // "importable" = TRUE
53
				'transmission'		=> self::GenColInfo('transmission', 'Transmis', 1),
71
			   'transmission'		=> self::GenColInfo('transmission', 'Transmis', 1),
54
				'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1, NULL, NULL, FALSE),
72
			   'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1, NULL, NULL, FALSE),
55
				'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
73
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
56
				'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
74
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
-
 
75
			   'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
-
 
76
 
-
 
77
			   // XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
57
				'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
78
			   // cf ExportXLS::traiterLigneObservation()
58
				//'images'				=> self::GenColInfo('images', 'Image(s)', 1, NULL, 'getImages', TRUE),
79
			   'images'				=> self::GenColInfo('images', 'Image(s)', 1, NULL, 'getImages', TRUE),
59
			);
80
			);
60
		}	
-
 
61
		//
-
 
62
		//'nom_commun'			=> self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
-
 
63
		//'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
-
 
64
		//'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'),
-
 
65
		//
-
 
66
		return $colonnes;
-
 
Line 67... Line 81...
67
	}
81
		}	
68
	
82
 
69
	public static function getIntitulesColonnes(&$colonnes) {
83
		/* 'nom_commun'			=> self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
-
 
84
		   'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
70
		$entetes = array();
85
		   'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
71
		foreach($colonnes as &$colonne) {
86
 
Line 72... Line 87...
72
			$entetes[] = $colonne['nom'];
87
		return $colonnes;
-
 
88
	}
73
		}
89
	
Line 74... Line 90...
74
		
90
	public static function getIntitulesColonnes($colonnes) {
75
		return $entetes;
91
		return array_map(function($item) { return $item['nom']; }, $colonnes);
76
	}
92
	}
77
	
93
	
78
	public static function getLigneObservation(&$obs, &$colonnes) {
94
	public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
Line 103... Line 119...
103
			// // cette section devrait être vide:
119
			// // cette section devrait être vide:
104
			// // cas particuliers ingérable avec l'architecture actuelle:
120
			// // cas particuliers ingérable avec l'architecture actuelle:
105
			if(false && $abbrev == 'date_observation' && $valeur == "0000-00-00") {
121
			if(false && $abbrev == 'date_observation' && $valeur == "0000-00-00") {
106
				/* blah */
122
				/* blah */
107
			}
123
			}
-
 
124
			if($abbrev == 'images') {
-
 
125
				$valeur = FormateurGroupeColonne::getImages($obs, $cel->id_utilisateur, $cel);
-
 
126
			}
Line 108... Line 127...
108
				
127
				
109
			if($valeur == null) {
128
			if($valeur == null) {
110
				$valeur = "";
129
				$valeur = "";
Line 152... Line 171...
152
			'fonction_data' => $fonction_data,
171
					 'fonction_data' => $fonction_data,
153
			'importable' => $importable
172
					 'importable' => $importable
154
		);
173
		);
155
	}
174
	}
Line 156... Line 175...
156
	
175
	
157
	protected function formaterDate($date_heure_mysql, $format = NULL) {
176
	static function formaterDate($date_heure_mysql) {
158
		if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return "00/00/0000";
177
		if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return "00/00/0000";
159
		$date_format = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql);
178
		$date_format = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql);
160
		$timestamp = @$date_format->getTimestamp();
179
		$timestamp = @$date_format->getTimestamp();
161
		if(!$timestamp) return "00/00/0000";
180
		if(!$timestamp) return "00/00/0000";
Line 165... Line 184...
165
				$date_formatee = strftime('%d/%m/%Y', $timestamp);
184
		$date_formatee = strftime('%d/%m/%Y', $timestamp);
166
		if(!$date_formatee) return "00/00/0000";
185
		if(!$date_formatee) return "00/00/0000";
167
		return $date_formatee;
186
		return $date_formatee;
168
	}
187
	}
Line 169... Line -...
169
	
-
 
170
	
-
 
171
	// TODO: mettre en static + param "id_utilisateur"
188
	
172
	function getImages($obs) {
189
	static function getImages($obs, $id_utilisateur, $cel) {
173
		if(! $this->id_utilisateur) return NULL;
190
		if(! $id_utilisateur) return NULL;
174
			$rec = $this->requeter(
191
		$rec = $cel->requeter(
175
			sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
192
			sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
176
			." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
193
					." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
177
							." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
194
					." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
178
							." WHERE ce_utilisateur = %d",
195
					." WHERE ce_utilisateur = %d",
179
							SEPARATEUR_IMAGES,
196
					SEPARATEUR_IMAGES,
180
							$this->id_utilisateur));
197
					$id_utilisateur));
181
				return $rec ? array_pop($rec) : NULL;
198
		return $rec ? array_pop($rec) : NULL;
Line 182... Line 199...
182
	}
199
	}
183
	
200
	
Line 203... Line 220...
203
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
220
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
204
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
221
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
205
		else return '';
222
		else return '';
Line 206... Line 223...
206
		
223
		
207
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
224
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
208
				if(isset($this->cache['getNomCommun'][$cache_id])) {
225
		if(isset(self::cache['getNomCommun'][$cache_id])) {
209
		//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")");
226
			//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")");
210
		return $this->cache['getNomCommun'][$cache_id];
227
			return self::cache['getNomCommun'][$cache_id];
211
		}
228
		}
212
		// pas de cache:
229
		// pas de cache:
Line 213... Line 230...
213
		//debug: error_log("require url_service_nom_attribution pour \"{$obs['nom_ret']}\"");
230
		//debug: error_log("require url_service_nom_attribution pour \"{$obs['nom_ret']}\"");
214
		
231
		
215
		// pour bdtfx:
232
		// pour bdtfx:
216
		// /service:eflore:0.1/nvjfl/noms-vernaculaires/attributions?masque.nt=X&masque.lg=fra&retour.champs=num_statut
233
		// /service:eflore:0.1/nvjfl/noms-vernaculaires/attributions?masque.nt=X&masque.lg=fra&retour.champs=num_statut
217
		// /projet/services/modules/0.1/nvjfl/NomsVernaculaires.php
234
		// /projet/services/modules/0.1/nvjfl/NomsVernaculaires.php
218
		$url = str_replace(Array('{referentiel}', '{valeur}', '{langue}'),
235
		$url = str_replace(Array('{referentiel}', '{valeur}', '{langue}'),
219
		Array($referentiel, $obs['nt'], $langue),
236
						   Array($referentiel, $obs['nt'], $langue),
220
		$this->config['eflore']['url_service_nom_attribution']) .
237
						   self::config['eflore']['url_service_nom_attribution']) .
221
					"&retour.champs=num_statut";
238
			"&retour.champs=num_statut";
222
		$noms = @json_decode(file_get_contents($url));
239
		$noms = @json_decode(file_get_contents($url));
223
		if(! $noms) return '';
-
 
224
		$noms = array_filter((array)($noms->resultat), function($item) {
-
 
225
		return ($item->num_statut == 1); 
240
		if(! $noms) return '';
Line 226... Line 241...
226
		});
241
		$noms = array_filter((array)($noms->resultat), function($item) { return ($item->num_statut == 1); });
227
		$nom = array_pop($noms)->nom_vernaculaire;
242
		$nom = array_pop($noms)->nom_vernaculaire;
228
		
243
		
229
		// cache
244
		// cache
Line -... Line 245...
-
 
245
		self::cache['getNomCommun'][$cache_id] = $nom;
-
 
246
		return $nom;
-
 
247
	}
-
 
248
	
-
 
249
	// si getNomCommun_v2 ou getNomCommun_v3 sont utilisés
Line 230... Line 250...
230
		$this->cache['getNomCommun'][$cache_id] = $nom;
250
	/* require_once('/home/raphael/eflore/framework/framework/Framework.php');
231
		return $nom;
251
	Framework::setCheminAppli("/home/raphael/eflore/projets/services/index.php");
232
	}
252
	Framework::setInfoAppli(Config::get('info'));
233
	
253
	require_once('/home/raphael/eflore/projets/services/modules/0.1/Projets.php');*/
Line 242... Line 262...
242
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
262
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
243
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
263
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
244
		else return '';
264
		else return '';
Line 245... Line 265...
245
		
265
		
246
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
266
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
247
		if(isset($this->cache['getNomCommun'][$cache_id])) {
267
		if(isset(self::cache['getNomCommun'][$cache_id])) {
248
		error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
268
			error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
249
		return $this->cache['getNomCommun'][$cache_id];
269
			return self::cache['getNomCommun'][$cache_id];
250
		}
270
		}
251
		// pas de cache:
271
		// pas de cache:
Line 252... Line 272...
252
		error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
272
		error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
253
		
273
		
254
				$donnees = Array('masque.nt' => $obs['nt'],
274
		$donnees = Array('masque.nt' => $obs['nt'],
255
		'masque.lg' => $langue,
275
						 'masque.lg' => $langue,
Line 256... Line 276...
256
									 'retour.champs' => 'num_statut');
276
						 'retour.champs' => 'num_statut');
257
		$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $donnees);
277
		$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $donnees);
258
		
-
 
259
		if(! $noms) return '';
-
 
260
				$noms = array_filter((array)($noms->resultat), function($item) { 
278
		
Line 261... Line 279...
261
		return ($item->num_statut == 1);
279
		if(! $noms) return '';
262
		});
280
		$noms = array_filter((array)($noms->resultat), function($item) { return ($item->num_statut == 1); });
263
		$nom = array_pop($noms)->nom_vernaculaire;
281
		$nom = array_pop($noms)->nom_vernaculaire;
264
		
282
		
Line 265... Line 283...
265
				// cache
283
		// cache
Line 278... Line 296...
278
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
296
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
279
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
297
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
280
		else return '';
298
		else return '';
Line 281... Line 299...
281
		
299
		
282
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
300
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
283
		if(isset($this->cache['getNomCommun'][$cache_id])) {
301
		if(isset(self::cache['getNomCommun'][$cache_id])) {
284
		error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
302
			error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
285
					return $this->cache['getNomCommun'][$cache_id];
303
			return self::cache['getNomCommun'][$cache_id];
286
		}
304
		}
287
		// pas de cache:
305
		// pas de cache:
Line 288... Line 306...
288
				error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
306
		error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
Line 295... Line 313...
295
		$noms = $this->service->traiterRessources();
313
			$noms = $this->service->traiterRessources();
296
				} catch(Exception $e) { 
314
		} catch(Exception $e) { 
297
		return '';
315
			return '';
298
		}
316
		}
299
				if(! $noms) return '';
317
		if(! $noms) return '';
300
		$noms = array_filter($noms['resultat'], function($item) {
318
		$noms = array_filter($noms['resultat'], function($item) { return ($item['num_statut'] == 1); });
301
		return ($item['num_statut'] == 1);
-
 
302
		});
-
 
303
				$premier_nom = array_pop($noms);
319
		$premier_nom = array_pop($noms);
304
		$nom = $premier_nom['nom_vernaculaire'];
320
		$nom = $premier_nom['nom_vernaculaire'];
Line 305... Line 321...
305
		
321
		
306
		// cache
322
		// cache
307
		$this->cache['getNomCommun'][$cache_id] = $nom;
323
		self::cache['getNomCommun'][$cache_id] = $nom;
308
		return $nom;
324
		return $nom;
Line 309... Line 325...
309
	}
325
	}
310
	
326