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 |
$presenceRessourceService = false;
|
|
|
131 |
if (isset($this->ressources[0])) {
|
|
|
132 |
if($this->ressources[0] == 'images-determinations-probables') {
|
|
|
133 |
$presenceRessourceService = true;
|
|
|
134 |
$this->serviceNom = 'liste-images-determinations-probables';
|
1252 |
aurelien |
135 |
} else if($this->ressources[0] == 'valider-determination') {
|
|
|
136 |
$presenceRessourceService = true;
|
|
|
137 |
$this->serviceNom = 'valider-determination';
|
1144 |
aurelien |
138 |
} else {
|
|
|
139 |
$this->editerMessageErreurRessource();
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
return $presenceRessourceService;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
private function editerMessageErreurRessource() {
|
|
|
146 |
$message = "Le service demandé '".$this->projetNom.'/'.implode('/', $this->ressources).
|
|
|
147 |
"' n'est pas disponible pour le projet ".$this->projetNom." !\n".
|
|
|
148 |
"Les services disponibles sont : images, images/#id/votes, images/#id/vote/#id_vote";
|
|
|
149 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
150 |
throw new Exception($message, $code);
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
private function etreRessourceIdentifiant($num) {
|
|
|
154 |
$presenceId = false;
|
|
|
155 |
if (is_numeric($this->ressources[$num])) {
|
|
|
156 |
$presenceId = true;
|
|
|
157 |
} else {
|
|
|
158 |
$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
|
|
|
159 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
160 |
throw new Exception($message, $code);
|
|
|
161 |
}
|
|
|
162 |
return $presenceId;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
private function initialiserService() {
|
|
|
166 |
|
|
|
167 |
$classe = $this->obtenirNomClasseService($this->serviceNom);
|
|
|
168 |
$chemins = array();
|
|
|
169 |
$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
|
|
|
170 |
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
|
|
|
171 |
$retour = '';
|
|
|
172 |
$service = null;
|
|
|
173 |
foreach ($chemins as $chemin) {
|
|
|
174 |
if (file_exists($chemin)) {
|
|
|
175 |
$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
|
|
|
176 |
require_once $chemin;
|
|
|
177 |
$service = new $classe($this->conteneur);
|
|
|
178 |
if ($this->methode == 'consulter') {
|
|
|
179 |
$retour = $service->consulter($this->ressources, $this->parametres);
|
|
|
180 |
} elseif ($this->methode == 'ajouter') {
|
|
|
181 |
$retour = $service->ajouter($this->ressources, $this->parametres);
|
|
|
182 |
} elseif ($this->methode == 'modifier') {
|
|
|
183 |
$retour = $service->modifier($this->ressources, $this->parametres);
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
if (is_null($service)) {
|
|
|
189 |
$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
|
|
|
190 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
191 |
throw new Exception($message, $code);
|
|
|
192 |
}
|
|
|
193 |
return $retour;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
private function obtenirNomClasseService($mot) {
|
|
|
197 |
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
|
|
|
198 |
return $classeNom;
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
?>
|