Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1047 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1047 Rev 1055
Line 12... Line 12...
12
	private $conteneur;
12
	private $conteneur;
13
	private $bdd;
13
	private $bdd;
14
	private $messages;
14
	private $messages;
15
	private $mode;
15
	private $mode;
Line -... Line 16...
-
 
16
 
16
 
17
	private $premierNoeudPolygon = null;
17
	private $infosRel = array();
18
	private $infosRel = array();
18
	private $infosNoeuds = array();
19
	private $infosNoeuds = array();
19
	private $idRelation = null;
20
	private $idRelation = null;
20
	private $idChemin = null;
21
	private $idChemin = null;
Line 37... Line 38...
37
			// Traitement de la relation courante
38
			// Traitement de la relation courante
38
			$this->idRelation = $relation['id_relation'];
39
			$this->idRelation = $relation['id_relation'];
Line 39... Line 40...
39
 
40
 
Line 40... Line 41...
40
			$this->chargerDonneesRelationActuelle();
41
			$this->chargerDonneesRelationActuelle();
41
 
42
 
42
			// Selection du premier chemin comme chemin actuel
43
			$numPolygon = 1;
43
			$this->idChemin = $this->getIdPremierChemin();
-
 
44
			$this->mettreAJourChemin('directe', __LINE__);
44
			while(count($this->chemins) > 0) {
45
 
45
				reset($this->chemins);
46
			// Selection du dernier noeud comme noeud actuel
46
				$idChemin = key($this->chemins);
47
			$idDernierNoeud = $this->getIdDernierNoeud();
47
				echo "--------------POLY : $numPolygon : $idChemin\n";
48
			if ($idDernierNoeud) {
48
				$this->ordonnerCheminsRelation($numPolygon, $idChemin);
49
				$this->idNoeud = $idDernierNoeud;
49
				$this->mettreAJourRelationAChemin();
Line 50... Line 50...
50
				$this->ordonnerChemins();
50
				$numPolygon++;
51
			}
51
			}
52
 
52
 
Line 58... Line 58...
58
	}
58
	}
Line 59... Line 59...
59
 
59
 
60
	private function getToutesRelationsAChemins() {
60
	private function getToutesRelationsAChemins() {
61
		$requete = 'SELECT DISTINCT id_relation '.
61
		$requete = 'SELECT DISTINCT id_relation '.
-
 
62
			'FROM osm_relation_a_chemins '.
62
			'FROM osm_relation_a_chemins '.
63
			'WHERE id_relation = 403823 '.
63
			' -- '.__FILE__.' : '.__LINE__;
64
			' -- '.__FILE__.' : '.__LINE__;
64
		$relations = $this->bdd->recupererTous($requete);
65
		$relations = $this->bdd->recupererTous($requete);
65
		return $relations;
66
		return $relations;
Line 66... Line 67...
66
	}
67
	}
67
 
68
 
68
	private function chargerDonneesRelationActuelle() {
69
	private function chargerDonneesRelationActuelle() {
69
		$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '.
70
		$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '.
70
			'FROM osm_relation_a_chemins AS rc '.
71
			'FROM osm_relation_a_chemins AS rc '.
71
			'	INNER JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '.
72
			'	INNER JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '.
72
			"WHERE rc.id_relation = {$this->idRelation} ".
73
			"WHERE rc.id_relation = {$this->idRelation} ".
73
			"ORDER BY cn.ordre ASC ".
74
			"ORDER BY rc.ordre ASC, cn.ordre ASC ".
-
 
75
			' -- '.__FILE__.' : '.__LINE__;
74
			' -- '.__FILE__.' : '.__LINE__;
76
		$infos = $this->bdd->recupererTous($requete);
75
		$infos = $this->bdd->recupererTous($requete);
77
		$noeuds = array();
76
		foreach ($infos as $info) {
78
		foreach ($infos as $info) {
-
 
79
			$noeuds[$info['id_noeud']][$info['id_chemin']] = $info['ordre'];
-
 
80
			if (! isset($this->chemins[$info['id_chemin']]) ) {
77
			$this->infosRel[$info['id_chemin']][$info['id_noeud']] = $info['ordre'];
81
				$this->chemins[$info['id_chemin']]['max'] == info['ordre'];
-
 
82
				if ($info['ordre'] == 1) {
78
			if (! isset($this->infosNoeuds[$info['id_noeud']][$info['id_chemin']])) {
83
					$this->chemins[$info['id_chemin']][0] == $info['id_noeud'];
-
 
84
				}
-
 
85
			} else {
-
 
86
 
-
 
87
			}
-
 
88
			if (count($noeuds[$info['id_noeud']]) == 2) {
-
 
89
				list($premierChemin, $dernierChemin) = array_keys($noeuds[$info['id_noeud']]);
-
 
90
				$this->chemins[$premierChemin][] = $info['id_noeud'];
79
				$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']] = 1;
91
				$this->chemins[$dernierChemin][] = $info['id_noeud'];
80
			} else {
92
				$this->noeuds[$info['id_noeud']][$premierChemin] = $dernierChemin;
81
				$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']]++;
93
				$this->noeuds[$info['id_noeud']][$dernierChemin] = $premierChemin;
82
			}
94
			}
-
 
95
		}
-
 
96
		//print_r($this->chemins);exit();
-
 
97
	}
-
 
98
 
-
 
99
	private function ordonnerCheminsRelation($numPolygon, $idChemin, $idCheminPrecedent = null, $ordre = 1) {
-
 
100
		$this->infosRel[$idChemin] = array($ordre, $numPolygon);
-
 
101
 
-
 
102
		list($premierNoeud, $dernierNoeud) = $this->chemins[$idChemin];
-
 
103
 
-
 
104
		if ($idCheminPrecedent == null) {// Premier chemin à tester
-
 
105
			$this->premierNoeudPolygon = $premierNoeud;
-
 
106
			$noeudSuivant = ($dernierNoeud == $premierNoeud) ? $premierNoeud : $dernierNoeud;
-
 
107
			echo "Chemin $idChemin :: premierNoeud: $premierNoeud, dernierNoeud: $dernierNoeud \n";
-
 
108
		} else {
-
 
109
			list($premierNoeudPrec, $dernierNoeudPrec) = $this->chemins[$idCheminPrecedent];
-
 
110
			unset($this->chemins[$idCheminPrecedent]);
-
 
111
			$noeudSuivant = ($dernierNoeudPrec == $dernierNoeud || $premierNoeudPrec == $dernierNoeud) ? $premierNoeud : $dernierNoeud;
-
 
112
			echo "Chemin $idChemin :: premierNoeudPrec: $premierNoeudPrec, dernierNoeudPrec: $dernierNoeudPrec, premierNoeud: $premierNoeud, dernierNoeud: $dernierNoeud \n";
-
 
113
		}
-
 
114
 
-
 
115
		if ($this->premierNoeudPolygon != $noeudSuivant) {
-
 
116
			if (isset($this->noeuds[$noeudSuivant][$idChemin])) {
-
 
117
				$idCheminSuivant = $this->noeuds[$noeudSuivant][$idChemin];
-
 
118
				if (! isset($this->infosRel[$idCheminSuivant])) {
-
 
119
					$this->ordonnerCheminsRelation($numPolygon, $idCheminSuivant, $idChemin, ++$ordre);
-
 
120
				} else {
-
 
121
					$this->messages->traiterAvertissement("Chemins %s déjà pris en comtpe", array($idCheminSuivant));
-
 
122
				}
-
 
123
			} else {
-
 
124
				$this->messages->traiterAvertissement("Relation %s a un polygone incomplet", array($this->idRelation));
-
 
125
			}
-
 
126
		} else {
-
 
127
			unset($this->chemins[$idChemin]);
-
 
128
		}
-
 
129
		return null;
-
 
130
	}
-
 
131
 
-
 
132
	private function mettreAJourRelationAChemin() {
-
 
133
		if (count($this->infosRel) > 0) {
-
 
134
			foreach ($this->infosRel as $idC => $donnees) {
-
 
135
				list($ordre, $numPolygon) = $this->bdd->proteger($donnees);
-
 
136
				$requete = 'UPDATE osm_relation_a_chemins '.
-
 
137
					"SET sens = $ordre, num_poly = $numPolygon ".
-
 
138
					"WHERE id_relation = {$this->idRelation} ".
-
 
139
					"AND id_chemin = $idC ".
-
 
140
					' -- '.__FILE__.' : '.__LINE__;
83
		}
141
				$this->bdd->requeter($requete);
-
 
142
			}
-
 
143
			$this->infosRel = array();
-
 
144
		}
-
 
145
	}
-
 
146
 
-
 
147
	private function creerSet($donnees) {
-
 
148
		$values = array();
-
 
149
		foreach ($donnees as $infos) {
-
 
150
			$infosP = $this->bdd->proteger($infos);
-
 
151
			$values[] = implode(',', $infosP);
-
 
152
		}
84
		//print_r($this->infosNoeuds);exit();
153
		$valuesClause = '('.implode('),(', $values).')';
Line 85... Line 154...
85
		$this->ordre = 0;
154
		return $valuesClause;
86
	}
155
	}
87
 
156
 
Line 107... Line 176...
107
 
176
 
108
	private function getIdDernierNoeud() {
177
	private function getIdDernierNoeud() {
109
		$idNoeud = false;
178
		$idNoeud = false;
110
		if (count($this->infosRel[$this->idChemin]) > 0) {
179
		if (count($this->infosRel[$this->idChemin]) > 0) {
111
			end($this->infosRel[$this->idChemin]);
180
			end($this->infosRel[$this->idChemin]);
112
			$idNoeud = key($this->infosRel[$this->idChemin]);
181
			$idNoeud = current($this->infosRel[$this->idChemin]);
113
		}
182
		}
114
		return $idNoeud;
183
		return $idNoeud;
Line 115... Line 184...
115
	}
184
	}
Line 130... Line 199...
130
	}
199
	}
Line 131... Line 200...
131
 
200
 
132
	private function getIdCheminSuivant() {
201
	private function getIdCheminSuivant() {
133
		$idCheminSuivant = false;
202
		$idCheminSuivant = false;
134
		if (isset($this->infosNoeuds[$this->idNoeud])) {
203
		if (isset($this->infosNoeuds[$this->idNoeud])) {
135
			$cheminsIds = array_keys($this->infosNoeuds[$this->idNoeud]);
-
 
136
			foreach ($cheminsIds as $idChemin) {
204
			$idCheminSuivant = next($this->infosNoeuds[$this->idNoeud]);
137
				if ($idChemin != $this->idChemin) {
-
 
138
					$idCheminSuivant = $idChemin;
-
 
139
					break;
-
 
140
				}
-
 
141
			}
205
			//echo $this->idChemin.'-'.$idCheminSuivant."\n".print_r($this->infosNoeuds[$this->idNoeud]); exit();
142
		} else {
206
		} else {
143
			$msg = "Impossible de trouver le chemin suivant pour la relation : %s, le chemin %s et le noeud %s";
207
			$msg = "Impossible de trouver le chemin suivant pour la relation : %s, le chemin %s et le noeud %s";
144
			$this->messages->traiterAvertissement($msg, array($this->idRelation, $this->idChemin, $this->idNoeud));
208
			$this->messages->traiterAvertissement($msg, array($this->idRelation, $this->idChemin, $this->idNoeud));
145
		}
209
		}
Line 153... Line 217...
153
 
217
 
154
	private function getIdPremierNoeud() {
218
	private function getIdPremierNoeud() {
155
		$idNoeud = false;
219
		$idNoeud = false;
156
		if (count($this->infosRel[$this->idChemin]) > 0) {
220
		if (count($this->infosRel[$this->idChemin]) > 0) {
157
			reset($this->infosRel[$this->idChemin]);
221
			reset($this->infosRel[$this->idChemin]);
158
			$idNoeud = key($this->infosRel[$this->idChemin]);
222
			$idNoeud = current($this->infosRel[$this->idChemin]);
159
		}
223
		}
160
		return $idNoeud;
224
		return $idNoeud;
161
	}
225
	}
162
}
226
}