Subversion Repositories eFlore/Applications.del

Rev

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

Rev 755 Rev 787
Line 23... Line 23...
23
	* http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
23
	* http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
24
	* */
24
	* */
Line 25... Line 25...
25
	
25
	
26
	private $parametres = array();
26
	private $parametres = array();
-
 
27
	private $ressources = array();
27
	private $ressources = array();
28
	private $methode = null;
28
	private $projetNom = array();
29
	private $projetNom = array();
29
	private $serviceNom = array();
30
	private $serviceNom = array();
Line 30... Line 31...
30
	private $cheminCourant = null;
31
	private $cheminCourant = null;
Line 37... Line 38...
37
	public function __construct() {
38
	public function __construct() {
38
		$this->cheminCourant = dirname(__FILE__).DS;
39
		$this->cheminCourant = dirname(__FILE__).DS;
39
	}
40
	}
Line 40... Line 41...
40
 
41
 
41
	public function consulter($ressources, $parametres) {
-
 
-
 
42
	public function consulter($ressources, $parametres) {
42
		
43
		$this->methode = 'consulter';
43
		$resultat = '';
44
		$resultat = '';
44
		$reponseHttp = new ReponseHttp();
45
		$reponseHttp = new ReponseHttp();
45
		try {
46
		try {
46
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
47
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
Line 52... Line 53...
52
		}
53
		}
53
		$reponseHttp->emettreLesEntetes();
54
		$reponseHttp->emettreLesEntetes();
54
		$corps = $reponseHttp->getCorps();
55
		$corps = $reponseHttp->getCorps();
55
		return $corps;
56
		return $corps;
56
	}
57
	}
-
 
58
	
-
 
59
	public function ajouter($ressources, $requeteDonnees) {
-
 
60
		$this->methode = 'ajouter';
-
 
61
		$resultat = '';
-
 
62
		try {
-
 
63
			$this->initialiserRessourcesEtParametres($ressources, $requeteDonnees);
-
 
64
			$this->conteneur = new Conteneur($this->parametres);
-
 
65
			$resultat = $this->traiterRessources();
-
 
66
		} catch (Exception $e) {
-
 
67
			$reponseHttp->ajouterErreur($e);
-
 
68
		}
-
 
69
	}
Line 57... Line 70...
57
 
70
 
58
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
71
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
59
		$this->ressources = $ressources;
72
		$this->ressources = $ressources;
60
		$this->parametres = $parametres;
73
		$this->parametres = $parametres;
Line 67... Line 80...
67
			$retour = $this->initialiserService();
80
			$retour = $this->initialiserService();
68
		}
81
		}
69
		return $retour;
82
		return $retour;
70
	}
83
	}
Line 71... Line 84...
71
	
84
	
72
	private function avoirRessourceIdentifiant() {
85
	private function avoirRessourceIdentifiant($num) {
73
		$presenceId = false;
86
		$presenceId = false;
74
			if (is_numeric($this->ressources[0])) {
87
			if (is_numeric($this->ressources[$num])) {
75
				$presenceId = true;
88
				$presenceId = true;
76
			} else {
89
			} else {
77
				$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
90
				$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
78
				$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
91
				$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
Line 108... Line 121...
108
		* http://localhost/del/services/0.1/observations/ => toutes les observations (infos obs, infos images, infos propositions, infos nb commentaires)
121
		* http://localhost/del/services/0.1/observations/ => toutes les observations (infos obs, infos images, infos propositions, infos nb commentaires)
109
		* http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
122
		* http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
110
		* */
123
		* */
111
		$presenceRessourceService = false;
124
		$presenceRessourceService = false;
112
		if (isset($this->ressources[0])) {
125
		if (isset($this->ressources[0])) {
113
			if ($this->avoirRessourceIdentifiant()) {
126
			if ($this->avoirRessourceIdentifiant(0)) {
114
				if (sizeof($this->ressources) == 1) {
127
				if (sizeof($this->ressources) == 1) {
115
					$presenceRessourceService = true;
128
					$presenceRessourceService = true;
116
					$this->serviceNom = 'observation';
129
					$this->serviceNom = 'observation';
117
				} else {
130
				} else {
118
					if (isset($this->ressources[1])) {
131
					if (isset($this->ressources[1])) {
Line 128... Line 141...
128
	}
141
	}
Line 129... Line 142...
129
	
142
	
130
	private function avoirRessourceSousService() {
143
	private function avoirRessourceSousService() {
131
		$presenceRessourceService = false;
144
		$presenceRessourceService = false;
-
 
145
		$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
132
		$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
146
		if ($this->avoirRessourceIdentifiant(1)) {
133
		$service = $this->ressources[1];
147
			$service = $this->ressources[2];
134
		if (in_array($service, $servicesDispo)) {
148
			if (in_array($service, $servicesDispo)) {
135
			$presenceRessourceService = true;
149
				$presenceRessourceService = true;
136
			$this->serviceNom = 'votes-image';
150
				$this->serviceNom = 'vote-observation';
137
		} else {
151
			} else {
138
			$message = "Le service demandé '$service' n'est pas disponible pour le projet {$this->projetNom} !\n".
152
				$message = "Le service demandé '$service' n'est pas disponible pour le projet {$this->projetNom} !\n".
139
						"Les services disponibles sont : ".implode(', ', $servicesDispo);
153
							"Les services disponibles sont : ".implode(', ', $servicesDispo);
140
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
154
				$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
155
				throw new Exception($message, $code);
141
			throw new Exception($message, $code);
156
			}
142
		}
157
		}
143
		return $presenceRessourceService;
158
		return $presenceRessourceService;
Line 144... Line 159...
144
	}
159
	}
Line 155... Line 170...
155
		foreach ($chemins as $chemin) {
170
		foreach ($chemins as $chemin) {
156
			if (file_exists($chemin)) {
171
			if (file_exists($chemin)) {
157
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
172
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
158
				require_once $chemin;
173
				require_once $chemin;
159
				$service = new $classe($this->conteneur);
174
				$service = new $classe($this->conteneur);
-
 
175
				if ($this->methode == 'consulter') {
160
				$retour = $service->consulter($this->ressources, $this->parametres);
176
					$retour = $service->consulter($this->ressources, $this->parametres);
-
 
177
				} elseif ($this->methode == 'ajouter') {
-
 
178
					$retour = $service->ajouter($this->ressources, $this->parametres);
-
 
179
				}
161
			}
180
			}
162
		}
181
		}
Line 163... Line 182...
163
		
182
		
164
		if (is_null($service)) {
183
		if (is_null($service)) {