Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 522 | Rev 905 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/**
*
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
*
*
*/
class BaseflorIndex {
        
        private $conteneur;
        private $efloreCommun;
        private $message;
        private $dossierBase;
        private $valeurs_insertion = array();
        private $Bdd;
        
        public function __construct(Conteneur $conteneur, Bdd $Bdd) {
                $this->conteneur = $conteneur;
                $this->Bdd = $Bdd;
                $this->efloreCommun = $conteneur->getEfloreCommun();
                $this->message = $conteneur->getMessages();
                $this->dossierBase = dirname(__FILE__).'/';
        }
        
        
        public function insererDonnees(){
                $this->efloreCommun->chargerFichierSql('chemins.index_sql');
                $this->recupererDonneesBaseflor();
                $this->recupererDonneesRangSup();
                $this->insererDonneesIndex();
        }
        
        private function recupererDonneesBaseflor() {
                $table = Config::get('tables.donnees');
                $requete = "SELECT cle, num_nomen, BDNT FROM $table ;";
                $resultat = $this->Bdd->recupererTous($requete);
                $this->valeurs_insertion['baseflor'] = $resultat;
                $this->valeurs_insertion['rangSup'] = $resultat;
        }
        
        private function recupererDonneesRangSup() {
                $table = Config::get('tables.rang_sup');
                $requete = "SELECT cle, num_nomen, bdnt FROM $table ;";
                $resultat = $this->Bdd->recupererTous($requete);
                $this->valeurs_insertion['rangSup']= $resultat;

        }
        
        private function insererDonneesIndex() {
                $table = Config::get('tables.index');
                $requete_truncate = 'TRUNCATE TABLE '.$table;
                $this->Bdd->requeter($requete_truncate);
                $i = 0;
                foreach ($this->valeurs_insertion as $tab => $res){
                        if ($tab == 'baseflor') {
                                foreach ($res as  $valeurs ) {
                                        $requete = "INSERT INTO $table VALUES({$i},{$valeurs['cle']},null,'".strtolower($valeurs['BDNT']).".nn:{$valeurs['num_nomen']}')";
                                        $this->Bdd->requeter($requete);
                                        $i++;
                                        $this->message->afficherAvancement('Insertion des valeurs issues de baseflor en cours');
                                }
                        } else {
                                foreach ($res as  $valeurs ) {
                                        $requete = "INSERT INTO $table VALUES({$i},null,{$valeurs['cle']},'{$valeurs['bdnt']}.nn{$valeurs['num_nomen']}')";
                                        $this->Bdd->requeter($requete);
                                        $i++;
                                        $this->message->afficherAvancement('Insertion des valeurs issues des rangs supérieurs en cours');
                                }
                        }
                }
        }
        
}
?>