Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
/** Exemple lancement:
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php vigie_flore -a chargerTous
*/
class VigieFlore extends EfloreScript {

        public function executer() {
                // Lancement de l'action demandée
                try {
                        $this->initialiserProjet('vigie_flore');

                        $cmd = $this->getParametre('a');
                        switch ($cmd) {
                                case 'chargerTous' :
                                        $this->chargerStructureSql();
                                        $this->chargerDonnees();
                                        $this->genererVue();
                                        $this->ajouterOntologie();
                                        break;
                                case 'chargerStructureSql' :
                                        $this->chargerStructureSql();
                                        break;
                                case 'chargerDonnees' :
                                        $this->chargerDonnees();
                                        $this->genererVue();
                                        $this->ajouterOntologie();
                                        break;
                                case 'genererVue' :
                                        $this->genererVue();
                                        break;
                                case 'ajouterOntologie' :
                                        $this->ajouterOntologie();
                                        break;
                                case 'supprimerTous' :
                                        $this->supprimerTous();
                                        break;
                                default :
                                        throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
                        }
                } catch (Exception $e) {
                        $this->traiterErreur($e->getMessage());
                }
        }

        protected function chargerDonnees() {
                $chemin = Config::get('chemins.donnees');
                $table = Config::get('tables.donnees');
                $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 genererVue() {
                $referentielTaxo = Config::get('tables.referentielTaxo');
                $donnees = Config::get('tables.donnees');
                $requete = "CREATE VIEW vigie_flore_tapir AS 
                        SELECT '' as observation_id, b.nom_sci as nom_scientifique_complet, v.nom_sci as nom_sci, b.num_nom, 
                                 v.commune as lieu_commune_code_insee, v.latitude as lieu_station_latitude, v.longitude as lieu_station_longitude,
                                 ref_geo AS geodeticDatum, v.date as observation_date, observateur AS observateur_nom_complet
                                 FROM $referentielTaxo b, $donnees v
                                 WHERE b.cd_nom = v.num_tax_tax_ref
                                        AND b.num_nom = b.num_nom_retenu;";
                $this->getBdd()->requeter($requete);
        }
        

        private function ajouterOntologie() {
                $requete = "INSERT INTO `eflore_ontologies` (`id`, `classe_id`, `nom`, `description`, `code`, `complements`) VALUES
                                (25, 10, 'Vigie Flore', 'données issues du <a href=\"http://vigienature.mnhn.fr/flore/vigie-flore\" title=\"Vigie-Flore\" onclick=\"window.open(this.href); return false;\">programme Vigie-Flore</a>', 'VF', 'legende=#9527BA');";
                $this->getBdd()->requeter($requete);
        }
        
        private function supprimerTous() {
                $requete = "DROP TABLE IF EXISTS vigie_flore_v2015_03; DROP TABLE vigie_flore_tapir;";
                $this->getBdd()->requeter($requete);
                Debug::printr('suppression');
        }
}
?>