Subversion Repositories Applications.referentiel

Rev

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

Rev 327 Rev 333
Line 195... Line 195...
195
	* /Recherche/Export/_
195
	* /Recherche/Export/_
196
	* ou les _ représentent dans l'ordre : référentiel, version, champs, filtre
196
	* ou les _ représentent dans l'ordre : référentiel, version, champs, filtre
197
	* Si un des paramètres est absent, il prendre la valeur *
197
	* Si un des paramètres est absent, il prendre la valeur *
198
	*/
198
	*/
199
	public function getElementExport($param) {
199
	public function getElementExport($param) {
200
		$colonnesOrdonnees = array("nn" => array("a.num_nom", "Numéro nomenclatural"),
-
 
201
						"nr" => array("a.num_nom_retenu", "Numéro nomenclatural du nom retenu"),
-
 
202
						"nt" => array("a.num_taxonomique", "Numéro taxonomique"),
-
 
203
						"cd" => array("a.cd_ref", "Numéro INPN"),
-
 
204
						"rg" => array("a.rang", "Code rang"),
-
 
205
						"fam" => array("a.famille", "Famille (APG III)"),
-
 
206
						"nsc" => array("concat(a.nom_sci,' ',a.auteur)", "Nom avec auteur"),
-
 
207
						"bibc" => array("concat(a.annee,' ',a.biblio_origine)", "Année et bibliographie"),
-
 
208
						"nsrc" => array("concat(b.nom_sci,' ',b.auteur) as nom_sci_retenu_complet", "Nom retenu avec auteur"),
-
 
209
						"nf" => array("a.nom_francais", "Nom français normalisé"),
-
 
210
						"extax" => array("if (a.exclure_taxref = 1, 0, 1)", "Présent dans Taxref"),
-
 
211
						"lien" => array("concat('http://www.tela-botanica.org/bdtfx-nn-',a.num_nom)", "Permalien"),
-
 
212
						"ntsup" => array("a.num_tax_sup", "Numéro nomenclatural rang supérieur"),
-
 
213
						"pre" => array("a.presence", "Répartition géographique"),
-
 
214
						"ns" => array("a.nom_sci", "Nom sans auteur"),
-
 
215
						"aut" => array("a.auteur", "Auteur"),
-
 
216
						"ann" => array("a.annee", "Année publication"),
-
 
217
						"bib" => array("a.biblio_origine", "Bibliographie"),
-
 
218
						"ntype" => array("a.num_type", "Numéro du type"),
-
 
219
						"nbas" => array("a.num_basionyme", "Numéro du basionyme"),
-
 
220
						"genre" => array("a.genre", "Genre"),
-
 
221
						"esp" => array("a.epithete_sp", "Epithète espèce"),
-
 
222
						"eing" => array("a.epithete_infra_generique", "Epithète infragénérique"),
-
 
223
						"te" => array("a.type_epithete", "Type d'épithète infraspécifique"),
-
 
224
						"einsp" => array("a.epithete_infra_sp", "Epithète infraspécifique"),
-
 
225
						"hybp01" => array("a.hybride_parent_01", "Hybride parent 1"),
-
 
226
						"nomsupgen" => array("a.nom_supra_generique", "Nom supra générique"),
-
 
227
						"hybp02" => array("a.hybride_parent_02", "Hybride parent 2"),
-
 
228
						"stori" => array("a.statut_origine", "Statut d'origine"),
-
 
229
						"stint" => array("a.statut_introduction", "Statut d'introduction"),
-
 
230
						"stcult" => array("a.statut_culture", "Statut de culture"),
-
 
231
						"notes" => array("a.notes", "Remarques"),
-
 
232
						"nomadd" => array("a.nom_addendum", "Commentaires nomenclaturaux"),
-
 
233
						"nsr" => array("b.nom_sci as nom_sci_retenu", "Nom retenu sans auteur"),
-
 
234
						"hom" => array("a.homonyme", "Homonymie"),
-
 
235
						"synprop" => array("a.synonyme_proparte", "Synonyme proprate"),
-
 
236
						"syndout" => array("a.synonyme_douteux", "Synonyme douteux"),
-
 
237
						"synmapp" => array("a.synonyme_mal_applique", "Synonyme mal appliqué"),
-
 
238
						"synorth" => array("a.synonyme_orthographique", "Synonyme orthographique"),
-
 
239
						"orthori" => array("a.orthographe_originelle", "Orthographe originelle"),
-
 
240
						"hybp01n" => array("a.hybride_parent_01_notes", "Hybride parent 1 notes"),
-
 
241
						"hybp02n" => array("a.hybride_parent_02_notes", "Hybride parent 2 notes"),
-
 
242
						"cultgp" => array("a.cultivar_groupe", "Groupe de cultivar"),
-
 
243
						"cult" => array("a.cultivar", "Nom cultivar"),
-
 
244
						"nomcomm" => array("a.nom_commercial", "Nom commercial"),
-
 
245
						"autres" => array("a.*", "Autres"));
-
 
246
		// Initialisation des variables
200
		// Initialisation des variables
247
		$info = array();
201
		$info = array();
248
		$p = $this->traiterParametresUrl(array("ref","version","champs","filtre"), $param, false);
202
		$p = $this->traiterParametresUrl(array("ref","version","champs","filtre"), $param, false);
249
		$ref = $p['ref'].'_v'.$p['version'];
203
		$ref = $p['ref'].'_v'.$p['version'];
250
		$racine_tmp = $this->config['chemins']['chemin_tmp'];
204
		$racine_tmp = $this->config['chemins']['chemin_tmp'];
251
		$dossier = $racine_tmp.date('Y_m_d').'/';
205
		$dossier = $racine_tmp.date('Y_m_d').'/';
252
		if(!is_dir($dossier)){
206
		if(!is_dir($dossier)){
253
			mkdir($dossier);
207
			mkdir($dossier);
254
		}
208
		}
255
		$fichier = $dossier.$ref."_".time().'.csv'; // à mettre en config
209
		$fichier = $dossier.$ref."_".time().'.csv'; 
256
		$colonnes = explode(",", $p['champs']);
-
 
257
		
-
 
258
		// recuperer colonne du ref pour vérifier que ces colonnes soient présentes + comptait nb colonnes pr autres
-
 
259
		foreach ($colonnes as $colonne) {
-
 
260
			$champs[] = $colonnesOrdonnees[$colonne][0];
210
		$champs = $this->formaterColonnes($p['champs'], $ref);
261
			$nom_champs[] = $colonnesOrdonnees[$colonne][1];
-
 
262
		}
-
 
263
		$requete = 'SELECT "'.implode('","', $nom_champs).'" UNION (SELECT '.implode(', ',$champs).
211
		$requete = 'SELECT "'.implode('","', $champs['titre']).'" UNION (SELECT '.implode(', ',$champs['select']).
264
			" INTO OUTFILE '".$fichier."' CHARACTER SET utf8 FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n' ". 
212
			" INTO OUTFILE '".$fichier."' CHARACTER SET utf8 FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n' ". 
265
		" FROM $ref a left join $ref b on b.num_nom=a.num_nom_retenu";
213
		" FROM $ref a left join $ref b on b.num_nom=a.num_nom_retenu";
266
		
214
 
267
		if (isset($p['filtre']) && $p['filtre'] != "*") {
215
		if (isset($p['filtre']) && $p['filtre'] != "*") {
268
			$param_filtres = explode(",",$p["filtre"]);
216
			$param_filtres = explode(",",$p["filtre"]);
269
			$dernier_filtre = array_pop($param_filtres);
217
			$dernier_filtre = array_pop($param_filtres);
270
			$filtres = array("nnr"=>"a.num_nom = a.num_nom_retenu", "pre" => "a.presence = 'P'");
218
			$filtres = array("nnr"=>"a.num_nom = a.num_nom_retenu", "pre" => "a.presence = 'P'");
271
			if (!isset($filtres[$dernier_filtre])) { // si il s'agit du filtre famille
219
			if (!isset($filtres[$dernier_filtre])) { // si il s'agit du filtre famille
Line 289... Line 237...
289
		}
237
		}
Line 290... Line 238...
290
	
238
	
291
		return $fichier;
239
		return $fichier;
Line -... Line 240...
-
 
240
	}
-
 
241
	
-
 
242
	private function formaterColonnes($colonnes, $ref) {
-
 
243
		$colonnesOrdonnees = array("nn" => array("a.num_nom", "num_nom", "Numéro nomenclatural"),
-
 
244
								"nr" => array("a.num_nom_retenu", "num_nom_retenu", "Numéro nomenclatural du nom retenu"),
-
 
245
								"nt" => array("a.num_taxonomique", "num_taxonomique", "Numéro taxonomique"),
-
 
246
								"cd" => array("a.cd_nom", "cd_nom", "Numéro INPN"),
-
 
247
								"rg" => array("a.rang", "rang", "Code rang"),
-
 
248
								"fam" => array("a.famille", "famille", "Famille (APG III)"),
-
 
249
								"nsc" => array("concat(a.nom_sci,' ',a.auteur)", "nom_sci", "Nom avec auteur"),
-
 
250
								"bibc" => array("concat(a.annee,' ',a.biblio_origine)", "annee", "Année et bibliographie"),
-
 
251
								"nsrc" => array("concat(b.nom_sci,' ',b.auteur) as nom_sci_retenu_complet", "auteur", "Nom retenu avec auteur"),
-
 
252
								"nf" => array("a.nom_francais", "nom_francais", "Nom français normalisé"),
-
 
253
								"extax" => array("if (a.exclure_taxref = 1, 0, 1)", "exclure_taxref", "Présent dans Taxref"),
-
 
254
								"lien" => array("concat('http://www.tela-botanica.org/bdtfx-nn-',a.num_nom)", "num_nom", "Permalien"),
-
 
255
								"ntsup" => array("a.num_tax_sup", "num_tax_sup", "Numéro nomenclatural rang supérieur"),
-
 
256
								"pre" => array("a.presence", "presence", "Répartition géographique"),
-
 
257
								"ns" => array("a.nom_sci", "nom_sci", "Nom sans auteur"),
-
 
258
								"aut" => array("a.auteur", "auteur", "Auteur"),
-
 
259
								"ann" => array("a.annee", "annee", "Année publication"),
-
 
260
								"bib" => array("a.biblio_origine", "biblio_origine", "Bibliographie"),
-
 
261
								"ntype" => array("a.num_type", "num_type", "Numéro du type"),
-
 
262
								"nbas" => array("a.num_basionyme", "num_basionyme", "Numéro du basionyme"),
-
 
263
								"genre" => array("a.genre", "genre", "Genre"),
-
 
264
								"esp" => array("a.epithete_sp", "epithete_sp", "Epithète espèce"),
-
 
265
								"eing" => array("a.epithete_infra_generique", "epithete_infra_generique", "Epithète infragénérique"),
-
 
266
								"te" => array("a.type_epithete", "type_epithete", "Type d'épithète infraspécifique"),
-
 
267
								"einsp" => array("a.epithete_infra_sp", "epithete_infra_sp", "Epithète infraspécifique"),
-
 
268
								"hybp01" => array("a.hybride_parent_01", "hybride_parent_01", "Hybride parent 1"),
-
 
269
								"nomsupgen" => array("a.nom_supra_generique", "nom_supra_generique", "Nom supra générique"),
-
 
270
								"hybp02" => array("a.hybride_parent_02", "hybride_parent_02", "Hybride parent 2"),
-
 
271
								"stori" => array("a.statut_origine", "statut_origine", "Statut d'origine"),
-
 
272
								"stint" => array("a.statut_introduction", "statut_introduction", "Statut d'introduction"),
-
 
273
								"stcult" => array("a.statut_culture", "statut_culture", "Statut de culture"),
-
 
274
								"notes" => array("a.notes", "notes", "Remarques"),
-
 
275
								"nomadd" => array("a.nom_addendum", "nom_addendum", "Commentaires nomenclaturaux"),
-
 
276
								"nsr" => array("b.nom_sci as nom_sci_retenu", "nom_sci", "Nom retenu sans auteur"),
-
 
277
								"hom" => array("a.homonyme", "homonyme", "Homonymie"),
-
 
278
								"synprop" => array("a.synonyme_proparte", "synonyme_proparte", "Synonyme proprate"),
-
 
279
								"syndout" => array("a.synonyme_douteux", "synonyme_douteux", "Synonyme douteux"),
-
 
280
								"synmapp" => array("a.synonyme_mal_applique", "synonyme_mal_applique", "Synonyme mal appliqué"),
-
 
281
								"synorth" => array("a.synonyme_orthographique", "synonyme_orthographique", "Synonyme orthographique"),
-
 
282
								"orthori" => array("a.orthographe_originelle", "orthographe_originelle", "Orthographe originelle"),
-
 
283
								"hybp01n" => array("a.hybride_parent_01_notes", "hybride_parent_01_notes", "Hybride parent 1 notes"),
-
 
284
								"hybp02n" => array("a.hybride_parent_02_notes", "hybride_parent_02_notes", "Hybride parent 2 notes"),
-
 
285
								"cultgp" => array("a.cultivar_groupe", "cultivar_groupe", "Groupe de cultivar"),
-
 
286
								"cult" => array("a.cultivar", "cultivar", "Nom cultivar"),
-
 
287
								"nomcomm" => array("a.nom_commercial", "nom_commercial", "Nom commercial"),
-
 
288
								"autres" => array("a.*", "*", "Autres"));
-
 
289
		$colonnes = explode(",", $colonnes);
-
 
290
		$requete = "SHOW COLUMNS FROM $ref";
-
 
291
		$colonnesTable = $this->bdd->query($requete)->fetchAll(PDO::FETCH_COLUMN, "Field");
-
 
292
		foreach ($colonnes as $colonne) {
-
 
293
			if ($colonne == "autres") {
-
 
294
				foreach ($colonnesOrdonnees as $colOrd) {
-
 
295
					$test[] = $colOrd[1];
-
 
296
				}
-
 
297
				$index = function($valeur) { return 'a.'.$valeur; };
-
 
298
				$titre = function($valeur) { return 'Autres : '.$valeur; };
-
 
299
				$colonneAutres = array_diff($colonnesTable, $test);
-
 
300
				$champs['select'] = array_merge($champs['select'], array_map($index, $colonneAutres));
-
 
301
				$champs['titre'] = array_merge($champs['titre'], array_map($titre, $colonneAutres));
-
 
302
			} else {
-
 
303
				if (array_search($colonnesOrdonnees[$colonne][1], $colonnesTable) != false) {
-
 
304
					$champs['select'][] = $colonnesOrdonnees[$colonne][0];
-
 
305
					$champs['titre'][] = $colonnesOrdonnees[$colonne][2];
-
 
306
				}
-
 
307
			}
-
 
308
		}
-
 
309
		return $champs;
-
 
310
	}
-
 
311
	
-
 
312
	private function ajouterIndexTable($valeur) {
-
 
313
		return 'a.'.$valeur;
292
	}
314
	}
293
	
315
	
294
	/**
316
	/**
295
	* Méthode principale appelée avec une requête de type POST.
317
	* Méthode principale appelée avec une requête de type POST.
296
	*/
318
	*/