initialiserProjet('chorodep');
// Lancement de l'action demandée
$cmd = $this->getParametre('a');
switch ($cmd) {
case 'chargerTous' :
$this->chargerStructureSql();
$this->chargerVersions();
$this->chargerChorodepContributeurs();
$this->chargerChorodepSources();
$this->chargerChorodepOntologies();
break;
case 'chargerStructureSql' :
$this->chargerStructureSql();
break;
case 'chargerVersions' :
$this->chargerVersions();
break;
case 'chargerChorodep' :
$this->chargerChorodepContributeurs();
$this->chargerChorodepSources();
$this->chargerChorodepOntologies();
break;
case 'verifierDonnees' :
$this->initialiserTraitement();
$this->verifierDonnees();
break;
case 'supprimerTous' :
$this->supprimerTous();
break;
// noms vernaculaires et statuts de protection
case 'NVSP' :
$this->nettoyageNVSP();
$this->chargerStructureNVSP();
$this->rabouterNomsVernaculaires();
$this->rabouterStatutsProtection();
break;
case 'nettoyageNVSP' :
$this->nettoyageNVSP();
break;
case 'chargerStructureNVSP' :
$this->chargerStructureNVSP();
break;
case 'nomsVernaculaires' :
$this->rabouterNomsVernaculaires();
break;
case 'statutsProtection' :
$this->rabouterStatutsProtection();
break;
default :
throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
}
} catch (Exception $e) {
$this->traiterErreur($e->getMessage());
}
}
private function chargerChorodepContributeurs() {
$chemin = Config::get('chemins.chorodepContributeurs');
$table = Config::get('tables.chorodepContributeurs');
$requete = "LOAD DATA INFILE '$chemin' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY '\t' ".
" ENCLOSED BY '' ".
" ESCAPED BY '\\\' ".
'IGNORE 2 LINES';
$this->getBdd()->requeter($requete);
}
private function chargerChorodepSources() {
$chemin = Config::get('chemins.chorodepSources');
$table = Config::get('tables.chorodepSources');
$requete = "LOAD DATA INFILE '$chemin' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY '\t' ".
" ENCLOSED BY '' ".
" ESCAPED BY '\\\' ".
'IGNORE 2 LINES';
$this->getBdd()->requeter($requete);
}
private function chargerChorodepOntologies() {
$chemin = Config::get('chemins.chorodepOntologies');
$table = Config::get('tables.chorodepOntologies');
$requete = "LOAD DATA INFILE '$chemin' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY '\t' ".
" ENCLOSED BY '' ".
" ESCAPED BY '\\\' ".
'IGNORE 1 LINES';
$this->getBdd()->requeter($requete);
}
private function chargerVersions() {
$versions = explode(',', Config::get('versions'));
$versionsDonnees = explode(',', Config::get('versionsDonnees'));
foreach ($versions as $id => $version) {
$versionDonnees = $versionsDonnees[$id];
$this->chargerStructureSqlVersion($versionDonnees);
$this->chargerDonneesVersion($versionDonnees, $version);
}
}
private function chargerStructureSqlVersion($versionDonnees) {
$fichierSqlTpl = Config::get('chemins.structureSqlVersionTpl');
$fichierSql = sprintf($fichierSqlTpl, $versionDonnees, $versionDonnees);
$contenuSql = $this->recupererContenu($fichierSql);
$this->executerScripSql($contenuSql);
}
private function chargerDonneesVersion($versionDonnees, $version) {
$fichierTsvTpl = Config::get('chemins.chorodepTpl');
$fichierTsv = sprintf($fichierTsvTpl, $versionDonnees, $versionDonnees);
$tableTpl = Config::get('tables.chorodepTpl');
$table = sprintf($tableTpl, $version);
$champs = Config::get('chorodepChamps'.$version);
$requete = "LOAD DATA INFILE '$fichierTsv' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY '\t' ".
" ENCLOSED BY '' ".
" ESCAPED BY '\\\' ".
"($champs) ";
$this->getBdd()->requeter($requete);
}
private function initialiserTraitement() {
//------------------------------------------------------------------------------------------------------------//
// Récupération des informations à vérifier
$table = $this->getNomTableDerniereVersion();
$requete = 'SELECT * '.
"FROM $table ";
$taxons = $this->getBdd()->recupererTous($requete);
$tax_col = $taxons[1];
$col = array_keys($tax_col);
$this->initialiserTableaux($col);
//------------------------------------------------------------------------------------------------------------//
// Analyse des données
echo 'Traitement de la ligne n° :';
$i = 0;
$j = 0;
$aso_departements_analyses = array();
$this->nbre_ligne_avec_guillemet = 0;
foreach ($taxons as $aso_champs) {
$nom = $aso_champs['nom_sci'];
$num_taxo = $aso_champs['num_tax'];
$num_nomenc = $aso_champs['num_nom'];
if ($num_nomenc == 'nc') {
$this->nc_nbre_nom++;
} else if ($num_nomenc != 'nc') {
$this->nbre_nom++;
// Vérification de la nom duplication des numéros nomenclaturaux
if ( !array_key_exists($num_nomenc, (array) $this->aso_num_nomenc) ) {
$this->aso_num_nomenc[$num_nomenc]['compteur'] = 1;
$this->aso_num_nomenc[$num_nomenc]['ligne'] = ($this->nbre_ligne+1);
} else {
$this->aso_num_nomenc[$num_nomenc]['compteur']++;
$this->aso_num_nomenc[$num_nomenc]['ligne'] .= ' - '.($this->nbre_ligne+1);
}
}
foreach ($aso_champs as $cle => $val ) {# Pour chaque département du taxon, on regarde la valeur
$this->nbre_ligne_avec_guillemet += preg_match('/"/', $val);
if ( preg_match('/^\d{2}$/', $cle) ) {# Nous vérifions que le nom du champs comprend bien le numéro du département entre ()
$nd = $cle;# Numéro du département
// Nous comptons le nombre de département en base de données
if (!isset($aso_departements_analyses[$nd])) {
$this->nbre_dep_analyse++;
$aso_departements_analyses[$nd] = $nd;
}
if ( $num_nomenc != 'nc' && isset($val) && $val != '') {# Si le taxon n'est pas abscent du département
if ($val == '1') {# Présent
// Calcul du nombre de plante ayant un statut "Présent"
$this->nbre_plte_presente++;
// Stockage par département du nombre de plante ayant un statut "Présent"
$this->aso_totaux_dep[$nd]['plte_presente']++;
// Stockage des informations
$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 3, $this->id_donnee_choro++);
} else if ($val == '1?') {# Présence à confirmer
// Calcul du nombre de plante ayant un statut "Présence à confirmer"
$this->nbre_plte_a_confirmer++;
// Stockage par département du nombre de plante ayant un statut "Présence à confirmer"
$this->aso_totaux_dep[$nd]['plte_a_confirmer']++;
// Stockage des informations
$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 4, $this->id_donnee_choro++);
} else if (preg_match('/^\s*(?:\?)\s*$/', $val)) {# Douteux
// Calcul du nombre de plante ayant un statut "Disparu ou douteux"
$this->nbre_plte_douteux++;
// Stockage par département du nombre de plante ayant un statut "Douteux"
$this->aso_totaux_dep[$nd]['plte_douteux']++;
// Stockage des informations
$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 5, $this->id_donnee_choro++);
if (preg_match('/(?: \?|\? | \? )/', $val)) {# Douteux
// Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "?".
$this->autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} elseif (preg_match('/^\s*(?:#)\s*$/', $val)) {# Erreur
# Calcul du nombre de plante ayant un statut "Erreur"
$this->nbre_plte_erreur++;
# Stockage par département du nombre de plante ayant un statut "Erreur"
$this->aso_totaux_dep[$nd]['plte_erreur']++;
# Stockage des informations
$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 6, $this->id_donnee_choro++);
if (preg_match('/(?: #|# | # )/', $val)) {# Erreur avec espace
# Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#".
$autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} elseif (preg_match('/^\s*(?:-\|-)\s*$/', $val)) {# Disparu
# Calcul du nombre de plante ayant un statut "Disparu"
$this->nbre_plte_disparue++;
# Stockage par département du nombre de plante ayant un statut "Disparu"
$this->aso_totaux_dep[$nd]['plte_disparue']++;
# Stockage des informations
$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 6, $this->id_donnee_choro++);
if (preg_match('/(?: -\|-|-\|- | -\|- )/', $val)) {# Disparu avec espace
# Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "-|-".
$autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} elseif (preg_match('/^\s*(?:#\?)\s*$/', $val)) {# Erreur à confirmer
# Calcul du nombre de plante ayant un statut "Erreur à confirmer"
$this->nbre_plte_erreur_a_confirmer++;
# Stockage par département du nombre de plante ayant un statut "Erreur à confirmer"
$this->aso_totaux_dep[$nd]['plte_erreur_a_confirmer']++;
# Stockage des informations
$this->tab_choro_dep[$j] = array(ZgFrDepartements::getIdChaine($nd), $num_taxo, $num_nomenc, 6, $this->id_donnee_choro++);
if (preg_match('/^(?:\s+#\?|#\?\s+|\s+#\?\s+)$/', $val)) {# Erreur à confirmer avec espace
# Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#?".
$autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} else {
// Ajout de la valeur dans une variable car elle n'est pas conforme.
$this->autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
$j++;
} else if (isset($val) && $val != '') {
if ($val == '1') {# Présent
// Calcul du nombre de plante 'nc' ayant un statut "Présent"
$this->nc_nbre_plte_presente++;
// Stockage par département du nombre de plante 'nc' ayant un statut "Présent"
$this->aso_totaux_dep[$nd]['nc_plte_presente']++;
} elseif ($val == '1?') {# Présence à confirmer
// Calcul du nombre de plante 'nc' ayant un statut "Présence à confirmer"
$this->nc_nbre_plte_a_confirmer++;
// Stockage par département du nombre de plante 'nc' ayant un statut "Présence à confirmer"
$this->aso_totaux_dep[$nd]['nc_plte_a_confirmer']++;
} elseif (preg_match('/^(?:\?| \?|\? | \?)$/', $val)) {# Douteux
// Calcul du nombre de plante 'nc' ayant un statut "Douteux"
$this->nc_nbre_plte_douteux++;
// Stockage par département du nombre de plante 'nc' ayant un statut "Douteux"
$this->aso_totaux_dep[$nd]['nc_plte_douteux']++;
if (preg_match('/(?: \?|\? | \? )/', $val)) {# Douteux
// Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "?".
$this->nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} elseif (preg_match('/^(?:#| #|# | # )$/', $val)) {# Erreur
# Calcul du nombre de plante 'nc' ayant un statut "Erreur"
$this->nc_nbre_plte_erreur++;
# Stockage par département du nombre de plante 'nc' ayant un statut "Erreur"
$this->aso_totaux_dep[$nd]['nc_plte_erreur']++;
if (preg_match('/(?: #|# | # )/', $val)) {# Erreur avec espace
# Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#".
$nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} elseif (preg_match('/^\s*(?:-\|-)\s*$/', $val)) {# Disparu
# Calcul du nombre de plante 'nc' ayant un statut "Disparu"
$this->nc_nbre_plte_disparue++;
# Stockage par département du nombre de plante 'nc' ayant un statut "Disparu"
$this->aso_totaux_dep[$nd]['nc_plte_disparue']++;
if (preg_match('/(?: -\|-|-\|- | -\|- )/', $val)) {# Disparu avec espace
# Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "-|-".
$nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} elseif (preg_match('/^\s*(?:#\?)\s*$/', $val)) {# Erreur à confirmer
# Calcul du nombre de plante 'nc' ayant un statut "Erreur à confirmer"
$this->nc_nbre_plte_erreur_a_confirmer++;
# Stockage par département du nombre de plante 'nc' ayant un statut "Erreur à confirmer"
$this->aso_totaux_dep[$nd]['nc_plte_erreur_a_confirmer']++;
if (preg_match('/^(?:\s+#\?|#\?\s+|\s+#\?\s+)$/', $val)) {# Erreur à confirmer avec espace
# Ajout de la valeur dans une variable car elle n'est pas tout à fait conforme à "#?".
$nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
} else {
// Ajout de la valeur dans une variable car elle n'est pas conforme.
$this->nc_autres_valeur_champ .= '<'.$val.'> '.'(Ligne n°: '.($this->nbre_ligne+2).
' - N° nomenclatural: '.$num_nomenc.' - N° département: '.$nd.')
';
}
}
// Affichage dans la console du numéro de l'enregistrement analysé.
//echo str_repeat(chr(8), ( strlen( $i ) + 1 ))."\t".$i++;
}
}// fin du foreach
// Affichage dans la console du numéro de l'enregistrement analysé.
echo str_repeat(chr(8), ( strlen( $this->nbre_ligne ) + 1 ))."\t".$this->nbre_ligne++;
}
echo "\n";
}
private function initialiserTableaux($dep) {
foreach ($dep as $code_dep) {
if ( preg_match('/^\d{2}$/', $code_dep) ) {
$this->aso_totaux_dep[$code_dep]['plte_presente'] = 0;
$this->aso_totaux_dep[$code_dep]['plte_a_confirmer'] = 0;
$this->aso_totaux_dep[$code_dep]['plte_douteux'] = 0;
$this->aso_totaux_dep[$code_dep]['plte_erreur'] = 0;
$this->aso_totaux_dep[$code_dep]['plte_disparue'] = 0;
$this->aso_totaux_dep[$code_dep]['plte_erreur_a_confirmer'] = 0;
$this->aso_totaux_dep[$code_dep]['autres_valeur_champ'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_plte_presente'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_plte_a_confirmer'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_plte_douteux'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_plte_erreur'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_plte_disparue'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_plte_erreur_a_confirmer'] = 0;
$this->aso_totaux_dep[$code_dep]['nc_autres_valeur_champ'] = 0;
}
}
}
private function verifierDonnees() {
// Ouverture du fichier contenant les résultats (sortie)
if (!$handle = fopen($this->fichier_verif, 'w')) {
echo "Impossible d'ouvrir le fichier ($this->fichier_verif)";
exit;
}
// Création de la page
$page = ''."\n";
$page .= '
'.
'Adresse fichier analysé : '.'
'."\n".
'
'.
'Nom du programme générant ce fichier : '.__FILE__.'
'."\n".
'Nombre de lignes analysées : '.$this->nbre_ligne.'
'."\n".
'Nbre de départements analysés : '.$this->nbre_dep_analyse.'
'."\n".
'Date d\'exécution du programme : '.date('d.m.Y').'
'."\n".
'
'.
'Nombre de nom "nc" : '.$this->nc_nbre_nom.'
'."\n".
'Nombre de nom : '.$this->nbre_nom.'
'."\n".
'Valeurs autres que 1, 1?, ?, #, #? et -|- : '.$this->autres_valeur_champ.'
'."\n".
'Valeurs autres que 1, 1?, ?, #, #? et -|- pour les plantes nc :
'."\n".$this->nc_autres_valeur_champ.''."\n".
'
'.
'Nombre de guillemets antislashés: '.$this->nbre_ligne_avec_guillemet.'
'."\n".
'
Tableau des numéros nomenclaturaux dupliqués | ||
---|---|---|
Numéro nomenclatural | Nbre d\'itération | Lignes |
'.$cle_nomenc.' | '.$val['compteur'].' | '.$val['ligne'].' |
Tableau des résulats par départements | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Département | Nbre pltes présentes | Nbre pltes à confirmer | '. 'Nbre pltes douteuses | Nbre pltes disparues | Nbre pltes erreur | Nbre pltes erreur à confirmer | '. 'Total | Nbre pltes nc présentes | Nbre pltes nc à confirmer | '. 'Nbre nc pltes douteuses | Nbre nc pltes disparues | Nbre nc pltes erreur | Nbre nc pltes erreur à confirmer |
'.ZgFrDepartements::getNom($cle_dep).' ('.ZgFrDepartements::getIdChaine($cle_dep).') | '. ''.$val{'plte_presente'}.' | '.$val{'plte_a_confirmer'}.' | '.$val{'plte_douteux'}.' | '. ''.$val{'plte_disparue'}.' | '.$val{'plte_erreur'}.' | '.$val{'plte_erreur_a_confirmer'}.' | '.$plt_total.' | '. ''.$val{'nc_plte_presente'}.' | '.$val{'nc_plte_a_confirmer'}.' | '.$val{'nc_plte_douteux'}.' | '. ''.$val{'nc_plte_disparue'}.' | '.$val{'nc_plte_erreur'}.' | '.$val{'nc_plte_erreur_a_confirmer'}.' |
'. ' | |||||||||||||
Totaux : '.$this->nbre_dep_analyse.' départements | '.$this->nbre_plte_presente.' | '. ''.$this->nbre_plte_a_confirmer.' | '.$this->nbre_plte_douteux.' | '.$this->nbre_plte_disparue.' | '. ''.$this->nbre_plte_erreur.' | '.$this->nbre_plte_erreur_a_confirmer.' | '.$plt_total.' | '. ''.$this->nc_nbre_plte_presente.' | '.''.$this->nc_nbre_plte_a_confirmer.' | '. ''.$this->nc_nbre_plte_douteux.' | '.$this->nc_nbre_plte_disparue.' | '.$this->nc_nbre_plte_erreur.' | '.$this->nc_nbre_plte_erreur_a_confirmer.' |
'. ' | |||||||||||||
Totaux plante / plante nc | '.$total_nbre_plte.' | '. ''.$total_nbre_plte_nc.' | |||||||||||
'. ' | |||||||||||||
Total plantes présentes et à confirmer | '.$plt_total.' | ||||||||||||
'. ' | |||||||||||||
Total plantes présentes | '.$plt_total.' | ||||||||||||
'. ' | |||||||||||||
Total données chorologiques | '.$plt_total.' |
'. '1.- Chaque champ précédé par "ATTENTION" doit être vide.'."\n". 'S\'il ne l\'est pas, il y a une erreur'."\n". '
'."\n"; $page .= ''."\n"; $page .= ''."\n"; // Fermeture de la poignée sur le fichier de sortie if (fwrite($handle, $page) === FALSE) { echo "Impossible d'écrire dans le fichier ($this->fichier_verif)"; exit; } echo 'Ecriture du fichier de vérification de la chorologie réalisée!'."\n"; fclose($handle); } private function supprimerTous() { $tablesChorodep = implode(',', $this->getNomsTablesChorodep()); $tableContributeurs = Config::get('tables.chorodepContributeurs'); $tableSources = Config::get('tables.chorodepSources'); $tableOntologies = Config::get('tables.chorodepOntologies'); $requete = "DROP TABLE IF EXISTS chorodep_meta, $tablesChorodep, $tableContributeurs, $tableSources, $tableOntologies "; $this->getBdd()->requeter($requete); } private function getNomsTablesChorodep() { $versions = explode(',', Config::get('versions')); $tableTpl = Config::get('tables.chorodepTpl'); $tablesChorodep = array(); foreach ($versions as $version) { $tablesChorodep[] = sprintf($tableTpl, $version); } return $tablesChorodep; } private function getNomTableDerniereVersion() { $version = $this->getDerniereVersion(); $table = sprintf(Config::get('tables.chorodepTpl'), $version); return $table; } private function getDerniereVersion() { $version = array_pop(explode(',', Config::get('versions'))); return $version; } // ---------- // intégration des noms vernaculaires et statuts de protection (NVSP) dans // une table dédiée, pour permettre le service intégratif de l'applciation "chorologie" // (basé sur les scripts de "gentiana-services") // ---------- /** * Dézingue tout le bousin * @TODO chaque méthode devrait s'autonettoyer au début afin d'être répétable * sans avoir à tout reprendre depuis le début (principe du dump) */ protected function nettoyageNVSP() { echo "---- suppression des tables\n"; $tableStatutsProtection = Config::get('tables.statuts_protection'); $tableNomsVernaculaires = Config::get('tables.noms_vernaculaires'); $req = "DROP TABLE IF EXISTS `" . $tableStatutsProtection . "`"; $this->getBdd()->requeter($req); $req = "DROP TABLE IF EXISTS `" . $tableNomsVernaculaires . "`;"; $this->getBdd()->requeter($req); } /** * Crée les tables vides */ protected function chargerStructureNVSP() { echo "---- création des tables\n"; $contenuSql = $this->recupererContenu(Config::get('chemins.structureNVSP')); $this->executerScripSql($contenuSql); } /** * Va chercher les noms vernaculaires pour chaque espèce, et les rajoute * dans la table dédiée */ protected function rabouterNomsVernaculaires() { $tableNomsVernaculaires = Config::get('tables.noms_vernaculaires'); restore_error_handler(); restore_exception_handler(); ini_set("display_errors", true); error_reporting(E_ALL); $squeletteUrlNvjfl = Config::get("url_nvjfl"); echo "---- récupération des noms vernaculaires depuis eFlore\n"; $depart = 0; $nbInsertions = 0; $yenaencore = true; $tailleTranche = 1000; while ($yenaencore) { $url = sprintf($squeletteUrlNvjfl, $depart, $tailleTranche); $noms = $this->chargerDonnees($url); // Si quelqu'un parvient à dédoublonner les $valeurs, on enlève le IGNORE $req = "INSERT IGNORE INTO " . $tableNomsVernaculaires . " VALUES "; $valeurs = array(); // insertion des données foreach ($noms['resultat'] as $res) { $numTaxons = explode(',', $res['num_taxon']); $nvP = $this->getBdd()->proteger($res['nom']); foreach ($numTaxons as $numTaxon) { $valeurs[] = "(" . $numTaxon . ", " . $nvP . ")"; } } $req .= implode(",", $valeurs); $this->getBdd()->executer($req); // prochain tour $nbInsertions += count($valeurs); // Faux car INSERT IGNORE - dédoublonner ou compter les insertions réelles $depart += $tailleTranche; $total = $noms['entete']['total']; $yenaencore = $depart <= $total; echo "insérés: " . min($depart, $total) . " noms, " . $nbInsertions . " attributions\n"; } } /** * Va chercher les statuts de protection pour chaque espèce et les rajoute * à la table; importe un fichier dump SQL des lois */ protected function rabouterStatutsProtection() { $tableChorologie = $this->getNomTableDerniereVersion(); $tableStatutsProtection = Config::get('tables.statuts_protection'); echo "---- récupération des statuts de protection depuis eFlore\n"; $req = "SELECT distinct num_nom FROM " . $tableChorologie; $resultat = $this->getBdd()->recupererTous($req); // pour chaque taxon mentionné (inefficace mais évite d'implémenter un // mode liste sur le service eflore/sptb $squeletteUrlSptb = Config::get("url_sptb"); foreach ($resultat as $res) { $nn = $res['num_nom']; //echo "NN: $nn\n"; if ($nn != 0) { $url = sprintf($squeletteUrlSptb, $nn); //echo "URL: $url\n"; $statuts = $this->chargerDonnees($url); //echo "STATUTS: " . print_r($statuts, true) . "\n"; if (count($statuts) > 0) { $json = array(); foreach ($statuts as $statut) { $nouveauStatut = array(); $nouveauStatut['zone'] = $statut['code_zone_application']; $nouveauStatut['lien'] = $statut['hyperlien_legifrance']; $json[] = $nouveauStatut; } // Si au moins un statut if (count($json) > 0) { $json = json_encode($json); //echo "JSON: " . print_r($json, true) . "\n"; // Insertion d'un bout de JSON $jsonP = $this->getBdd()->proteger($json); $nnP = $this->getBdd()->proteger($nn); $reqIns = "INSERT INTO " . $tableStatutsProtection . " values($nnP, $jsonP)"; //echo "ReqIns: $reqIns\n"; $this->getBdd()->executer($reqIns); } } } } } } class ZgFrDepartements { static private $departements = array( "01" => array("Ain", "01", 1), "02" => array("Aisne", "02", 2), "03" => array("Allier", "03", 3), "04" => array("Alpes-de-Haute-Provence", "04", 4), "05" => array("Hautes-Alpes", "05", 5), "06" => array("Alpes-Maritimes", "06", 6), "07" => array("Ardèche", "07", 7), "08" => array("Ardennes", "08", 8), "09" => array("Ariège", "09", 9), "10" => array("Aube", "10", 10), "11" => array("Aude", "11", 11), "12" => array("Aveyron", "12", 12), "13" => array("Bouches-du-Rhône", "13", 13), "14" => array("Calvados", "14", 14), "15" => array("Cantal", "15", 15), "16" => array("Charente", "16", 16), "17" => array("Charente-Maritime", "17", 17), "18" => array("Cher", "18", 18), "19" => array("Corrèze", "19", 19), "20" => array("Corse", "20", 20), "2A" => array("Haute-Corse", "2A", 20), "2B" => array("Corse-du-Sud", "2B", 20), "21" => array("Côte-d'Or", "21", 21), "22" => array("Côtes-d'Armor", "22", 22), "23" => array("Creuse", "23", 23), "24" => array("Dordogne", "24", 24), "25" => array("Doubs","25", 25), "26" => array("Drôme", "26", 26), "27" => array("Eure", "27", 27), "28" => array("Eure-et-Loir", "28", 28), "29" => array("Finistère", "29", 29), "30" => array("Gard", "30", 30), "31" => array("Haute-Garonne", "31", 31), "32" => array("Gers", "32", 32), "33" => array("Gironde", "33", 33), "34" => array("Hérault", "34", 34), "35" => array("Ille-et-Vilaine", "35", 35), "36" => array("Indre", "36", 36), "37" => array("Indre-et-Loire", "37", 37), "38" => array("Isère", "38", 38), "39" => array("Jura", "39", 39), "40" => array("Landes", "40", 40), "41" => array("Loir-et-Cher", "41", 41), "42" => array("Loire", "42", 42), "43" => array("Haute-Loire", "43", 43), "44" => array("Loire-Atlantique", "44", 44), "45" => array("Loiret", "45", 45), "46" => array("Lot", "46", 46), "47" => array("Lot-et-Garonne", "47", 47), "48" => array("Lozére ", "48", 48), "49" => array("Maine-et-Loire", "49", 49), "50" => array("Manche", "50", 50), "51" => array("Marne", "51", 51), "52" => array("Haute-Marne", "52", 52), "53" => array("Mayenne", "53", 53), "54" => array("Meurthe-et-Moselle", "54", 54), "55" => array("Meuse", "55", 55), "56" => array("Morbihan", "56", 56), "57" => array("Moselle", "57", 57), "58" => array("Nièvre", "58", 58), "59" => array("Nord", "59", 59), "60" => array("Oise", "60", 60), "61" => array("Orne", "61", 61), "62" => array("Pas-de-Calais", "62", 62), "63" => array("Puy-de-Dôme", "63", 63), "64" => array("Pyrénées-Atlantiques", "64", 64), "65" => array("Hautes-Pyrénées", "65", 65), "66" => array("Pyrénées-Orientales", "66", 66), "67" => array("Bas-Rhin", "67", 67), "68" => array("Haut-Rhin", "68", 68), "69" => array("Rhône", "69", 69), "70" => array("Haute-Saône", "70", 70), "71" => array("Saône-et-Loire", "71", 71), "72" => array("Sarthe", "72", 72), "73" => array("Savoie", "73", 73), "74" => array("Haute-Savoie", "74", 74), "75" => array("Paris", "75", 75), "76" => array("Seine-Maritime", "76", 76), "77" => array("Seine-et-Marne", "77", 77), "78" => array("Yvelines", "78", 78), "79" => array("Deux-Sèvres", "79", 79), "80" => array("Somme", "80", 80), "81" => array("Tarn", "81", 81), "82" => array("Tarn-et-Garonne", "82", 82), "83" => array("Var", "83", 83), "84" => array("Vaucluse", "84", 84), "85" => array("Vendée", "85", 85), "86" => array("Vienne", "86", 86), "87" => array("Haute-Vienne", "87", 87), "88" => array("Vosges", "88", 88), "89" => array("Yonne", "89", 89), "90" => array("Territoire-de-Belfort", "90", 90), "91" => array("Essonne", "91", 91), "92" => array("Hauts-de-Seine", "92", 92), "93" => array("Seine-Saint-Denis", "93", 93), "94" => array("Val-de-Marne", "94", 94), "95" => array("Val-d'Oise", "95", 95), "96" => array("aaa", "96", 96), "971" => array("Guadeloupe", "971", 971), "972" => array("Martinique", "972", 972), "973" => array("Guyane", "973", 973), "974" => array("Réunion", "974", 974), "99" => array("Etranger", "99", 99), ); static public function get() { return self::$departements; } static public function getNom($n) { return self::$departements[$n][0]; } static public function getIdChaine($n) { return self::$departements[$n][1]; } static public function getIdNumerique($n) { return (int)self::$departements[$n][2]; } static public function getIdEflore($n) { return (int)self::$departements[$n][3]; } } ?>