Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1056 jpm 1
<?php
2
/**
3
 * Création de la table osm_communes.
4
 * /opt/lampp/bin/php cli.php osm -a communes -m manuel
5
 *
6
 */
7
class FranceCommunes {
8
 
9
	private $conteneur;
10
	private $bdd;
11
	private $messages;
12
	private $mode;
13
 
14
	private $bddOsmNom;
15
 
16
	public function __construct($conteneur) {
17
		$this->conteneur = $conteneur;
18
		$this->bdd = $this->conteneur->getBdd();
19
		$this->bddOsmNom = $this->conteneur->getParametre('bdd_osm_nom');
20
		$this->messages = $this->conteneur->getMessages();
21
		$this->mode = $this->conteneur->getParametre('m');
22
	}
23
 
24
	public function executer() {
25
		// Lancement de l'action demandée
26
		$cmd = $this->conteneur->getParametre('a');
27
		switch ($cmd) {
28
			case 'cm' :
1060 jpm 29
				$this->supprimerTableOsmCommunes();
30
				$this->conteneur->getEfloreCommun()->chargerStructureSql();
1056 jpm 31
				$this->creerTableOsmCommunes();
32
				break;
1060 jpm 33
			case 'cmCreer' :
34
				$this->creerTableOsmCommunes();
35
				break;
1056 jpm 36
			case 'cmSupprimer' :
37
				$this->supprimerTableOsmCommunes();
38
				break;
39
			default :
40
				$this->messages->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
41
		}
42
 
43
	}
44
 
45
	private function supprimerTableOsmCommunes() {
46
		$requete = 'DROP TABLE IF EXISTS osm_communes '.
47
			' -- '.__FILE__.' : '.__LINE__;
48
		$this->bdd->requeter($requete);
49
	}
50
 
51
	private function creerTableOsmCommunes() {
52
		$requete = 'INSERT INTO osm_communes '.
53
			"SELECT osm_id, osm_version, osm_timestamp, name, ref_insee, shape, shape_centroid, wikipedia ".
54
			"FROM {$this->bddOsmNom}.multipolygons_ref ".
1061 jpm 55
			"WHERE admin_level = 8 ".
56
			"AND (ref_insee IS NOT NULL OR ref_insee != '') ".
57
			"AND CHAR_LENGTH(ref_insee) = 5 ".
1056 jpm 58
			' -- '.__FILE__.' : '.__LINE__;
59
		$this->bdd->requeter($requete);
60
	}
61
}