Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 26 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26 Rev 31
1
<?php
1
<?php
2
 
2
 
3
class Commun {
3
class Commun {
4
	
4
	
5
	
5
	
6
	private $parametres;
6
	private $parametres;
7
	private $nomSource;
7
	private $nomSource;
8
	private $nomService;
8
	private $nomService;
9
	
9
	
10
	private $verificateur;
10
	private $verificateur;
11
	private $parametresRecherche;
11
	private $parametresRecherche;
12
	
12
	
13
	
13
	
14
	public function consulter($ressources, $parametres) {
14
	public function consulter($ressources, $parametres) {
15
		
-
 
16
		$this->recupererRessourcesEtParametres($ressources, $parametres);
15
		$this->recupererRessourcesEtParametres($ressources, $parametres);
17
		$retour = null;
16
		$retour = null;
18
		
-
 
19
		try {
17
		try {
20
			if (!$this->verifierExistenceSourcesDonnees()) {
18
			if (!$this->verifierExistenceSourcesDonnees()) {
21
				$message = "Source de donnees indisponible";
19
				$message = "Source de donnees indisponible";
22
				throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
20
				throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
23
			} else {
21
			} else {
24
				$this->chargerNomSource();
-
 
25
				$this->verifierParametres();
22
				$this->verifierParametres();
26
				$this->chargerNomService();
23
				if ($this->ressources[0] == 'mailles') {
27
				$objetTraitement = new $this->nomService($this->parametresRecherche);
24
					$retour = $this->recupererMaillage();
-
 
25
				} else {
-
 
26
					$this->chargerNomSource();
28
				$methode = $this->genererNomMethodeAExecuter();
27
					$this->chargerNomService();
29
				$retour = $objetTraitement->$methode();
28
					$retour = $this->executerServicePourSource();
-
 
29
				}
30
			}
30
			}
31
			
-
 
32
		} catch (Exception $erreur) {
31
		} catch (Exception $erreur) {
33
			$retour = $erreur; 
32
			$retour = $erreur; 
34
		}
33
		}
35
		
-
 
36
		return $retour;
34
		return $retour;
37
	}
35
	}
38
	
36
	
39
	private function recupererRessourcesEtParametres($ressources, $parametres) {
37
	private function recupererRessourcesEtParametres($ressources, $parametres) {
40
		$this->ressources = $ressources;
38
		$this->ressources = $ressources;
41
		$this->parametres = $parametres;
39
		$this->parametres = $parametres;
42
	}
40
	}
43
	
-
 
44
	private function chargerNomService() {
-
 
45
		$this->nomService = ucfirst($this->parametres['source']) . 'Formateur';
-
 
46
		Projets::chargerConfigurationSource($this->parametres['source']);
-
 
47
	}
-
 
48
	
-
 
49
	private function genererNomMethodeAExecuter() {
-
 
50
		return 'recuperer' . ucfirst($this->ressources[0]);
-
 
51
	}
-
 
52
	
41
	
53
	private function verifierExistenceSourcesDonnees() {
42
	private function verifierExistenceSourcesDonnees() {
54
		$sourcesDisponibles = explode(',', Config::get('sources_dispo'));
43
		$sourcesDisponibles = explode(',', Config::get('sources_dispo'));
55
		$estDisponible = false;
44
		$estDisponible = false;
56
		if (isset($this->parametres['source'])) {
45
		if (isset($this->parametres['source'])) {
57
			if (in_array($this->parametres['source'], $sourcesDisponibles)) {
46
			if (in_array($this->parametres['source'], $sourcesDisponibles)) {
58
				$estDisponible = true;
47
				$estDisponible = true;
59
			}
48
			}
60
		} else {
49
		} else {
61
			// choisir la source par defaut, qui est toujours disponible
50
			// choisir la source par defaut, qui est toujours disponible
62
			$estDisponible = true;
51
			$estDisponible = true;
63
		}
52
		}
64
		return $estDisponible;
53
		return $estDisponible;
65
	}
54
	}
66
	
-
 
67
	private function chargerNomSource() {
-
 
68
		if (isset($this->parametres['source'])) {
-
 
69
			$this->nomSource = $this->parametres['source'];
-
 
70
		} else {
-
 
71
			$this->nomSource = Config::get('source_defaut');
-
 
72
		}
-
 
73
	}
-
 
74
	
55
	
75
	private function verifierParametres() {
56
	private function verifierParametres() {
76
		$this->verificateur = new VerificateurParametres($this->parametres);
57
		$this->verificateur = new VerificateurParametres($this->parametres);
77
		$this->verificateur->verifierParametres();
58
		$this->verificateur->verifierParametres();
78
		if ($this->verificateur->contientErreurs()) {
59
		if ($this->verificateur->contientErreurs()) {
79
			$this->verificateur->leverException();
60
			$this->verificateur->leverException();
80
		} else {
61
		} else {
81
			$this->recupererParametresRecherche();
62
			$this->recupererParametresRecherche();
82
		}
63
		}
83
	}
64
	}
84
	
65
	
85
	private function recupererParametresRecherche() {
66
	private function recupererParametresRecherche() {
86
		$this->parametresRecherche = $this->verificateur->renvoyerResultatVerification();
67
		$this->parametresRecherche = $this->verificateur->renvoyerResultatVerification();
87
	}
68
	}
-
 
69
	
-
 
70
	private function chargerNomSource() {
-
 
71
		if (isset($this->parametres['source'])) {
-
 
72
			$this->nomSource = $this->parametres['source'];
-
 
73
		} else {
-
 
74
			$this->nomSource = Config::get('source_defaut');
-
 
75
		}
-
 
76
	}
-
 
77
	
-
 
78
	private function chargerNomService() {
-
 
79
		$this->nomService = ucfirst($this->parametres['source']) . 'Formateur';
-
 
80
		Projets::chargerConfigurationSource($this->parametres['source']);
-
 
81
	}
-
 
82
	
-
 
83
	private function recupererMaillage() {
-
 
84
		$maillage = new Maillage($this->parametresRecherche->bbox, $this->parametresRecherche->zoom);
-
 
85
		$maillage->genererMaillesVides();
-
 
86
		$formateurJSON = new FormateurJson();
-
 
87
		return $formateurJSON->formaterMaillesVides($maillage->formaterSortie(true));
-
 
88
	}
-
 
89
	
-
 
90
	private function executerServicePourSource() {
-
 
91
		$objetTraitement = new $this->nomService($this->parametresRecherche);
-
 
92
		$methode = $this->genererNomMethodeAExecuter();
-
 
93
		return $objetTraitement->$methode();
-
 
94
	}
-
 
95
	
-
 
96
	private function genererNomMethodeAExecuter() {
-
 
97
		return 'recuperer' . ucfirst($this->ressources[0]);
88
	
98
	}
89
	
99
	
90
}
100
}
91
 
101
 
92
?>
102
?>