1144 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Description :
|
|
|
4 |
* Classe principale de chargement des services d'eFlore.
|
|
|
5 |
*
|
|
|
6 |
* Encodage en entrée : utf8
|
|
|
7 |
* Encodage en sortie : utf8
|
|
|
8 |
* @package eflore-projets
|
|
|
9 |
* @author Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
|
|
|
10 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
|
|
11 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
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>
|
|
|
14 |
* @version 0.1
|
|
|
15 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
|
|
16 |
*/
|
|
|
17 |
class Determinations extends RestService {
|
|
|
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 |
* */
|
|
|
28 |
|
|
|
29 |
private $parametres = array();
|
|
|
30 |
private $ressources = array();
|
|
|
31 |
private $methode = null;
|
|
|
32 |
private $projetNom = array();
|
|
|
33 |
private $serviceNom = array();
|
|
|
34 |
private $cheminCourant = null;
|
|
|
35 |
|
|
|
36 |
private $conteneur;
|
|
|
37 |
|
|
|
38 |
/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
|
|
|
39 |
protected $utilisationParametresBruts = true;
|
|
|
40 |
|
|
|
41 |
public function __construct() {
|
|
|
42 |
$this->cheminCourant = dirname(__FILE__).DS;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function consulter($ressources, $parametres) {
|
|
|
46 |
$this->methode = 'consulter';
|
|
|
47 |
$resultat = '';
|
|
|
48 |
$reponseHttp = new ReponseHttp();
|
|
|
49 |
try {
|
|
|
50 |
$this->initialiserRessourcesEtParametres($ressources, $parametres);
|
|
|
51 |
$this->conteneur = new Conteneur($this->parametres);
|
|
|
52 |
$resultat = $this->traiterRessources();
|
|
|
53 |
$reponseHttp->setResultatService($resultat);
|
|
|
54 |
} catch (Exception $e) {
|
|
|
55 |
$reponseHttp->ajouterErreur($e);
|
|
|
56 |
}
|
|
|
57 |
$reponseHttp->emettreLesEntetes();
|
|
|
58 |
$corps = $reponseHttp->getCorps();
|
|
|
59 |
return $corps;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function ajouter($ressources, $requeteDonnees) {
|
|
|
63 |
$this->methode = 'ajouter';
|
|
|
64 |
$resultat = '';
|
|
|
65 |
$reponseHttp = new ReponseHttp();
|
|
|
66 |
try {
|
|
|
67 |
$this->initialiserRessourcesEtParametres($ressources, $requeteDonnees);
|
|
|
68 |
$this->conteneur = new Conteneur($this->parametres);
|
|
|
69 |
$resultat = $this->traiterRessources();
|
|
|
70 |
} catch (Exception $e) {
|
|
|
71 |
$reponseHttp->ajouterErreur($e);
|
|
|
72 |
$reponseHttp->emettreLesEntetes();
|
|
|
73 |
echo $reponseHttp->getCorps();
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public function modifier($ressources, $requeteDonnees) {
|
|
|
78 |
$this->methode = 'modifier';
|
|
|
79 |
$resultat = '';
|
|
|
80 |
$reponseHttp = new ReponseHttp();
|
|
|
81 |
try {
|
|
|
82 |
$this->initialiserRessourcesEtParametres($ressources, $requeteDonnees);
|
|
|
83 |
$this->conteneur = new Conteneur($this->parametres);
|
|
|
84 |
$resultat = $this->traiterRessources();
|
|
|
85 |
} catch (Exception $e) {
|
|
|
86 |
$reponseHttp->ajouterErreur($e);
|
|
|
87 |
$reponseHttp->emettreLesEntetes();
|
|
|
88 |
echo $reponseHttp->getCorps();
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
private function initialiserRessourcesEtParametres($ressources, $parametres) {
|
|
|
93 |
$this->ressources = $ressources;
|
|
|
94 |
$this->parametres = $parametres;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
private function traiterRessources() {
|
|
|
98 |
$retour = '';
|
|
|
99 |
$this->initialiserProjet();
|
|
|
100 |
if ($this->avoirRessourceService()) {
|
|
|
101 |
$retour = $this->initialiserService();
|
|
|
102 |
}
|
|
|
103 |
return $retour;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
/*------------------------------------------------------------------------------------------------------------------
|
|
|
108 |
CONFIGURATION DU PROJET
|
|
|
109 |
------------------------------------------------------------------------------------------------------------------*/
|
|
|
110 |
private function initialiserProjet() {
|
|
|
111 |
$this->chargerNomDuProjet();
|
|
|
112 |
$this->chargerConfigProjet();
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
private function chargerNomDuProjet() {
|
|
|
117 |
$this->projetNom = 'determinations';
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
private function chargerConfigProjet() {
|
|
|
121 |
$projet = $this->projetNom;
|
|
|
122 |
$chemin = Config::get('chemin_configurations')."config_$projet.ini";
|
|
|
123 |
Config::charger($chemin);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/*------------------------------------------------------------------------------------------------------------------
|
|
|
127 |
CONFIGURATION DU SERVICE
|
|
|
128 |
------------------------------------------------------------------------------------------------------------------*/
|
|
|
129 |
private function avoirRessourceService() {
|
|
|
130 |
/*
|
|
|
131 |
* url possibles :
|
|
|
132 |
* http://localhost/del/services/0.1/images/ => toutes les images, appel à la classe ListeImages
|
|
|
133 |
* http://localhost/del/services/0.1/images/#id => une image donnée => non utilisé sur DEL pour l'instant
|
|
|
134 |
* http://localhost/del/services/0.1/images/#id/votes/ => tous les votes d'une image classés par protocole
|
|
|
135 |
* http://localhost/del/services/0.1/images/#id/votes/protocole/#id => tous les votes d'une image et d'un protocole donné
|
|
|
136 |
* http://localhost/del/services/0.1/images/#id/votes/#id => un vote donné pour une image donnée.
|
|
|
137 |
* */
|
|
|
138 |
$presenceRessourceService = false;
|
|
|
139 |
if (isset($this->ressources[0])) {
|
|
|
140 |
if($this->ressources[0] == 'images-determinations-probables') {
|
|
|
141 |
$presenceRessourceService = true;
|
|
|
142 |
$this->serviceNom = 'liste-images-determinations-probables';
|
|
|
143 |
} else {
|
|
|
144 |
$this->editerMessageErreurRessource();
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
return $presenceRessourceService;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
private function editerMessageErreurRessource() {
|
|
|
151 |
$message = "Le service demandé '".$this->projetNom.'/'.implode('/', $this->ressources).
|
|
|
152 |
"' n'est pas disponible pour le projet ".$this->projetNom." !\n".
|
|
|
153 |
"Les services disponibles sont : images, images/#id/votes, images/#id/vote/#id_vote";
|
|
|
154 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
155 |
throw new Exception($message, $code);
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
private function etreRessourceIdentifiant($num) {
|
|
|
159 |
$presenceId = false;
|
|
|
160 |
if (is_numeric($this->ressources[$num])) {
|
|
|
161 |
$presenceId = true;
|
|
|
162 |
} else {
|
|
|
163 |
$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
|
|
|
164 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
165 |
throw new Exception($message, $code);
|
|
|
166 |
}
|
|
|
167 |
return $presenceId;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
private function initialiserService() {
|
|
|
171 |
//$this->chargerNomDuService();
|
|
|
172 |
|
|
|
173 |
$classe = $this->obtenirNomClasseService($this->serviceNom);
|
|
|
174 |
$chemins = array();
|
|
|
175 |
$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
|
|
|
176 |
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
|
|
|
177 |
$retour = '';
|
|
|
178 |
$service = null;
|
|
|
179 |
foreach ($chemins as $chemin) {
|
|
|
180 |
if (file_exists($chemin)) {
|
|
|
181 |
$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
|
|
|
182 |
require_once $chemin;
|
|
|
183 |
$service = new $classe($this->conteneur);
|
|
|
184 |
if ($this->methode == 'consulter') {
|
|
|
185 |
$retour = $service->consulter($this->ressources, $this->parametres);
|
|
|
186 |
} elseif ($this->methode == 'ajouter') {
|
|
|
187 |
$retour = $service->ajouter($this->ressources, $this->parametres);
|
|
|
188 |
} elseif ($this->methode == 'modifier') {
|
|
|
189 |
$retour = $service->modifier($this->ressources, $this->parametres);
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
if (is_null($service)) {
|
|
|
195 |
$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
|
|
|
196 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
197 |
throw new Exception($message, $code);
|
|
|
198 |
}
|
|
|
199 |
return $retour;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
private function obtenirNomClasseService($mot) {
|
|
|
203 |
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
|
|
|
204 |
return $classeNom;
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
?>
|