207 |
aurelien |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class OdsExport extends OdsTriple {
|
|
|
4 |
|
|
|
5 |
const PREFIXE = 'get';
|
|
|
6 |
const ABBR_LISTE_EVENEMENTS = 'evenement';
|
|
|
7 |
const ABBR_LISTE_ESPECES = 'espece';
|
249 |
aurelien |
8 |
const ABBR_LISTE_MILIEUX = 'environnement';
|
|
|
9 |
|
246 |
aurelien |
10 |
private $type_mime = 'text/html';
|
|
|
11 |
|
207 |
aurelien |
12 |
/**
|
|
|
13 |
* Méthodes d'extractions d'informations
|
|
|
14 |
*/
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Méthode appelée avec une requête de type GET.
|
|
|
18 |
*
|
|
|
19 |
*/
|
|
|
20 |
function getElement($param = array()) {
|
|
|
21 |
|
|
|
22 |
$type = $param[0];
|
|
|
23 |
|
|
|
24 |
if ($type == '*' || is_numeric($type)) {
|
|
|
25 |
$info = $this->getElementParDefaut($param);
|
|
|
26 |
} else {
|
|
|
27 |
$methode = self::PREFIXE.$type;
|
|
|
28 |
if (method_exists($this, $methode)) {
|
|
|
29 |
array_shift($param);
|
|
|
30 |
$info = $this->$methode($param);
|
|
|
31 |
} else {
|
|
|
32 |
$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
|
|
|
33 |
}
|
|
|
34 |
}
|
249 |
aurelien |
35 |
|
270 |
aurelien |
36 |
$this->envoyer($info,$this->type_mime);
|
207 |
aurelien |
37 |
}
|
281 |
aurelien |
38 |
|
270 |
aurelien |
39 |
public function getExportStationJson() {
|
281 |
aurelien |
40 |
|
270 |
aurelien |
41 |
$donnees = $this->getExportStation();
|
|
|
42 |
$donnees_formatees = $this->formaterListeStationPourExportJson($donnees);
|
|
|
43 |
|
|
|
44 |
$this->type_mime = 'application/json';
|
|
|
45 |
|
|
|
46 |
return $donnees_formatees;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function getExportStation($start = null,$limit = null, $order_by = 'oo_date') {
|
|
|
50 |
|
279 |
aurelien |
51 |
$id_demo = $this->config['appli']['id_participant_demo'];
|
|
|
52 |
$requete_selection_stations = 'SELECT * FROM ods_stations WHERE os_ce_participant != '.$this->proteger($id_demo);
|
270 |
aurelien |
53 |
$res_selection_stations = $this->executerRequete($requete_selection_stations);
|
|
|
54 |
|
|
|
55 |
return $res_selection_stations;
|
|
|
56 |
}
|
|
|
57 |
|
281 |
aurelien |
58 |
public function getExportUtilisateurCsv() {
|
|
|
59 |
|
|
|
60 |
$controle = new ControleUtilisateur($this->config);
|
|
|
61 |
$controle->authentifierAdmin();
|
|
|
62 |
|
|
|
63 |
$gestionnaire_utilisateurs = new OdsUtilisateur($this->config);
|
|
|
64 |
$utilisateurs = $gestionnaire_utilisateurs->getListeUtilisateurAvecInfosComplementairesFormateeId();
|
|
|
65 |
|
|
|
66 |
$utilisateurs_formates = array();
|
|
|
67 |
$premiere_annee = 2006;
|
|
|
68 |
|
|
|
69 |
$nb_obs = $this->compterObservationsParUtilisateur();
|
282 |
aurelien |
70 |
$annees = array();
|
281 |
aurelien |
71 |
|
|
|
72 |
foreach ($utilisateurs as $id => $utilisateur) {
|
|
|
73 |
$utilisateur_formate = array(
|
|
|
74 |
'id' => isset($utilisateur['uid']) ? $utilisateur['uid'] : '',
|
|
|
75 |
'pseudo' => isset($utilisateur['name']) ? $utilisateur['name'] : '',
|
|
|
76 |
'mail' => isset($utilisateur['mail']) ? $utilisateur['mail'] : '',
|
|
|
77 |
'nom' => isset($utilisateur['profile_nom']) ? $utilisateur['profile_nom'] : '',
|
|
|
78 |
'prenom' => isset($utilisateur['profile_prenom']) ? $utilisateur['profile_prenom'] : '',
|
|
|
79 |
'code postal' => isset($utilisateur['profile_code_postal']) ? $utilisateur['profile_code_postal'] : '',
|
|
|
80 |
'ville' => isset($utilisateur['profile_ville']) ? $utilisateur['profile_ville'] : '',
|
282 |
aurelien |
81 |
'type' => isset($utilisateur['profile_type']) ? $utilisateur['profile_type'] : '',
|
|
|
82 |
'date inscription' => isset($utilisateur['created']) ? date('d/m/Y', $utilisateur['created']) : '',
|
281 |
aurelien |
83 |
);
|
|
|
84 |
|
|
|
85 |
for($i = $premiere_annee; $i <= date('Y'); $i++) {
|
282 |
aurelien |
86 |
$annees['annee '.$i] += isset($nb_obs[$utilisateur['uid']]) && isset($nb_obs[$utilisateur['uid']][$i]) ? $nb_obs[$utilisateur['uid']][$i] : '0';
|
281 |
aurelien |
87 |
$utilisateur_formate['annee '.$i] = isset($nb_obs[$utilisateur['uid']]) && isset($nb_obs[$utilisateur['uid']][$i]) ? $nb_obs[$utilisateur['uid']][$i] : '0';
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
$utilisateurs_formates[] = $utilisateur_formate;
|
|
|
91 |
}
|
|
|
92 |
|
282 |
aurelien |
93 |
$ligne_total_obs = array(
|
|
|
94 |
'id' => '',
|
|
|
95 |
'pseudo' => '',
|
|
|
96 |
'mail' => '',
|
|
|
97 |
'nom' => '',
|
|
|
98 |
'prenom' => '',
|
|
|
99 |
'code postal' => '',
|
|
|
100 |
'ville' => '',
|
|
|
101 |
'type' => '',
|
|
|
102 |
'date inscription' => ''
|
|
|
103 |
);
|
|
|
104 |
$ligne_total_obs = array_merge($ligne_total_obs, $annees);
|
|
|
105 |
$utilisateurs_formates[] = $ligne_total_obs;
|
281 |
aurelien |
106 |
$csv = $this->convertirTableauAssocVersCSV($utilisateurs_formates);
|
|
|
107 |
$this->envoyerFichier($csv, 'utilisateurs');
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
private function compterObservationsParUtilisateur() {
|
|
|
111 |
$requete = 'SELECT COUNT(*) as nb_obs, oo_ce_participant as participant, YEAR(oo_date) as annee '.
|
|
|
112 |
'FROM `ods_observations` WHERE oo_date != "0000-00-00" GROUP BY oo_ce_participant, YEAR(oo_date)';
|
|
|
113 |
|
|
|
114 |
$res_selection_obs = $this->executerRequete($requete);
|
|
|
115 |
$stats = array();
|
|
|
116 |
foreach ($res_selection_obs as $obs_nb) {
|
|
|
117 |
$stats[$obs_nb['participant']][$obs_nb['annee']] = $obs_nb['nb_obs'];
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
return $stats;
|
|
|
121 |
}
|
|
|
122 |
|
270 |
aurelien |
123 |
public function formaterListeStationPourExportJson($tableau_stations_infos) {
|
|
|
124 |
|
|
|
125 |
$gestionnaire_especes = new OdsEspece($this->config);
|
|
|
126 |
$gestionnaire_communes = new OdsCommune($this->config);
|
|
|
127 |
$gestionnaire_utilisateurs = new OdsUtilisateur($this->config);
|
|
|
128 |
|
|
|
129 |
$especes = $gestionnaire_especes->getToutesEspeces();
|
|
|
130 |
$evenements = $this->obtenirValeursListeParAbreviation(self::ABBR_LISTE_EVENEMENTS);
|
|
|
131 |
$milieux = $this->obtenirValeursListeParAbreviation(self::ABBR_LISTE_MILIEUX);
|
|
|
132 |
$utilisateurs = $gestionnaire_utilisateurs->getListeUtilisateurAvecInfosComplementairesFormateeId();
|
|
|
133 |
$communes = $gestionnaire_communes->obtenirCommunesLieesAStationIndexeesCodeInsee();
|
|
|
134 |
|
|
|
135 |
$resultats_formates = array();
|
|
|
136 |
$stats = array('total' => count($tableau_stations_infos));
|
|
|
137 |
|
|
|
138 |
foreach($tableau_stations_infos as $stations_infos) {
|
|
|
139 |
$commune = isset($communes[$stations_infos['os_ce_commune']]['oc_nom']) ? $communes[$stations_infos['os_ce_commune']]['oc_nom'] : '';
|
|
|
140 |
|
|
|
141 |
$id_station = $stations_infos['os_id_station'];
|
|
|
142 |
$resultats_formates[$id_station]['nom'] = $stations_infos['os_nom'];
|
|
|
143 |
$resultats_formates[$id_station]['code_commune'] = is_numeric($stations_infos['os_ce_commune']) ? substr($stations_infos['os_ce_commune'], 0, 2) : '';
|
|
|
144 |
$resultats_formates[$id_station]['nom_commune'] = $commune;
|
|
|
145 |
$resultats_formates[$id_station]['latitude'] = $stations_infos['os_latitude'];
|
|
|
146 |
$resultats_formates[$id_station]['longitude'] = $stations_infos['os_longitude'];
|
|
|
147 |
$resultats_formates[$id_station]['altitude'] = $stations_infos['os_altitude'];
|
|
|
148 |
$resultats_formates[$id_station]['type_participant'] = 'Particulier';
|
|
|
149 |
|
|
|
150 |
if(isset($utilisateurs[$stations_infos['os_ce_participant']])) {
|
|
|
151 |
$participant = $utilisateurs[$stations_infos['os_ce_participant']];
|
|
|
152 |
$resultats_formates[$id_station]['participant']['id'] = $participant['uid'];
|
|
|
153 |
$resultats_formates[$id_station]['participant']['nom'] = $participant['name'];
|
|
|
154 |
$resultats_formates[$id_station]['type_participant'] = isset($participant['profile_type']) ? $participant['profile_type'] : 'Particulier';
|
|
|
155 |
} else {
|
|
|
156 |
$resultats_formates[$id_station]['participant']['id'] = null;
|
|
|
157 |
$resultats_formates[$id_station]['participant']['nom'] = 'Anonyme';
|
|
|
158 |
$resultats_formates[$id_station]['type_participant'] = 'Particulier';
|
|
|
159 |
}
|
|
|
160 |
if(isset($stats[$resultats_formates[$id_station]['type_participant']])) {
|
|
|
161 |
$stats[$resultats_formates[$id_station]['type_participant']]++;
|
|
|
162 |
} else {
|
|
|
163 |
$stats[$resultats_formates[$id_station]['type_participant']] = 1;
|
|
|
164 |
}
|
|
|
165 |
}
|
271 |
aurelien |
166 |
$resultat = array('stats' => $stats, 'stations' => $resultats_formates);
|
270 |
aurelien |
167 |
return $resultat;
|
|
|
168 |
}
|
249 |
aurelien |
169 |
|
207 |
aurelien |
170 |
public function getExportObservation($start = null,$limit = null, $order_by = 'oo_date') {
|
227 |
aurelien |
171 |
|
284 |
aurelien |
172 |
$requete_selection_observations = 'SELECT oo.*, oi.*, os.*, oc.* FROM ods_observations oo'.
|
|
|
173 |
' LEFT JOIN ods_individus oi'.
|
207 |
aurelien |
174 |
' ON oi_id_individu = oo_ce_individu'.
|
284 |
aurelien |
175 |
' INNER JOIN ods_especes oe'.
|
|
|
176 |
' ON oe.oe_espece_active = 1 '.
|
|
|
177 |
' AND oe.oe_id_espece = oi_ce_espece '.
|
|
|
178 |
' LEFT JOIN ods_stations os'.
|
263 |
gduche |
179 |
' ON oi_ce_station = os_id_station '.
|
284 |
aurelien |
180 |
' LEFT JOIN ods_communes oc'.
|
|
|
181 |
' ON os_ce_commune = oc_code_insee ';
|
|
|
182 |
|
207 |
aurelien |
183 |
$requete_selection_observations .= $this->construireConditionRequete();
|
|
|
184 |
$requete_selection_observations .= ' ORDER BY oo_date DESC';
|
284 |
aurelien |
185 |
|
207 |
aurelien |
186 |
$res_selection_observations = $this->executerRequete($requete_selection_observations);
|
284 |
aurelien |
187 |
|
207 |
aurelien |
188 |
return $res_selection_observations;
|
|
|
189 |
}
|
|
|
190 |
|
270 |
aurelien |
191 |
private function creerFiltreIdZoneGeo($valeurMasque) {
|
|
|
192 |
$masque = '';
|
|
|
193 |
$dept = $valeurMasque;
|
|
|
194 |
$dept = sprintf('%02s', $dept);
|
|
|
195 |
$dept = sprintf("%-'_5s", $dept);
|
|
|
196 |
$masque = " oc_code_insee LIKE ".$this->proteger($dept);
|
|
|
197 |
return $masque;
|
263 |
gduche |
198 |
}
|
|
|
199 |
|
207 |
aurelien |
200 |
public function construireConditionRequete() {
|
|
|
201 |
|
235 |
aurelien |
202 |
$condition = ' WHERE oo_date != "0000-00-00" AND DAY(oo_date) != "00" AND ';
|
207 |
aurelien |
203 |
|
|
|
204 |
foreach($_GET as $cle => $valeur) {
|
|
|
205 |
|
|
|
206 |
switch($cle) {
|
|
|
207 |
|
|
|
208 |
case 'type_espece':
|
|
|
209 |
$condition .= 'oi_ce_espece IN (SELECT oe_id_espece FROM ods_especes WHERE oe_ce_type = '.$this->proteger($valeur).')';
|
|
|
210 |
break;
|
|
|
211 |
|
|
|
212 |
case 'annee':
|
235 |
aurelien |
213 |
if($this->anneesMultiplesDemandees($valeur)) {
|
|
|
214 |
$valeur = rtrim($valeur,',');
|
|
|
215 |
$condition .= 'YEAR(oo_date) IN ('.$valeur.')';
|
|
|
216 |
} else {
|
|
|
217 |
$condition .= 'YEAR(oo_date) ';
|
|
|
218 |
$condition .= ' = '.$this->proteger($valeur);
|
|
|
219 |
}
|
207 |
aurelien |
220 |
break;
|
|
|
221 |
|
|
|
222 |
case 'mois':
|
|
|
223 |
$condition .= 'MONTH(oo_date) <= '.$this->proteger($valeur);
|
|
|
224 |
break;
|
|
|
225 |
|
|
|
226 |
case 'espece':
|
235 |
aurelien |
227 |
$condition .= 'oi_ce_espece IN ('.$valeur.') ';
|
207 |
aurelien |
228 |
break;
|
|
|
229 |
|
|
|
230 |
case 'evenement':
|
|
|
231 |
$condition .= 'oo_ce_evenement = '.$this->proteger($valeur);
|
|
|
232 |
break;
|
|
|
233 |
|
|
|
234 |
case 'utilisateur':
|
|
|
235 |
$condition .= 'oo_ce_participant = '.$this->proteger($valeur);
|
|
|
236 |
break;
|
|
|
237 |
|
264 |
gduche |
238 |
case 'departement' :
|
263 |
gduche |
239 |
$condition .= $this->creerFiltreIdZoneGeo($valeur);
|
|
|
240 |
break;
|
264 |
gduche |
241 |
|
|
|
242 |
case 'region' :
|
|
|
243 |
$requete_association_region .= 'SELECT * FROM ods_triples WHERE ot_ce_parent = 36 AND ot_valeur = '.$valeur;
|
|
|
244 |
$listeAssociationRegions = $this->executerRequete($requete_association_region);
|
|
|
245 |
$departements = array();
|
|
|
246 |
foreach ($listeAssociationRegions as $associationRegion) {
|
|
|
247 |
$departements[] = $this->creerFiltreIdZoneGeo($associationRegion['ot_cle']);
|
|
|
248 |
}
|
|
|
249 |
$condition .= ' ('. implode(' OR ', $departements).')';
|
|
|
250 |
break;
|
207 |
aurelien |
251 |
default:
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
$condition .= ' AND ';
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
$condition = rtrim($condition,'AND ');
|
|
|
258 |
|
227 |
aurelien |
259 |
$id_demo = $this->config['appli']['id_participant_demo'];
|
|
|
260 |
$id_admin = $this->config['appli']['id_participant_admin'];
|
|
|
261 |
|
|
|
262 |
$condition .= ' AND oo_ce_participant != '.$id_demo;
|
|
|
263 |
$condition .= ' AND oo_ce_participant != '.$id_admin;
|
|
|
264 |
|
207 |
aurelien |
265 |
return $condition;
|
|
|
266 |
}
|
|
|
267 |
|
235 |
aurelien |
268 |
private function anneesMultiplesDemandees($annee) {
|
|
|
269 |
// un ensemble d'identifiants est une suite d'identifiants séparés par des virgules
|
|
|
270 |
// sans virgule terminale
|
|
|
271 |
$reg_exp = "/^(([0-9])+,)*([0-9])+$/";
|
|
|
272 |
return preg_match($reg_exp, $annee);
|
|
|
273 |
}
|
|
|
274 |
|
210 |
aurelien |
275 |
public function getExportObservationPlat() {
|
|
|
276 |
|
|
|
277 |
$donnees = $this->getExportObservation();
|
270 |
aurelien |
278 |
$donnees_formatees = $this->formaterListeObservationPourExportCSV($donnees);
|
210 |
aurelien |
279 |
|
|
|
280 |
return $donnees_formatees ;
|
|
|
281 |
}
|
|
|
282 |
|
207 |
aurelien |
283 |
public function getExportObservationJson() {
|
|
|
284 |
|
|
|
285 |
$donnees = $this->getExportObservation();
|
270 |
aurelien |
286 |
$donnees_formatees = $this->formaterListeObservationPourExportJson($donnees);
|
249 |
aurelien |
287 |
|
246 |
aurelien |
288 |
$this->type_mime = 'application/json';
|
|
|
289 |
|
207 |
aurelien |
290 |
return $donnees_formatees;
|
|
|
291 |
}
|
|
|
292 |
|
270 |
aurelien |
293 |
public function formaterListeObservationPourExportJson($tableau_observations_infos) {
|
207 |
aurelien |
294 |
|
|
|
295 |
$gestionnaire_especes = new OdsEspece($this->config);
|
|
|
296 |
$gestionnaire_communes = new OdsCommune($this->config);
|
|
|
297 |
|
|
|
298 |
$especes = $gestionnaire_especes->getToutesEspeces();
|
|
|
299 |
$evenements = $this->obtenirValeursListeParAbreviation(self::ABBR_LISTE_EVENEMENTS);
|
249 |
aurelien |
300 |
$milieux = $this->obtenirValeursListeParAbreviation(self::ABBR_LISTE_MILIEUX);
|
207 |
aurelien |
301 |
|
|
|
302 |
$resultats_formates = array();
|
|
|
303 |
|
|
|
304 |
foreach($tableau_observations_infos as $observations_infos) {
|
|
|
305 |
|
|
|
306 |
$id_espece = $observations_infos['oi_ce_espece'];
|
278 |
aurelien |
307 |
if($id_espece == 0) {
|
|
|
308 |
continue;
|
|
|
309 |
}
|
207 |
aurelien |
310 |
$nom_espece = $especes[$id_espece]['nom_scientifique'];
|
|
|
311 |
|
|
|
312 |
$id_evenement = $observations_infos['oo_ce_evenement'];
|
|
|
313 |
$chaine_evenement = $evenements[$id_evenement]['ot_cle'];
|
|
|
314 |
|
|
|
315 |
$infos_evenement = $this->renvoyerInformationStadeAPartirChaineTriple($chaine_evenement);
|
|
|
316 |
|
|
|
317 |
$date_observation_formatee = date($this->config['appli']['format_date'], strtotime($observations_infos['oo_date']));
|
|
|
318 |
|
|
|
319 |
$id_observation = $observations_infos['oo_id_observation'];
|
|
|
320 |
$infos_formatees = array(
|
|
|
321 |
'date' => $date_observation_formatee,
|
|
|
322 |
'evenenement' => $infos_evenement['nom'],
|
|
|
323 |
'code_bbch' => $infos_evenement['numero'],
|
|
|
324 |
'nom_scientifique' => $nom_espece,
|
235 |
aurelien |
325 |
'id_espece' => $id_espece,
|
|
|
326 |
'participant' => $observations_infos['os_ce_participant']
|
207 |
aurelien |
327 |
);
|
|
|
328 |
|
|
|
329 |
$id_station = $observations_infos['oi_ce_station'];
|
|
|
330 |
|
|
|
331 |
if(!isset($resultats_formates[$id_station])) {
|
|
|
332 |
$resultats_formates[$id_station]['station'] = $observations_infos['os_nom'];
|
|
|
333 |
$resultats_formates[$id_station]['code_commune'] = $observations_infos['os_ce_commune'];
|
|
|
334 |
//$resultats_formates[$id_station]['nom_commune'] = $gestionnaire_communes->obtenirNomCommuneParCodeInsee($observations_infos['os_ce_commune']);
|
|
|
335 |
$resultats_formates[$id_station]['latitude'] = $observations_infos['os_latitude'];
|
|
|
336 |
$resultats_formates[$id_station]['longitude'] = $observations_infos['os_longitude'];
|
|
|
337 |
$resultats_formates[$id_station]['altitude'] = $observations_infos['os_altitude'];
|
278 |
aurelien |
338 |
if(isset($milieux[$observations_infos['os_ce_environnement']]['ot_valeur'])) {
|
|
|
339 |
$resultats_formates[$id_station]['milieu'] = $milieux[$observations_infos['os_ce_environnement']]['ot_valeur'];
|
|
|
340 |
} else {
|
|
|
341 |
$resultats_formates[$id_station]['milieu'] = '';
|
|
|
342 |
}
|
207 |
aurelien |
343 |
$resultats_formates[$id_station]['participant'] = $observations_infos['os_ce_participant'];
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
$resultats_formates[$id_station]['obs'][$id_observation] = $infos_formatees;
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
return $resultats_formates;
|
|
|
350 |
}
|
|
|
351 |
|
210 |
aurelien |
352 |
public function getFichierExportObservationCsv() {
|
|
|
353 |
|
|
|
354 |
$donnees = $this->getExportObservation();
|
270 |
aurelien |
355 |
$donnees_formatees = $this->formaterListeObservationPourExportCSV($donnees);
|
210 |
aurelien |
356 |
$chaine_csv = $this->convertirTableauAssocVersCSV($donnees_formatees);
|
207 |
aurelien |
357 |
|
210 |
aurelien |
358 |
$this->envoyerFichier($chaine_csv);
|
207 |
aurelien |
359 |
}
|
|
|
360 |
|
270 |
aurelien |
361 |
public function formaterListeObservationPourExportCSV($tableau_observations_infos) {
|
207 |
aurelien |
362 |
|
|
|
363 |
$gestionnaire_especes = new OdsEspece($this->config);
|
|
|
364 |
$gestionnaire_communes = new OdsCommune($this->config);
|
227 |
aurelien |
365 |
$gestionnaire_utilisateurs = new OdsUtilisateur($this->config);
|
207 |
aurelien |
366 |
|
|
|
367 |
$especes = $gestionnaire_especes->getToutesEspeces();
|
|
|
368 |
$evenements = $this->obtenirValeursListeParAbreviation(self::ABBR_LISTE_EVENEMENTS);
|
249 |
aurelien |
369 |
$milieux = $this->obtenirValeursListeParAbreviation(self::ABBR_LISTE_MILIEUX);
|
207 |
aurelien |
370 |
|
210 |
aurelien |
371 |
$codes_insee_communes = array();
|
|
|
372 |
|
207 |
aurelien |
373 |
$resultats_formates = array();
|
|
|
374 |
foreach($tableau_observations_infos as $observations_infos) {
|
|
|
375 |
|
|
|
376 |
$id_espece = $observations_infos['oi_ce_espece'];
|
|
|
377 |
$nom_espece = $especes[$id_espece]['nom_scientifique'];
|
|
|
378 |
|
|
|
379 |
$id_evenement = $observations_infos['oo_ce_evenement'];
|
|
|
380 |
$chaine_evenement = $evenements[$id_evenement]['ot_cle'];
|
|
|
381 |
|
|
|
382 |
$infos_evenement = $this->renvoyerInformationStadeAPartirChaineTriple($chaine_evenement);
|
|
|
383 |
|
|
|
384 |
$date_observation_formatee = date($this->config['appli']['format_date'], strtotime($observations_infos['oo_date']));
|
|
|
385 |
|
|
|
386 |
$id_observation = $observations_infos['oo_id_observation'];
|
281 |
aurelien |
387 |
$milieu = isset($milieux[$observations_infos['os_ce_environnement']]['ot_valeur']) ? $milieux[$observations_infos['os_ce_environnement']]['ot_valeur'] : '';
|
207 |
aurelien |
388 |
|
|
|
389 |
$infos_formatees = array(
|
|
|
390 |
'id_observation' => $id_observation,
|
|
|
391 |
'date' => $date_observation_formatee,
|
|
|
392 |
'evenenement' => $infos_evenement['nom'],
|
|
|
393 |
'code_bbch' => $infos_evenement['numero'],
|
|
|
394 |
'nom_scientifique' => $nom_espece,
|
|
|
395 |
'station' => $observations_infos['os_nom'],
|
|
|
396 |
'code_commune' => $observations_infos['os_ce_commune'],
|
210 |
aurelien |
397 |
'nom_commune' => '',
|
207 |
aurelien |
398 |
'latitude' => $observations_infos['os_latitude'],
|
|
|
399 |
'longitude' => $observations_infos['os_longitude'],
|
|
|
400 |
'altitude' => $observations_infos['os_altitude'],
|
281 |
aurelien |
401 |
'milieu' => $milieu,
|
227 |
aurelien |
402 |
'id_participant' => $observations_infos['os_ce_participant'],
|
|
|
403 |
'pseudo_participant' => '',
|
|
|
404 |
'mail_participant' => ''
|
207 |
aurelien |
405 |
);
|
|
|
406 |
|
|
|
407 |
$resultats_formates[] = $infos_formatees;
|
210 |
aurelien |
408 |
|
|
|
409 |
if(is_numeric($observations_infos['os_ce_commune'])) {
|
|
|
410 |
$codes_insee_communes[] = $observations_infos['os_ce_commune'];
|
|
|
411 |
}
|
207 |
aurelien |
412 |
}
|
281 |
aurelien |
413 |
|
210 |
aurelien |
414 |
$correspondance_codes_insee_noms = $gestionnaire_communes->obtenirTableauNomsCommunesParTableauCodesInsee($codes_insee_communes);
|
227 |
aurelien |
415 |
$correspondance_id_utilisateur = $gestionnaire_utilisateurs->getListeUtilisateurFormateeId();
|
210 |
aurelien |
416 |
|
|
|
417 |
foreach($resultats_formates as &$resultat) {
|
|
|
418 |
|
227 |
aurelien |
419 |
if(isset($correspondance_codes_insee_noms[$resultat['code_commune']]) && trim($correspondance_codes_insee_noms[$resultat['code_commune']]) != '') {
|
210 |
aurelien |
420 |
$resultat['nom_commune'] = $correspondance_codes_insee_noms[$resultat['code_commune']];
|
|
|
421 |
}
|
227 |
aurelien |
422 |
|
|
|
423 |
$resultat['pseudo_participant'] = $correspondance_id_utilisateur[$resultat['id_participant']]['name'];
|
|
|
424 |
$resultat['mail_participant'] = $correspondance_id_utilisateur[$resultat['id_participant']]['mail'];
|
210 |
aurelien |
425 |
}
|
|
|
426 |
|
207 |
aurelien |
427 |
return $resultats_formates;
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
public function convertirTableauAssocVersCSV($tableau) {
|
|
|
431 |
|
|
|
432 |
$csv = '';
|
|
|
433 |
$colonnes = array_keys($tableau[0]);
|
|
|
434 |
$csv .= implode(';',$colonnes).";\n";
|
|
|
435 |
|
|
|
436 |
foreach($tableau as $elements) {
|
281 |
aurelien |
437 |
$ligne = "";
|
|
|
438 |
// parcours des cases de chaque ligne nécessaire car si on utilise implode
|
|
|
439 |
// les valeurs vides ne sont pas prises et ça décale les colonnes
|
|
|
440 |
foreach ($elements as $element) {
|
|
|
441 |
$ligne .= '"'.$element.'";';
|
|
|
442 |
}
|
|
|
443 |
$csv .= $ligne."\n";
|
207 |
aurelien |
444 |
}
|
|
|
445 |
|
|
|
446 |
return $csv;
|
|
|
447 |
}
|
|
|
448 |
|
281 |
aurelien |
449 |
public function envoyerFichier($contenu, $nom = 'observations_export') {
|
207 |
aurelien |
450 |
|
281 |
aurelien |
451 |
$nom_fichier = $nom.".csv";
|
207 |
aurelien |
452 |
$chemin_fichier = $this->config['appli']['chemin_fichiers_temp'].'/'.$nom_fichier;
|
|
|
453 |
|
|
|
454 |
file_put_contents($chemin_fichier, $contenu);
|
|
|
455 |
|
|
|
456 |
$contenu = file_get_contents($chemin_fichier);
|
|
|
457 |
$taille_fichier = filesize($chemin_fichier);
|
|
|
458 |
|
|
|
459 |
unlink($chemin_fichier);
|
|
|
460 |
|
|
|
461 |
ini_set('zlib.output_compression','Off');
|
|
|
462 |
|
|
|
463 |
header('Pragma: public');
|
|
|
464 |
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
|
|
465 |
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
|
|
|
466 |
|
|
|
467 |
header('Content-Tranfer-Encoding: none');
|
|
|
468 |
|
|
|
469 |
header('Content-Type: application/octetstream; name="'.$nom_fichier.'"');
|
|
|
470 |
header('Content-Disposition: attachement; filename="'.$nom_fichier.'"');
|
|
|
471 |
|
|
|
472 |
header('Content-Length: '.$taille_fichier);
|
|
|
473 |
|
|
|
474 |
echo $contenu;
|
|
|
475 |
exit();
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
private function formaterInformationPourEnvoi($tableauinfos) {
|
|
|
479 |
|
|
|
480 |
}
|
|
|
481 |
}
|
|
|
482 |
?>
|