14,10 → 14,11 |
private $messages; |
private $mode; |
|
private $infosRel = array(); |
private $infosNoeuds = array(); |
private $idRelation = null; |
private $idChemin = null; |
private $idNoeud = null; |
private $chemins = array(); |
private $ordre = 0; |
|
public function __construct($conteneur) { |
36,7 → 37,7 |
// Traitement de la relation courante |
$this->idRelation = $relation['id_relation']; |
|
$this->chargerCheminsRelationActuelle(); |
$this->chargerDonneesRelationActuelle(); |
|
// Selection du premier chemin comme chemin actuel |
$this->idChemin = $this->getIdPremierChemin(); |
67,30 → 68,30 |
private function chargerDonneesRelationActuelle() { |
$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '. |
'FROM osm_relation_a_chemins AS rc '. |
' LEFT JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '. |
' INNER JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '. |
"WHERE rc.id_relation = {$this->idRelation} ". |
"ODER BY cn.ordre ASC ". |
"ORDER BY cn.ordre ASC ". |
' -- '.__FILE__.' : '.__LINE__; |
$infos = $this->bdd->recupererTous($requete); |
foreach ($infos as $info) { |
$this->infosRel[$this->idRelation][$info['id_chemin']]['noeuds'][$info['id_noeud']] = $info['ordre']; |
$this->infosRel[$info['id_chemin']][$info['id_noeud']] = $info['ordre']; |
if (! isset($this->infosNoeuds[$info['id_noeud']][$info['id_chemin']])) { |
$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']] = 1; |
} else { |
$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']]++; |
} |
} |
$this->chemins = ($chemins) ? $chemins : array(); |
//print_r($this->infosNoeuds);exit(); |
$this->ordre = 0; |
} |
|
private function chargerCheminsRelationActuelle() { |
$requete = 'SELECT id_chemin '. |
'FROM osm_relation_a_chemins '. |
"WHERE id_relation = {$this->idRelation} ". |
' -- '.__FILE__.' : '.__LINE__; |
$chemins = $this->bdd->recupererTous($requete); |
$this->chemins = ($chemins) ? $chemins : array(); |
$this->ordre = 0; |
} |
|
private function getIdPremierChemin() { |
return isset($this->chemins[0]) ? $this->chemins[0]['id_chemin'] : null; |
$idChemin = null; |
if (count($this->infosRel) > 0) { |
reset($this->infosRel); |
$idChemin = key($this->infosRel); |
} |
return $idChemin; |
} |
|
private function mettreAJourChemin($sens, $ligne, $fichier = __FILE__) { |
105,66 → 106,57 |
} |
|
private function getIdDernierNoeud() { |
$requete = 'SELECT id_noeud '. |
'FROM osm_chemin_a_noeuds '. |
"WHERE id_chemin = {$this->idChemin} ". |
'ORDER BY ordre DESC '. |
'LIMIT 0,1 '. |
' -- '.__FILE__.' : '.__LINE__; |
$noeud = $this->bdd->recuperer($requete); |
$idDernierNoeud = ($noeud) ? $noeud['id_noeud'] : false; |
return $idDernierNoeud; |
$idNoeud = false; |
if (count($this->infosRel[$this->idChemin]) > 0) { |
end($this->infosRel[$this->idChemin]); |
$idNoeud = key($this->infosRel[$this->idChemin]); |
} |
return $idNoeud; |
} |
|
private function ordonnerChemins() { |
foreach ($this->chemins as $chemin) { |
foreach ($this->infosRel as $chemin) { |
// Selection du chemin qui possède le dernier noeud du précédent chemin et écarter l'actuel |
$idCheminSuivant = $this->getIdCheminSuivant(); |
if ($idCheminSuivant) { |
$this->idChemin = $idCheminSuivant; |
$this->comparerNoeuds(); |
} else { |
$msg = "Impossible de trouver le chemin suivant pour la relation : %s"; |
$this->messages->traiterAvertissement($msg, array($this->idRelation)); |
$idPremierNoeud = $this->getIdPremierNoeud(); |
$idDernierNoeud = $this->getIdDernierNoeud(); |
$sens = $this->getSens($idPremierNoeud); |
$this->mettreAJourChemin($sens, __LINE__); |
$this->idNoeud = ($sens == 'directe') ? $idDernierNoeud : $idPremierNoeud; |
} |
} |
} |
|
private function getIdCheminSuivant() { |
$requete = 'SELECT wn.id_chemin '. |
'FROM osm_relation_a_chemins AS rw '. |
' LEFT JOIN osm_chemin_a_noeuds AS wn ON (rw.id_chemin = wn.id_chemin) '. |
"WHERE wn.id_noeud = {$this->idNoeud} ". |
" AND wn.id_chemin != {$this->idChemin} ". |
" AND rw.id_relation = {$this->idRelation} ". |
" LIMIT 0,1 ". |
' -- '.__FILE__.' : '.__LINE__; |
$chemins = $this->bdd->recuperer($requete); |
$idCheminSuivant = ($chemins && isset($chemins['id_chemin'])) ? $chemins['id_chemin'] : false; |
$idCheminSuivant = false; |
if (isset($this->infosNoeuds[$this->idNoeud])) { |
$cheminsIds = array_keys($this->infosNoeuds[$this->idNoeud]); |
foreach ($cheminsIds as $idChemin) { |
if ($idChemin != $this->idChemin) { |
$idCheminSuivant = $idChemin; |
break; |
} |
} |
} else { |
$msg = "Impossible de trouver le chemin suivant pour la relation : %s, le chemin %s et le noeud %s"; |
$this->messages->traiterAvertissement($msg, array($this->idRelation, $this->idChemin, $this->idNoeud)); |
} |
return $idCheminSuivant; |
} |
|
private function comparerNoeuds() { |
$idPremierNoeud = $this->getIdPremierNoeud(); |
$idDernierNoeud = $this->getIdDernierNoeud(); |
if ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) { |
$this->mettreAJourChemin('directe', __LINE__); |
$this->idNoeud = $idDernierNoeud; |
} else { |
$this->mettreAJourChemin('indirecte', __LINE__); |
$this->idNoeud = $idPremierNoeud; |
} |
private function getSens($idPremierNoeud) { |
$sens = ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) ? 'directe' : 'indirecte'; |
return $sens; |
} |
|
private function getIdPremierNoeud() { |
$requete = 'SELECT id_noeud '. |
'FROM osm_chemin_a_noeuds '. |
"WHERE id_chemin = {$this->idChemin} ". |
'ORDER BY ordre ASC '. |
'LIMIT 0,1 '. |
' -- '.__FILE__.' : '.__LINE__; |
$noeud = $this->bdd->recuperer($requete); |
$idPremierNoeud = ($noeud) ? $noeud['id_noeud'] : false; |
return $idPremierNoeud; |
$idNoeud = false; |
if (count($this->infosRel[$this->idChemin]) > 0) { |
reset($this->infosRel[$this->idChemin]); |
$idNoeud = key($this->infosRel[$this->idChemin]); |
} |
return $idNoeud; |
} |
} |