Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 248 Rev 249
Line 3... Line 3...
3
class OdsExport extends OdsTriple {
3
class OdsExport extends OdsTriple {
Line 4... Line 4...
4
	
4
	
5
	const PREFIXE = 'get';
5
	const PREFIXE = 'get';
6
	const ABBR_LISTE_EVENEMENTS = 'evenement';
6
	const ABBR_LISTE_EVENEMENTS = 'evenement';
-
 
7
	const ABBR_LISTE_ESPECES = 'espece';
7
	const ABBR_LISTE_ESPECES = 'espece';
8
	const ABBR_LISTE_MILIEUX = 'environnement';
8
	
9
 
Line 9... Line 10...
9
	private $type_mime = 'text/html';
10
	private $type_mime = 'text/html';
10
	
11
	
11
	/**
12
	/**
Line 29... Line 30...
29
                $info = $this->$methode($param);
30
                $info = $this->$methode($param);
30
            } else {
31
            } else {
31
                $this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
32
                $this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
32
            }
33
            }
33
        }
34
        }
34
       
35
 
35
        $this->envoyer($info,$this->type_mime);
36
	$this->envoyer($info,$this->type_mime);
36
    }
37
    }
37
    	
38
	
38
	public function getExportObservation($start = null,$limit = null, $order_by = 'oo_date') {
39
	public function getExportObservation($start = null,$limit = null, $order_by = 'oo_date') {
Line 39... Line 40...
39
						
40
						
40
		$requete_selection_observations = 'SELECT * FROM ods_observations '.
41
		$requete_selection_observations = 'SELECT * FROM ods_observations '.
41
									' LEFT JOIN ods_individus '. 
42
									' LEFT JOIN ods_individus '. 
Line 119... Line 120...
119
	}
120
	}
Line 120... Line 121...
120
	
121
	
Line 121... Line 122...
121
	public function getExportObservationPlat() {
122
	public function getExportObservationPlat() {
122
				
123
				
Line 123... Line 124...
123
		$donnees = $this->getExportObservation();
124
		$donnees = $this->getExportObservation();
124
		$donnees_formatees = $this->formaterPourExportObservationCSV($donnees);	
125
		$donnees_formatees = $this->formaterPourExportCSV($donnees);	
Line 125... Line 126...
125
			
126
			
Line 126... Line 127...
126
		return $donnees_formatees ;
127
		return $donnees_formatees ;
127
	}
128
	}
128
	
129
	
129
	public function getExportObservationJson() {
130
	public function getExportObservationJson() {
Line 130... Line 131...
130
		
131
		
131
		$donnees = $this->getExportObservation();
132
		$donnees = $this->getExportObservation();
Line 132... Line 133...
132
		$donnees_formatees = $this->formaterPourExportObservationJson($donnees);
133
		$donnees_formatees = $this->formaterPourExportJson($donnees);
Line 133... Line 134...
133
		
134
 
134
		$this->type_mime = 'application/json';
135
		$this->type_mime = 'application/json';
Line 135... Line 136...
135
		
136
		
136
		return $donnees_formatees;
137
		return $donnees_formatees;
-
 
138
	}
Line 137... Line 139...
137
	}
139
	
Line 138... Line 140...
138
	
140
	public function formaterPourExportJson($tableau_observations_infos) {
Line 175... Line 177...
175
				$resultats_formates[$id_station]['code_commune'] = $observations_infos['os_ce_commune'];
177
				$resultats_formates[$id_station]['code_commune'] = $observations_infos['os_ce_commune'];
176
				//$resultats_formates[$id_station]['nom_commune'] = $gestionnaire_communes->obtenirNomCommuneParCodeInsee($observations_infos['os_ce_commune']);
178
				//$resultats_formates[$id_station]['nom_commune'] = $gestionnaire_communes->obtenirNomCommuneParCodeInsee($observations_infos['os_ce_commune']);
177
				$resultats_formates[$id_station]['latitude'] = $observations_infos['os_latitude'];
179
				$resultats_formates[$id_station]['latitude'] = $observations_infos['os_latitude'];
178
				$resultats_formates[$id_station]['longitude'] = $observations_infos['os_longitude'];
180
				$resultats_formates[$id_station]['longitude'] = $observations_infos['os_longitude'];
179
				$resultats_formates[$id_station]['altitude'] = $observations_infos['os_altitude'];
181
				$resultats_formates[$id_station]['altitude'] = $observations_infos['os_altitude'];
180
				$resultats_formates[$id_station]['milieu'] = $observations_infos['os_milieu'];
182
				$resultats_formates[$id_station]['milieu'] = $milieux[$observations_infos['os_ce_environnement']]['ot_valeur'];
181
				$resultats_formates[$id_station]['participant'] = $observations_infos['os_ce_participant'];
183
				$resultats_formates[$id_station]['participant'] = $observations_infos['os_ce_participant'];
182
			}
184
			}
Line 183... Line 185...
183
			
185
			
184
			$resultats_formates[$id_station]['obs'][$id_observation] = $infos_formatees;
186
			$resultats_formates[$id_station]['obs'][$id_observation] = $infos_formatees;
Line 188... Line 190...
188
	}
190
	}
Line 189... Line 191...
189
	
191
	
Line 190... Line 192...
190
	public function getFichierExportObservationCsv() {
192
	public function getFichierExportObservationCsv() {
191
				
193
				
192
		$donnees = $this->getExportObservation();
194
		$donnees = $this->getExportObservation();
Line 193... Line 195...
193
		$donnees_formatees = $this->formaterPourExportObservationCSV($donnees);		
195
		$donnees_formatees = $this->formaterPourExportCSV($donnees);		
194
		$chaine_csv = $this->convertirTableauAssocVersCSV($donnees_formatees);
196
		$chaine_csv = $this->convertirTableauAssocVersCSV($donnees_formatees);
Line 195... Line 197...
195
			
197
			
Line 196... Line 198...
196
		$this->envoyerFichier($chaine_csv);
198
		$this->envoyerFichier($chaine_csv);
197
	}
199
	}
198
	
200
	
Line 199... Line 201...
199
	public function formaterPourExportObservationCSV($tableau_observations_infos) {
201
	public function formaterPourExportCSV($tableau_observations_infos) {
200
		
202
		
-
 
203
		$gestionnaire_especes = new OdsEspece($this->config);
Line 201... Line 204...
201
		$gestionnaire_especes = new OdsEspece($this->config);
204
		$gestionnaire_communes = new OdsCommune($this->config);
Line 202... Line 205...
202
		$gestionnaire_communes = new OdsCommune($this->config);
205
		$gestionnaire_utilisateurs = new OdsUtilisateur($this->config);
Line 233... Line 236...
233
				'code_commune' => $observations_infos['os_ce_commune'],
236
				'code_commune' => $observations_infos['os_ce_commune'],
234
				'nom_commune' => '',
237
				'nom_commune' => '',
235
				'latitude' => $observations_infos['os_latitude'],
238
				'latitude' => $observations_infos['os_latitude'],
236
				'longitude' => $observations_infos['os_longitude'],
239
				'longitude' => $observations_infos['os_longitude'],
237
				'altitude' => $observations_infos['os_altitude'],
240
				'altitude' => $observations_infos['os_altitude'],
238
				'milieu' => $observations_infos['os_milieu'],
241
				'milieu' => $milieux[$observations_infos['os_ce_environnement']]['ot_valeur'],
239
				'id_participant' => $observations_infos['os_ce_participant'],
242
				'id_participant' => $observations_infos['os_ce_participant'],
240
				'pseudo_participant' => '',
243
				'pseudo_participant' => '',
241
				'mail_participant' => ''
244
				'mail_participant' => ''
242
			);
245
			);
Line 262... Line 265...
262
		}
265
		}
Line 263... Line 266...
263
		
266
		
264
		return $resultats_formates;
267
		return $resultats_formates;
Line 265... Line -...
265
	}
-
 
266
	
-
 
267
	public function getExportStationJson() {
-
 
268
    	
-
 
269
    	$donnees = $this->getExportStation();
-
 
270
    	$donnees_formatees = $this->formaterPourExportStationJson($donnees);
-
 
271
    	
-
 
272
    	$this->type_mime = 'application/json';
-
 
273
    	
-
 
274
    	return $donnees_formatees;
-
 
275
    }
-
 
276
    
-
 
277
    public function getExportStation() {
-
 
278
    	
-
 
279
    	$requete_selection_stations = 'SELECT * FROM ods_stations '.
-
 
280
    								  ' LEFT JOIN ods_individus '.
-
 
281
    								  ' ON ods_individus.oi_ce_station = ods_stations.os_id_station '.
-
 
282
    								  ' ORDER BY ods_stations.os_id_station, ods_individus.oi_ce_espece';
-
 
283
    								  
-
 
284
 		$res_selection_stations = $this->executerRequete($requete_selection_stations);
-
 
285
 		
-
 
286
 		return $res_selection_stations;
-
 
287
    }
-
 
288
    
-
 
289
    public function formaterPourExportStationJson($tableau_stations_infos) {
-
 
290
    	
-
 
291
    	$gestionnaire_especes = new OdsEspece($this->config);
-
 
292
		$gestionnaire_communes = new OdsCommune($this->config);
-
 
293
		$gestionnaire_utilisateurs = new OdsUtilisateur($this->config);		
-
 
294
				
-
 
295
		$especes = $gestionnaire_especes->getToutesEspeces();
-
 
296
		
-
 
297
		$resultats_formates = array();
-
 
298
		
-
 
299
		foreach($tableau_stations_infos as &$stations_infos) {
-
 
300
			
-
 
301
			if(!isset($resultats_formates[$stations_infos['os_id_station']])) {
-
 
302
				if($stations_infos['os_ce_commune'] == "NULL") {
-
 
303
					$stations_infos['os_ce_commune'] = '';
-
 
304
				}
-
 
305
				
-
 
306
				$resultats_formates[$stations_infos['os_id_station']] = array(
-
 
307
					'station' => $stations_infos['os_nom'],
-
 
308
					'code_commune' => $stations_infos['os_ce_commune'],
-
 
309
					'nom_commune' => '',
-
 
310
					'latitude' => $stations_infos['os_latitude'],
-
 
311
					'longitude' => $stations_infos['os_longitude'],
-
 
312
					'altitude' => $stations_infos['os_altitude'],
-
 
313
					'id_participant' => $stations_infos['os_ce_participant'],
-
 
314
					'pseudo_participant' => '',
-
 
315
					'mail_participant' => '',
-
 
316
					'especes' => array()
-
 
317
				);
-
 
318
				
-
 
319
				if(is_numeric($stations_infos['os_ce_commune'])) {
-
 
320
					$codes_insee_communes[] = $stations_infos['os_ce_commune'];
-
 
321
				}
-
 
322
			}
-
 
323
			
-
 
324
			$infos_espece = $especes[$stations_infos['oi_ce_espece']];
-
 
325
			
-
 
326
			if($infos_espece != null) {
-
 
327
				
-
 
328
				if($infos_espece['type'] != "") {
-
 
329
					$infos_espece['type'] = $this->obtenirValeurTripleParId($infos_espece['type']);
-
 
330
				}
-
 
331
				
-
 
332
				$resultats_formates[$stations_infos['os_id_station']]['especes'][$infos_espece['id_espece']] = $infos_espece;
-
 
333
			}
-
 
334
		}
-
 
335
		
-
 
336
		$correspondance_codes_insee_noms = $gestionnaire_communes->obtenirTableauNomsCommunesParTableauCodesInsee($codes_insee_communes);
-
 
337
		$correspondance_id_utilisateur = $gestionnaire_utilisateurs->getListeUtilisateurAvecInfosComplementairesFormateeId();
-
 
338
		
-
 
339
		foreach($resultats_formates as &$resultat) {
-
 
340
			
-
 
341
			if(isset($correspondance_codes_insee_noms[$resultat['code_commune']]) && trim($correspondance_codes_insee_noms[$resultat['code_commune']]) != '') {								
-
 
342
				$resultat['nom_commune'] = $correspondance_codes_insee_noms[$resultat['code_commune']];
-
 
343
			}
-
 
344
			
-
 
345
			$resultat['pseudo_participant'] = $correspondance_id_utilisateur[$resultat['id_participant']]['name'];
-
 
346
			$resultat['mail_participant'] = $correspondance_id_utilisateur[$resultat['id_participant']]['mail'];
-
 
347
			
-
 
348
			$types = array("Particulier" ,"Établissement scolaire", "Association" ,"Professionnel", "Autre","Inconnu");
-
 
349
			
-
 
350
			if(isset($correspondance_id_utilisateur[$resultat['id_participant']]['profile_type'])) {
-
 
351
				$resultat['type_participant'] = $correspondance_id_utilisateur[$resultat['id_participant']]['profile_type'];
-
 
352
			} else {
-
 
353
				$resultat['type_participant'] = "Inconnu";
-
 
354
			}
-
 
355
		}
-
 
356
		
-
 
357
		return $resultats_formates;
-
 
358
    }
268
	}
Line 359... Line 269...
359
	
269
	
360
	public function convertirTableauAssocVersCSV($tableau) {
270
	public function convertirTableauAssocVersCSV($tableau) {
361
		
271