1046 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Traitement de l'ordre :
|
|
|
4 |
*
|
|
|
5 |
* Fonction qui rajoute l'ordre et le sens de chaque way d'une relation dans la table `osm_relation_a_chemins`
|
|
|
6 |
*
|
|
|
7 |
* Exemple de lancement du script :
|
|
|
8 |
* /opt/lampp/bin/php -d memory_limit=8000M cli.php osm -a ordre -m manuel
|
|
|
9 |
*
|
|
|
10 |
*/
|
|
|
11 |
class OrdonneurDeChemins {
|
|
|
12 |
private $conteneur;
|
|
|
13 |
private $bdd;
|
|
|
14 |
private $messages;
|
|
|
15 |
private $mode;
|
|
|
16 |
|
|
|
17 |
private $idRelation = null;
|
|
|
18 |
private $idChemin = null;
|
|
|
19 |
private $idNoeud = null;
|
|
|
20 |
private $chemins = array();
|
|
|
21 |
private $ordre = 0;
|
|
|
22 |
|
|
|
23 |
public function __construct($conteneur) {
|
|
|
24 |
$this->conteneur = $conteneur;
|
|
|
25 |
$this->bdd = $this->conteneur->getBdd();
|
|
|
26 |
$this->messages = $this->conteneur->getMessages();
|
|
|
27 |
$this->mode = $this->conteneur->getParametre('m');
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public function executer() {
|
|
|
31 |
$relations = $this->getToutesRelationsAChemins();
|
|
|
32 |
if ($this->mode == 'manuel') {
|
|
|
33 |
$this->messages->traiterInfo("Nombre de relations : %s", array(count($relations)));
|
|
|
34 |
}
|
|
|
35 |
foreach ($relations as $relation) {
|
|
|
36 |
// Traitement de la relation courante
|
|
|
37 |
$this->idRelation = $relation['id_relation'];
|
|
|
38 |
|
|
|
39 |
$this->chargerCheminsRelationActuelle();
|
|
|
40 |
|
|
|
41 |
// Selection du premier chemin comme chemin actuel
|
|
|
42 |
$this->idChemin = $this->getIdPremierChemin();
|
|
|
43 |
$this->mettreAJourChemin('directe', __LINE__);
|
|
|
44 |
|
|
|
45 |
// Selection du dernier noeud comme noeud actuel
|
|
|
46 |
$idDernierNoeud = $this->getIdDernierNoeud();
|
|
|
47 |
if ($idDernierNoeud) {
|
|
|
48 |
$this->idNoeud = $idDernierNoeud;
|
|
|
49 |
$this->ordonnerChemins();
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
// Affichage de l'avancement
|
|
|
53 |
if ($this->mode == 'manuel') {
|
|
|
54 |
$this->messages->afficherAvancement("Ordone les chemins de la relation : ", 1);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
private function getToutesRelationsAChemins() {
|
|
|
60 |
$requete = 'SELECT DISTINCT id_relation '.
|
|
|
61 |
'FROM osm_relation_a_chemins '.
|
|
|
62 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
63 |
$relations = $this->bdd->recupererTous($requete);
|
|
|
64 |
return $relations;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private function chargerDonneesRelationActuelle() {
|
|
|
68 |
$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '.
|
|
|
69 |
'FROM osm_relation_a_chemins AS rc '.
|
|
|
70 |
' LEFT JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '.
|
|
|
71 |
"WHERE rc.id_relation = {$this->idRelation} ".
|
|
|
72 |
"ODER BY cn.ordre ASC ".
|
|
|
73 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
74 |
$infos = $this->bdd->recupererTous($requete);
|
|
|
75 |
foreach ($infos as $info) {
|
|
|
76 |
$this->infosRel[$this->idRelation][$info['id_chemin']]['noeuds'][$info['id_noeud']] = $info['ordre'];
|
|
|
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__;
|
|
|
87 |
$chemins = $this->bdd->recupererTous($requete);
|
|
|
88 |
$this->chemins = ($chemins) ? $chemins : array();
|
|
|
89 |
$this->ordre = 0;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
private function getIdPremierChemin() {
|
|
|
93 |
return isset($this->chemins[0]) ? $this->chemins[0]['id_chemin'] : null;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private function mettreAJourChemin($sens, $ligne, $fichier = __FILE__) {
|
|
|
97 |
$ordre = $this->ordre++;
|
|
|
98 |
$requete = 'UPDATE osm_relation_a_chemins '.
|
|
|
99 |
"SET ordre = '$ordre', sens = '$sens' ".
|
|
|
100 |
"WHERE id_relation = {$this->idRelation} ".
|
|
|
101 |
"AND id_chemin = {$this->idChemin} ".
|
|
|
102 |
" -- $fichier : $ligne";
|
|
|
103 |
$retour = $this->bdd->requeter($requete);
|
|
|
104 |
return $retour;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
private function getIdDernierNoeud() {
|
|
|
108 |
$requete = 'SELECT id_noeud '.
|
|
|
109 |
'FROM osm_chemin_a_noeuds '.
|
|
|
110 |
"WHERE id_chemin = {$this->idChemin} ".
|
|
|
111 |
'ORDER BY ordre DESC '.
|
|
|
112 |
'LIMIT 0,1 '.
|
|
|
113 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
114 |
$noeud = $this->bdd->recuperer($requete);
|
|
|
115 |
$idDernierNoeud = ($noeud) ? $noeud['id_noeud'] : false;
|
|
|
116 |
return $idDernierNoeud;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
private function ordonnerChemins() {
|
|
|
120 |
foreach ($this->chemins as $chemin) {
|
|
|
121 |
// Selection du chemin qui possède le dernier noeud du précédent chemin et écarter l'actuel
|
|
|
122 |
$idCheminSuivant = $this->getIdCheminSuivant();
|
|
|
123 |
if ($idCheminSuivant) {
|
|
|
124 |
$this->idChemin = $idCheminSuivant;
|
|
|
125 |
$this->comparerNoeuds();
|
|
|
126 |
} else {
|
|
|
127 |
$msg = "Impossible de trouver le chemin suivant pour la relation : %s";
|
|
|
128 |
$this->messages->traiterAvertissement($msg, array($this->idRelation));
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
private function getIdCheminSuivant() {
|
|
|
134 |
$requete = 'SELECT wn.id_chemin '.
|
|
|
135 |
'FROM osm_relation_a_chemins AS rw '.
|
|
|
136 |
' LEFT JOIN osm_chemin_a_noeuds AS wn ON (rw.id_chemin = wn.id_chemin) '.
|
|
|
137 |
"WHERE wn.id_noeud = {$this->idNoeud} ".
|
|
|
138 |
" AND wn.id_chemin != {$this->idChemin} ".
|
|
|
139 |
" AND rw.id_relation = {$this->idRelation} ".
|
|
|
140 |
" LIMIT 0,1 ".
|
|
|
141 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
142 |
$chemins = $this->bdd->recuperer($requete);
|
|
|
143 |
$idCheminSuivant = ($chemins && isset($chemins['id_chemin'])) ? $chemins['id_chemin'] : false;
|
|
|
144 |
return $idCheminSuivant;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
private function comparerNoeuds() {
|
|
|
148 |
$idPremierNoeud = $this->getIdPremierNoeud();
|
|
|
149 |
$idDernierNoeud = $this->getIdDernierNoeud();
|
|
|
150 |
if ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) {
|
|
|
151 |
$this->mettreAJourChemin('directe', __LINE__);
|
|
|
152 |
$this->idNoeud = $idDernierNoeud;
|
|
|
153 |
} else {
|
|
|
154 |
$this->mettreAJourChemin('indirecte', __LINE__);
|
|
|
155 |
$this->idNoeud = $idPremierNoeud;
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
private function getIdPremierNoeud() {
|
|
|
160 |
$requete = 'SELECT id_noeud '.
|
|
|
161 |
'FROM osm_chemin_a_noeuds '.
|
|
|
162 |
"WHERE id_chemin = {$this->idChemin} ".
|
|
|
163 |
'ORDER BY ordre ASC '.
|
|
|
164 |
'LIMIT 0,1 '.
|
|
|
165 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
166 |
$noeud = $this->bdd->recuperer($requete);
|
|
|
167 |
$idPremierNoeud = ($noeud) ? $noeud['id_noeud'] : false;
|
|
|
168 |
return $idPremierNoeud;
|
|
|
169 |
}
|
|
|
170 |
}
|