Subversion Repositories eFlore/Applications.del

Rev

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

Rev 724 Rev 746
Line 12... Line 12...
12
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
12
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
* @version 0.1
14
* @version 0.1
15
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
15
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
16
*/
16
*/
17
class Del extends RestService {
17
class Images extends RestService {
Line -... Line 18...
-
 
18
 
-
 
19
	
-
 
20
	/*
-
 
21
	 * url possibles : 
-
 
22
	 * http://localhost/del/services/0.1/images/ => toutes les images, appel à la classe ListeImages
-
 
23
	 * http://localhost/del/services/0.1/images/#id => une image donnée => non utilisé sur DEL pour l'instant
-
 
24
	 * http://localhost/del/services/0.1/images/#id/votes/ => tous les votes d'une image classés par protocole
-
 
25
	 * http://localhost/del/services/0.1/images/#id/votes/protocole/#id => tous les votes d'une image et d'un protocole donné
-
 
26
	 * http://localhost/del/services/0.1/images/#id/votes/#id => un vote donné pour une image donnée.
-
 
27
	 * */
18
 
28
	
19
	private $parametres = array();
29
	private $parametres = array();
20
	private $ressources = array();
30
	private $ressources = array();
21
	private $projetNom = array();
31
	private $projetNom = array();
22
	private $serviceNom = array();
32
	private $serviceNom = array();
Line 54... Line 64...
54
	}
64
	}
Line 55... Line 65...
55
 
65
 
56
	private function traiterRessources() {
66
	private function traiterRessources() {
57
		$retour = '';
67
		$retour = '';
58
		if ($this->avoirRessources()) {
68
		if ($this->avoirRessources()) {
59
			if ($this->avoirRessourceProjet()) {
69
			//if ($this->avoirRessourceProjet()) {
60
				$this->initialiserProjet();
70
				$this->initialiserProjet();
61
				if ($this->avoirRessourceService()) {
71
				if ($this->avoirRessourceService()) {
62
					$retour = $this->initialiserService();
72
					$retour = $this->initialiserService();
63
				}
73
				}
64
			}
74
			//}
65
		}
75
		}
66
		return $retour;
76
		return $retour;
Line 67... Line 77...
67
	}
77
	}
Line 77... Line 87...
77
			throw new Exception($message, $code);
87
			throw new Exception($message, $code);
78
		}
88
		}
79
		return $presenceDeRessources;
89
		return $presenceDeRessources;
80
	}
90
	}
Line 81... Line -...
81
 
-
 
82
	private function avoirRessourceProjet() {
-
 
83
		$presenceRessourceProjet = false;
-
 
84
		$projet = $this->ressources[0];
-
 
85
		$projetsDispo = Outils::recupererTableauConfig('projetsDispo');
-
 
86
		if (in_array($projet, $projetsDispo)) {
-
 
87
			$presenceRessourceProjet = true;
-
 
88
		} else {
-
 
89
			$message = "La ressource '$projet' n'indique pas un projet existant.\n".
-
 
90
				"Les projets existant sont :\n".implode(', ', $projetsDispo);
-
 
91
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
-
 
92
			throw new Exception($message, $code);
-
 
93
		}
-
 
94
		return $presenceRessourceProjet;
-
 
95
	}
-
 
96
 
91
 
97
	private function initialiserProjet() {
92
	private function initialiserProjet() {
98
		$this->chargerNomDuProjet();
93
		$this->chargerNomDuProjet();
Line 99... Line 94...
99
		$this->chargerConfigProjet();
94
		$this->chargerConfigProjet();
Line 105... Line 100...
105
			spl_autoload_register(array($this, 'chargerClasseProjet'), true , true);
100
			spl_autoload_register(array($this, 'chargerClasseProjet'), true , true);
106
		}
101
		}
107
	}
102
	}
Line 108... Line 103...
108
 
103
 
109
	private function chargerNomDuProjet() {
104
	private function chargerNomDuProjet() {
110
		$this->projetNom = $this->ressources[0];
105
		$this->projetNom = 'images';
Line 111... Line 106...
111
	}
106
	}
112
 
107
 
113
	private function chargerConfigProjet() {
108
	private function chargerConfigProjet() {
Line 139... Line 134...
139
 
134
 
140
	private function avoirRessourceService() {
135
	private function avoirRessourceService() {
141
		$presenceRessourceService = false;
136
		$presenceRessourceService = false;
Line 142... Line 137...
142
		$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
137
		$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
143
	
138
	
144
		if (isset($this->ressources[1])) {
139
		if (isset($this->ressources[0])) {
145
			$service = $this->ressources[1];
140
			$service = $this->ressources[0];
146
			if (in_array($service, $servicesDispo)) {
141
			if (in_array($service, $servicesDispo)) {
147
				$presenceRessourceService = true;
142
				$presenceRessourceService = true;
148
			} else {
143
			} else {
Line 160... Line 155...
160
		return $presenceRessourceService;
155
		return $presenceRessourceService;
161
	}
156
	}
Line 162... Line 157...
162
 
157
 
163
	private function initialiserService() {
158
	private function initialiserService() {
-
 
159
		$this->chargerNomDuService();
164
		$this->chargerNomDuService();
160
		
165
		$classe = $this->obtenirNomClasseService($this->serviceNom);
161
		$classe = $this->obtenirNomClasseService($this->serviceNom);
166
		$chemins = array();
162
		$chemins = array();
167
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
163
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
Line 175... Line 171...
175
				$service = new $classe($this->conteneur);
171
				$service = new $classe($this->conteneur);
176
				$ressourcesPourService = $this->filtrerRessourcesPourService();
172
				$ressourcesPourService = $this->filtrerRessourcesPourService();
177
				$retour = $service->consulter($ressourcesPourService, $this->parametres);
173
				$retour = $service->consulter($ressourcesPourService, $this->parametres);
178
			}
174
			}
179
		}
175
		}
-
 
176
		
180
		if (is_null($service)) {
177
		if (is_null($service)) {
181
			$message = "La service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
178
			$message = "La service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
182
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
179
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
183
			throw new Exception($message, $code);
180
			throw new Exception($message, $code);
184
		}
181
		}
185
		return $retour;
182
		return $retour;
186
	}
183
	}
Line 187... Line 184...
187
 
184
 
188
	private function chargerNomDuService() {
185
	private function chargerNomDuService() {
189
		$this->serviceNom = $this->ressources[1];
186
		$this->serviceNom = $this->ressources[0];
Line 190... Line 187...
190
	}
187
	}
191
 
188
 
192
	private function obtenirNomClasseService($mot) {
189
	private function obtenirNomClasseService($mot) {