Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 1240 → Rev 1241

/trunk/services/modules/0.1/nvps/NomsVernaculaires.php
43,8 → 43,11
'limite' => 100
);
protected $champ_tri = 'code_langue';
protected $direction_tri = 'asc';
/**
* Vrai tri SQL
*/
protected $tri;
protected $tri_ordre = 'asc';
/**
* Indique les champs supplémentaires à retourner
93,6 → 96,9
case 'masque.nt' :
$this->ajouterFiltreMasque('num_taxon', $valeur);
break;
case 'masque.nn' :
$this->ajouterFiltreMasque('num_nom', $valeur);
break;
case 'masque.nv' :
$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
break;
105,6 → 111,9
case 'retour.format' :
$this->retour_format = $valeur;
break;
case 'retour.tri' :
$this->tri = $valeur;
break;
case 'navigation.depart' :
$this->limite_requete['depart'] = $valeur;
break;
128,7 → 137,7
}
 
public function ajouterFiltreMasque($nom_champ, $valeur) {
if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
if ($nom_champ == 'num_taxon' || $nom_champ == 'num_nom') { // si il s'agit d'un chiffre
$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
} else {
if ($this->recherche == 'floue') {
203,6 → 212,7
$requete = ' SELECT '.$this->formerRequeteChamp().
' FROM '.$this->table
.$this->formerRequeteCondition()
.'ORDER BY nom_vernaculaire ASC'
.$this->formerRequeteLimite();
return $requete;
}
298,7 → 308,7
}
}
}
if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
$resultat_json[$num] = $this->table_retour;
$this->table_retour = array();
}
372,7 → 382,6
$resultat_json[$tab['id']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
if ($this->retour_format == 'max') {
$resultat_json[$tab['id']]['num_taxon'] = $tab['num_taxon'];
$resultat_json[$tab['id']]['nom_retenu.code'] = $tab['num_taxon'];
$resultat_json[$tab['id']]['taxon'] = $tab['num_taxon'];
$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
$resultat_json[$tab['id']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
383,19 → 392,9
}
}
if ($this->retour_format == 'max') {
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
// fois et les attribuer aux noms car c'est beaucoup plus rapide
$noms_sci = $this->recupererNomTaxons();
foreach ($resultat_json as $num_nom => &$tab) {
$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
if($tab == null) {
unset($resultat_json[$num_nom]);
}
}
}
uasort($resultat_json, array($this,'trierLigneTableau'));
$table_retour_json['resultat'] = $resultat_json;
return $table_retour_json;
}
448,35 → 447,8
return $ligne_tableau_resultat;
}
private function trierLigneTableau($a, $b) {
$retour = 0;
if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
$retour = 0;
}
if($this->champ_tri == 'code_langue') {
if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
$retour = ($this->direction_tri == 'asc') ? -1 : 1;
} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
$retour = ($this->direction_tri == 'asc') ? 1 : -1;
} else {
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
}
} else {
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
}
return $retour;
}
 
private function comparerChaineSelonDirectionTri($a, $b) {
if($this->direction_tri == 'asc') {
return ($a < $b) ? -1 : 1;
} else {
return ($a > $b) ? -1 : 1;
}
}
// formatage de la reponse /id ss la forme
// id, nom_vernaculaire, attributions
// langue
500,7 → 472,7
}
}
if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
//if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
unset($this->table_retour['href']);
return $this->table_retour;
}
558,30 → 530,8
return $valeur;
}
 
public function afficherTaxons() {
$resultat = $this->recupererNomTaxons();
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
foreach ($langue as $num_nom=>$taxon) {
$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
if (isset($resultat[$num_tax])) {
$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
}
}
}
}
public function recupererNomTaxons() {
$taxons = array_unique($this->taxons);
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
$res = $this->consulterHref($url);
foreach ($res->resultat as $id=>$taxon) {
$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
}
return $resultat;
}
 
 
public function formaterNomsVernaculairesIdChamp($resultat) {
$this->table_retour['id'] = $this->ressources[0];
$champs = explode(' ', $this->ressources[1]);
/trunk/scripts/modules/nvps/nvps.ini
1,9 → 1,10
version = "2012"
dossierTsv = "{ref:dossierDonneesEflore}nvps/2012/"
version = "2017"
dossierTsv = "{ref:dossierDonneesEflore}nvps/2017/"
dossierSql = "{ref:dossierTsv}"
 
[tables]
nvps = "nvps_v{ref:version}"
bdtfx = "bdtfx_v4_01"
 
[fichiers]
structureSql = "nvps_v{ref:version}.sql"
/trunk/scripts/modules/nvps/Nvps.php
30,6 → 30,9
case 'chargerNvps' :
$this->chargerNvps();
break;
case 'ajouterNumTax' :
$this->ajouterNumTaxon();
break;
case 'supprimerTous' :
$this->supprimerTous();
break;
62,8 → 65,24
break;
}
}
$requete = "ALTER TABLE `nvps_v2017` ADD `num_taxon` INT(10) NOT NULL AFTER `notes`;";
echo "\n";
}
/**
* Ajoute le num_taxon
*/
private function ajouterNumTaxon() {
$table = Config::get('tables.nvps');
$referentiel = Config::get('tables.bdtfx');
$requete_struct = "ALTER TABLE ".$table." ADD `num_taxon` INT(10) NOT NULL AFTER `notes`;";
$this->getBdd()->requeter($requete_struct);
$requete ="UPDATE ".$table." n left join ".$referentiel." on ".$referentiel.".num_nom = n.num_nom SET `num_taxon`= num_taxonomique";
$this->getBdd()->requeter($requete);
}
 
private function ouvrirFichier($chemin) {
$fichierOuvert = false;
85,7 → 104,8
private function analyserFichier($fichierOuvert) {
$entetesCsv = explode("\t", trim(fgets($fichierOuvert)));
 
$donnees = array();
$donnees = array();
$i = 0;
while ($ligneCsv = fgets($fichierOuvert)) {
$champs = explode("\t", trim($ligneCsv));
if (count($champs) > 0) {
92,20 → 112,20
$infos = array();
foreach ($entetesCsv as $ordre => $champNom) {
$valeur = isset($champs[$ordre]) ? $champs[$ordre] : '';
$infos[$champNom] = $valeur;
$infos[$champNom] = $this->getBdd()->proteger($valeur);
}
$infos['id'] = $this->getIndexNomVernaculaire($infos['nom_vernaculaire']);
$donnees[] = $this->getBdd()->protegerTableau($infos);
}
$this->afficherAvancement("Analyse du fichier des noms vernaculaires");
$donnees[$i] = $infos; $i++;
if ($this->stopperLaBoucle()) {
break;
}
}
echo "\n";
 
return $donnees;
}
 
private function getIndexNomVernaculaire($nomVernaculaire) {
$indexCourrant = null;