Subversion Repositories eFlore/Applications.cel

Rev

Rev 1374 | Rev 1378 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1374 Rev 1376
1
<?php
1
<?php
2
/**
2
/**
3
* Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
3
* Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
4
* Encodage en entrée : utf8
4
* Encodage en entrée : utf8
5
* Encodage en sortie : utf8
5
* Encodage en sortie : utf8
6
* Format du service :
6
* Format du service :
7
* /CelWidgetExport/format
7
* /CelWidgetExport/format
8
* /CelWidgetExport/csv
8
* /CelWidgetExport/csv
9
*
9
*
10
* Les paramêtres :
10
* Les paramêtres :
11
*  - "start" indique le numéro du premier item à afficher
11
*  - "start" indique le numéro du premier item à afficher
12
*  - "limit" nombre d'items à afficher
12
*  - "limit" nombre d'items à afficher
13
*
13
*
14
* @author Aurélien Peronnet <aurelien@tela-botanica.org>
14
* @author Aurélien Peronnet <aurelien@tela-botanica.org>
15
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
16
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
17
* @version $Id$
17
* @version $Id$
18
* @copyright 2012
18
* @copyright 2012
19
*/
19
*/
20
class CelWidgetExport extends Cel {
20
class CelWidgetExport extends Cel {
21
	
21
	
22
	private $nom_fichier_export = 'cel_export.csv';
22
	private $nom_fichier_export = 'cel_export.csv';
23
	private $champs_a_exclure = array('ce_utilisateur' => 'ce_utilisateur', 
23
	private $champs_a_exclure = array('ce_utilisateur' => 'ce_utilisateur', 
24
		'courriel_utilisateur' => 'courriel_utilisateur',
24
		'courriel_utilisateur' => 'courriel_utilisateur',
25
		'transmission' => 'transmission');
25
		'transmission' => 'transmission');
26
	private $correspondance_champs = array(
26
	private $correspondance_champs = array(
27
		'id_observation' => 'Identifiant Observation',
27
		'id_observation' => 'Identifiant Observation',
28
		'ordre' => 'Ordre Observation',
28
		'ordre' => 'Ordre Observation',
29
		'prenom_utilisateur' => 'Prénom',
29
		'prenom_utilisateur' => 'Prénom',
30
		'nom_utilisateur' => 'Nom',
30
		'nom_utilisateur' => 'Nom',
31
		'nom_sel' => 'Nom Sélectionné',
31
		'nom_sel' => 'Nom Sélectionné',
32
		'nom_sel_nn' => 'Numéro Nomenclatural Nom Selectionné',
32
		'nom_sel_nn' => 'Numéro Nomenclatural Nom Selectionné',
33
		'nom_ret' => 'Nom Retenu',
33
		'nom_ret' => 'Nom Retenu',
34
		'nom_ret_nn' => 'Numéro Nomenclatural Nom Retenu',
34
		'nom_ret_nn' => 'Numéro Nomenclatural Nom Retenu',
35
		'nt' => 'Numéro Taxonomique',
35
		'nt' => 'Numéro Taxonomique',
36
		'famille' => 'Famille',
36
		'famille' => 'Famille',
37
		'nom_referentiel' => 'Référentiel Taxonomique',
37
		'nom_referentiel' => 'Référentiel Taxonomique',
38
		'ce_zone_geo' => 'Code Insee',
38
		'ce_zone_geo' => 'Code Insee',
39
		'zone_geo' => 'Commune',
39
		'zone_geo' => 'Commune',
40
		'lieudit' => 'Lieu-Dit',
40
		'lieudit' => 'Lieu-Dit',
41
		'station' => 'Station',
41
		'station' => 'Station',
42
		'milieu' => 'Milieu',
42
		'milieu' => 'Milieu',
43
		'latitude' => 'Latitude',
43
		'latitude' => 'Latitude',
44
		'longitude' => 'Longitude',
44
		'longitude' => 'Longitude',
45
		'geodatum' => 'Référentiel Géographique',
45
		'geodatum' => 'Référentiel Géographique',
46
		'date_observation' => 'Date Observation',
46
		'date_observation' => 'Date Observation',
47
		'mots_cles_texte' => 'Mots Clés',
47
		'mots_cles_texte' => 'Mots Clés',
48
		'commentaire' => 'Commentaires',
48
		'commentaire' => 'Commentaires',
49
		'date_creation' => 'Date Création',
49
		'date_creation' => 'Date Création',
50
		'date_modification' => 'Date Modification',
50
		'date_modification' => 'Date Modification',
51
		'date_transmission' => 'Date Transmission'
51
		'date_transmission' => 'Date Transmission'
52
		);
52
		);
-
 
53
	private $parametres_autorises = array(
-
 
54
		'utilisateur' => 'courriel_utilisateur',
-
 
55
		'commune' => 'zone_geo',
-
 
56
		'dept' => 'departement',
-
 
57
		'projet' => 'mots_cles',
-
 
58
		'num_tax' => 'nt'
-
 
59
	);
53
		
60
		
54
	/**
61
	/**
55
	 * Méthode appelée avec une requête de type GET.
62
	 * Méthode appelée avec une requête de type GET.
56
	 */
63
	 */
57
	public function getElement($params = array()) {
64
	public function getElement($params = array()) {
58
		
65
		
59
		$criteres = $_GET;
66
		$criteres = $this->traiterParametres($_GET);
60
		// Seulement les observation publiques
67
		// Seulement les observation publiques
61
		$criteres['transmission'] = 1;
68
		$criteres['transmission'] = 1;
62
		$chercheur_observations = new RechercheObservation($this->config);
69
		$chercheur_observations = new RechercheObservation($this->config);
63
		
70
		
64
		$numero_page = isset($criteres['debut']) ? $criteres['debut'] : 1;
71
		$numero_page = isset($criteres['debut']) ? $criteres['debut'] : 1;
65
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 50;
72
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 50;
66
		
73
		
67
		unset($criteres['limite']);
74
		unset($criteres['limite']);
68
		unset($criteres['debut']);
75
		unset($criteres['debut']);
69
	
76
	
70
		$observations = $chercheur_observations->rechercherObservations(null, $criteres, $numero_page, $limite);
77
		$observations = $chercheur_observations->rechercherObservations(null, $criteres, $numero_page, $limite);
71
		$csv = $this->convertirEnCsv($observations);
78
		$csv = $this->convertirEnCsv($observations);
72
		$this->envoyerCsv($csv);
79
		$this->envoyerCsv($csv);
73
	}
80
	}
-
 
81
	
-
 
82
	protected function traiterParametres(Array $parametres) {
-
 
83
		$parametres_traites = array();
-
 
84
		foreach($parametres as $cle => $valeur) {
-
 
85
			if(trim($valeur) != '' && isset($this->parametres_autorises[$cle])) {
-
 
86
				$parametres_traites[$this->parametres_autorises[$cle]] = $valeur;
-
 
87
			}
-
 
88
		}
-
 
89
		return $parametres_traites;
-
 
90
	}
74
	
91
	
75
	private function envoyerCsv($csv) {
92
	private function envoyerCsv($csv) {
76
		header('Content-Type: text/csv; charset=UTF-8');
93
		header('Content-Type: text/csv; charset=UTF-8');
77
		header('Content-Disposition: attachment;filename='.$this->nom_fichier_export);
94
		header('Content-Disposition: attachment;filename='.$this->nom_fichier_export);
78
		echo $csv;
95
		echo $csv;
-
 
96
		exit;
79
	}
97
	}
80
	
98
	
81
	private function convertirEnCsv($data)
99
	private function convertirEnCsv($data)
82
	{
100
	{
83
		$chemin_temp = "php://temp";
101
		$chemin_temp = "php://temp";
84
		$outstream = fopen($chemin_temp, 'r+');
102
		$outstream = fopen($chemin_temp, 'r+');
85
		$intitule_champs = array();
103
		$intitule_champs = array();
86
		foreach($data as $ligne) {
104
		foreach($data as $ligne) {
87
			$ligne = array_diff_key($ligne, $this->champs_a_exclure);
105
			$ligne = array_diff_key($ligne, $this->champs_a_exclure);
88
			if(empty($intitule_champs)) {
106
			if(empty($intitule_champs)) {
89
				$intitule_champs = $this->creerEntetesChamps($ligne);
107
				$intitule_champs = $this->creerEntetesChamps($ligne);
90
				fputcsv($outstream, $intitule_champs, ',', '"');			
108
				fputcsv($outstream, $intitule_champs, ',', '"');			
91
			}
109
			}
92
			fputcsv($outstream, $ligne, ',', '"');
110
			fputcsv($outstream, $ligne, ',', '"');
93
		}
111
		}
94
		rewind($outstream);
112
		rewind($outstream);
95
		$csv = stream_get_contents($outstream);
113
		$csv = stream_get_contents($outstream);
96
		fclose($outstream);
114
		fclose($outstream);
97
		return $csv;
115
		return $csv;
98
	}
116
	}
99
	
117
	
100
	private function creerEntetesChamps($noms_colonnes) {
118
	private function creerEntetesChamps($noms_colonnes) {
101
		$champs_presents = array_intersect_key($this->correspondance_champs, $noms_colonnes);
119
		$champs_presents = array_intersect_key($this->correspondance_champs, $noms_colonnes);
102
		return array_values($champs_presents);
120
		return array_values($champs_presents);
103
	}
121
	}
104
}
122
}
105
?>
123
?>