Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 691 → Rev 692

/trunk/scripts/modules/nvps/Nvps.php
19,14 → 19,14
$this->initialiserProjet('nvps');
 
$cmd = $this->getParametre('a');
switch ($cmd) {
case 'chargerTous' :
$this->chargerStructureSql();
$this->chargerNvps();
break;
case 'chargerStructure' :
$this->chargerStructureSql();
break;
switch ($cmd) {
case 'chargerTous' :
$this->chargerStructureSql();
$this->chargerNvps();
break;
case 'chargerStructure' :
$this->chargerStructureSql();
break;
case 'chargerNvps' :
$this->chargerNvps();
break;
39,11 → 39,11
} catch (Exception $e) {
$this->traiterErreur($e->getMessage());
}
}
}
 
/**
* Charge le fichier en créant un id pour chaque nom vernaculaire.
*/
/**
* Charge le fichier en créant un id pour chaque nom vernaculaire.
*/
private function chargerNvps() {
//Debug::printr(Config::get('fichiers'));
$fichierOuvert = $this->ouvrirFichier(Config::get('chemins.nvps'));
50,7 → 50,11
$donnees = $this->analyserFichier($fichierOuvert);
fclose($fichierOuvert);
foreach ($donnees as $donnee) {
$requete = 'INSERT INTO '.Config::get('tables.nvps').' VALUES ('.implode(', ', $donnee).')';
$table = Config::get('tables.nvps');
$fields = implode(', ', array_keys($donnee));
$values = implode(', ', $donnee);
 
$requete = "INSERT INTO $table ($fields) VALUES ($values) ";
$this->getBdd()->requeter($requete);
 
$this->afficherAvancement("Insertion des noms vernaculaires dans la base de données");
61,18 → 65,37
echo "\n";
}
 
private function ouvrirFichier($chemin) {
$fichierOuvert = false;
if ($chemin) {
if (file_exists($chemin) === true) {
$fichierOuvert = fopen($chemin, 'r');
if ($fichierOuvert == false) {
throw new Exception("Le fichier $chemin n'a pas pu être ouvert.");
}
} else {
throw new Exception("Le fichier $chemin est introuvable.");
}
} else {
throw new Exception("Aucun chemin de fichier n'a été fourni.");
}
return $fichierOuvert;
}
 
private function analyserFichier($fichierOuvert) {
$entetesCsv = explode("\t", trim(fgets($fichierOuvert)));
 
$donnees = array();
$entetesCsv = fgets($fichierOuvert);
while ($ligneCsv = fgets($fichierOuvert)) {
$champs = explode("\t", trim($ligneCsv));
if (count($champs) > 0) {
if (isset($champs[2])) {
$nomVernaculaire = $champs[2];
$indexCourrant = $this->getIndexNomVernaculaire($nomVernaculaire);
$champs = array_merge(array($indexCourrant), $champs);
$donnees[] = $this->protegerValeursDesChamps($champs);
$infos = array();
foreach ($entetesCsv as $ordre => $champNom) {
$valeur = isset($champs[$ordre]) ? $champs[$ordre] : '';
$infos[$champNom] = $valeur;
}
$infos['id'] = $this->getIndexNomVernaculaire($infos['nom_vernaculaire']);
$donnees[] = $this->getBdd()->protegerTableau($infos);
}
$this->afficherAvancement("Analyse du fichier des noms vernaculaires");
if ($this->stopperLaBoucle()) {
80,6 → 103,7
}
}
echo "\n";
 
return $donnees;
}
 
92,34 → 116,6
return $indexCourrant;
}
 
private function ouvrirFichier($chemin) {
$fichierOuvert = false;
if ($chemin) {
if (file_exists($chemin) === true) {
$fichierOuvert = fopen($chemin, 'r');
if ($fichierOuvert == false) {
throw new Exception("Le fichier $chemin n'a pas pu être ouvert.");
}
} else {
throw new Exception("Le fichier $chemin est introuvable.");
}
} else {
throw new Exception("Aucun chemin de fichier n'a été fourni.");
}
return $fichierOuvert;
}
 
private function protegerValeursDesChamps($champs) {
$champsProteges = array();
for ($i = 0; $i < 9; $i++) {
$valeur = isset($champs[$i]) ? $champs[$i] : '';
$champsProteges[] = $this->getBdd()->proteger($valeur);
}
return $champsProteges;
}
 
 
 
private function supprimerTous() {
$requete = "DROP TABLE IF EXISTS nvps_meta, nvps_v2007, nvps_v2012";
$this->getBdd()->requeter($requete);