Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1046 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1046 Rev 1047
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
 
-
 
17
	private $infosRel = array();
16
 
18
	private $infosNoeuds = array();
17
	private $idRelation = null;
19
	private $idRelation = null;
18
	private $idChemin = null;
20
	private $idChemin = null;
19
	private $idNoeud = null;
-
 
20
	private $chemins = array();
21
	private $idNoeud = null;
Line 21... Line 22...
21
	private $ordre = 0;
22
	private $ordre = 0;
22
 
23
 
23
	public function __construct($conteneur) {
24
	public function __construct($conteneur) {
Line 34... Line 35...
34
		}
35
		}
35
		foreach ($relations as $relation) {
36
		foreach ($relations as $relation) {
36
			// Traitement de la relation courante
37
			// Traitement de la relation courante
37
			$this->idRelation = $relation['id_relation'];
38
			$this->idRelation = $relation['id_relation'];
Line 38... Line 39...
38
 
39
 
Line 39... Line 40...
39
			$this->chargerCheminsRelationActuelle();
40
			$this->chargerDonneesRelationActuelle();
40
 
41
 
41
			// Selection du premier chemin comme chemin actuel
42
			// Selection du premier chemin comme chemin actuel
Line 65... Line 66...
65
	}
66
	}
Line 66... Line 67...
66
 
67
 
67
	private function chargerDonneesRelationActuelle() {
68
	private function chargerDonneesRelationActuelle() {
68
		$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '.
69
		$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '.
69
			'FROM osm_relation_a_chemins AS rc '.
70
			'FROM osm_relation_a_chemins AS rc '.
70
			'	LEFT JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '.
71
			'	INNER JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '.
71
			"WHERE rc.id_relation = {$this->idRelation} ".
72
			"WHERE rc.id_relation = {$this->idRelation} ".
72
			"ODER BY cn.ordre ASC ".
73
			"ORDER BY cn.ordre ASC ".
73
			' -- '.__FILE__.' : '.__LINE__;
74
			' -- '.__FILE__.' : '.__LINE__;
74
		$infos = $this->bdd->recupererTous($requete);
75
		$infos = $this->bdd->recupererTous($requete);
75
		foreach ($infos as $info) {
76
		foreach ($infos as $info) {
-
 
77
			$this->infosRel[$info['id_chemin']][$info['id_noeud']] = $info['ordre'];
-
 
78
			if (! isset($this->infosNoeuds[$info['id_noeud']][$info['id_chemin']])) {
-
 
79
				$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']] = 1;
-
 
80
			} else {
-
 
81
				$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']]++;
76
			$this->infosRel[$this->idRelation][$info['id_chemin']]['noeuds'][$info['id_noeud']] = $info['ordre'];
82
			}
77
		}
-
 
78
		$this->chemins = ($chemins) ? $chemins : array();
-
 
79
		$this->ordre = 0;
-
 
80
	}
-
 
81
 
-
 
82
	private function chargerCheminsRelationActuelle() {
-
 
83
		$requete = 'SELECT id_chemin '.
-
 
84
			'FROM osm_relation_a_chemins '.
-
 
85
			"WHERE id_relation = {$this->idRelation} ".
-
 
86
			' -- '.__FILE__.' : '.__LINE__;
83
		}
87
		$chemins = $this->bdd->recupererTous($requete);
-
 
88
		$this->chemins = ($chemins) ? $chemins : array();
84
		//print_r($this->infosNoeuds);exit();
89
		$this->ordre = 0;
85
		$this->ordre = 0;
Line 90... Line 86...
90
	}
86
	}
-
 
87
 
-
 
88
	private function getIdPremierChemin() {
-
 
89
		$idChemin = null;
91
 
90
		if (count($this->infosRel) > 0) {
-
 
91
			reset($this->infosRel);
-
 
92
			$idChemin = key($this->infosRel);
92
	private function getIdPremierChemin() {
93
		}
Line 93... Line 94...
93
		return isset($this->chemins[0]) ? $this->chemins[0]['id_chemin'] : null;
94
		return $idChemin;
94
	}
95
	}
95
 
96
 
Line 103... Line 104...
103
		$retour = $this->bdd->requeter($requete);
104
		$retour = $this->bdd->requeter($requete);
104
		return $retour;
105
		return $retour;
105
	}
106
	}
Line 106... Line 107...
106
 
107
 
107
	private function getIdDernierNoeud() {
108
	private function getIdDernierNoeud() {
108
		$requete = 'SELECT id_noeud '.
-
 
109
			'FROM osm_chemin_a_noeuds '.
109
		$idNoeud = false;
110
			"WHERE id_chemin = {$this->idChemin} ".
-
 
111
			'ORDER BY ordre DESC '.
-
 
112
			'LIMIT 0,1 '.
-
 
113
			' -- '.__FILE__.' : '.__LINE__;
110
		if (count($this->infosRel[$this->idChemin]) > 0) {
114
		$noeud = $this->bdd->recuperer($requete);
111
			end($this->infosRel[$this->idChemin]);
-
 
112
			$idNoeud = key($this->infosRel[$this->idChemin]);
115
		$idDernierNoeud = ($noeud) ? $noeud['id_noeud'] : false;
113
		}
116
		return $idDernierNoeud;
114
		return $idNoeud;
Line 117... Line 115...
117
	}
115
	}
118
 
116
 
119
	private function ordonnerChemins() {
117
	private function ordonnerChemins() {
120
		foreach ($this->chemins as $chemin) {
118
		foreach ($this->infosRel as $chemin) {
121
			// Selection du chemin qui possède le dernier noeud du précédent chemin et écarter l'actuel
119
			// Selection du chemin qui possède le dernier noeud du précédent chemin et écarter l'actuel
122
			$idCheminSuivant = $this->getIdCheminSuivant();
120
			$idCheminSuivant = $this->getIdCheminSuivant();
-
 
121
			if ($idCheminSuivant) {
123
			if ($idCheminSuivant) {
122
				$this->idChemin = $idCheminSuivant;
124
				$this->idChemin = $idCheminSuivant;
123
				$idPremierNoeud = $this->getIdPremierNoeud();
125
				$this->comparerNoeuds();
124
				$idDernierNoeud = $this->getIdDernierNoeud();
126
			} else {
125
				$sens = $this->getSens($idPremierNoeud);
127
				$msg = "Impossible de trouver le chemin suivant pour la relation : %s";
126
				$this->mettreAJourChemin($sens, __LINE__);
128
				$this->messages->traiterAvertissement($msg, array($this->idRelation));
127
				$this->idNoeud =  ($sens == 'directe') ? $idDernierNoeud : $idPremierNoeud;
129
			}
128
			}
Line 130... Line 129...
130
		}
129
		}
131
	}
130
	}
132
 
131
 
133
	private function getIdCheminSuivant() {
132
	private function getIdCheminSuivant() {
134
		$requete = 'SELECT wn.id_chemin '.
133
		$idCheminSuivant = false;
135
			'FROM osm_relation_a_chemins AS rw '.
134
		if (isset($this->infosNoeuds[$this->idNoeud])) {
136
			'	LEFT JOIN osm_chemin_a_noeuds AS wn ON (rw.id_chemin = wn.id_chemin) '.
135
			$cheminsIds = array_keys($this->infosNoeuds[$this->idNoeud]);
137
			"WHERE wn.id_noeud = {$this->idNoeud} ".
136
			foreach ($cheminsIds as $idChemin) {
-
 
137
				if ($idChemin != $this->idChemin) {
-
 
138
					$idCheminSuivant = $idChemin;
138
			"	AND wn.id_chemin != {$this->idChemin} ".
139
					break;
139
			"	AND rw.id_relation = {$this->idRelation} ".
140
				}
140
			" LIMIT 0,1 ".
141
			}
-
 
142
		} else {
141
			' -- '.__FILE__.' : '.__LINE__;
143
			$msg = "Impossible de trouver le chemin suivant pour la relation : %s, le chemin %s et le noeud %s";
142
		$chemins = $this->bdd->recuperer($requete);
144
			$this->messages->traiterAvertissement($msg, array($this->idRelation, $this->idChemin, $this->idNoeud));
Line 143... Line 145...
143
		$idCheminSuivant = ($chemins && isset($chemins['id_chemin'])) ? $chemins['id_chemin'] : false;
145
		}
144
		return $idCheminSuivant;
-
 
145
	}
-
 
146
 
146
		return $idCheminSuivant;
147
	private function comparerNoeuds() {
-
 
148
		$idPremierNoeud = $this->getIdPremierNoeud();
-
 
149
		$idDernierNoeud = $this->getIdDernierNoeud();
147
	}
150
		if ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) {
-
 
151
			$this->mettreAJourChemin('directe', __LINE__);
-
 
152
			$this->idNoeud = $idDernierNoeud;
-
 
153
		} else {
148
 
Line 154... Line 149...
154
			$this->mettreAJourChemin('indirecte', __LINE__);
149
	private function getSens($idPremierNoeud) {
155
			$this->idNoeud = $idPremierNoeud;
150
		$sens = ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) ? 'directe' : 'indirecte';
156
		}
-
 
157
	}
151
		return $sens;
158
 
-
 
159
	private function getIdPremierNoeud() {
-
 
160
		$requete = 'SELECT id_noeud '.
-
 
161
			'FROM osm_chemin_a_noeuds '.
152
	}
162
			"WHERE id_chemin = {$this->idChemin} ".
153
 
-
 
154
	private function getIdPremierNoeud() {
163
			'ORDER BY ordre ASC '.
155
		$idNoeud = false;
164
			'LIMIT 0,1 '.
156
		if (count($this->infosRel[$this->idChemin]) > 0) {
165
			' -- '.__FILE__.' : '.__LINE__;
157
			reset($this->infosRel[$this->idChemin]);
166
		$noeud = $this->bdd->recuperer($requete);
158
			$idNoeud = key($this->infosRel[$this->idChemin]);