Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
/**
 * Création de la table osm_communes.
 * /opt/lampp/bin/php cli.php osm -a communes -m manuel
 *
 */
class FranceCommunes {

        private $conteneur;
        private $bdd;
        private $messages;
        private $mode;

        private $bddOsmNom;

        public function __construct($conteneur) {
                $this->conteneur = $conteneur;
                $this->bdd = $this->conteneur->getBdd();
                $this->bddOsmNom = $this->conteneur->getParametre('bdd_osm_nom');
                $this->messages = $this->conteneur->getMessages();
                $this->mode = $this->conteneur->getParametre('m');
        }

        public function executer() {
                // Lancement de l'action demandée
                $cmd = $this->conteneur->getParametre('a');
                switch ($cmd) {
                        case 'cm' :
                                $this->supprimerTableOsmCommunes();
                                $this->conteneur->getEfloreCommun()->chargerStructureSql();
                                $this->creerTableOsmCommunes();
                                break;
                        case 'cmCreer' :
                                $this->creerTableOsmCommunes();
                                break;
                        case 'cmSupprimer' :
                                $this->supprimerTableOsmCommunes();
                                break;
                        default :
                                $this->messages->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
                }

        }

        private function supprimerTableOsmCommunes() {
                $requete = 'DROP TABLE IF EXISTS osm_communes '.
                        ' -- '.__FILE__.' : '.__LINE__;
                $this->bdd->requeter($requete);
        }

        private function creerTableOsmCommunes() {
                $requete = 'INSERT INTO osm_communes '.
                        "SELECT osm_id, osm_version, osm_timestamp, name, ref_insee, shape, shape_centroid, wikipedia ".
                        "FROM {$this->bddOsmNom}.multipolygons_ref ".
                        "WHERE zone = 'france' AND admin_level = 8 ".
                        ' -- '.__FILE__.' : '.__LINE__;
                $this->bdd->requeter($requete);
        }
}