702 |
gduche |
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 |
*/
|
746 |
gduche |
17 |
class Images extends RestService {
|
702 |
gduche |
18 |
|
746 |
gduche |
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 |
|
702 |
gduche |
29 |
private $parametres = array();
|
|
|
30 |
private $ressources = array();
|
|
|
31 |
private $projetNom = array();
|
|
|
32 |
private $serviceNom = array();
|
718 |
gduche |
33 |
private $cheminCourant = null;
|
|
|
34 |
|
|
|
35 |
private $conteneur;
|
|
|
36 |
|
|
|
37 |
/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
|
702 |
gduche |
38 |
protected $utilisationParametresBruts = true;
|
|
|
39 |
|
|
|
40 |
public function __construct() {
|
718 |
gduche |
41 |
$this->cheminCourant = dirname(__FILE__).DS;
|
702 |
gduche |
42 |
}
|
|
|
43 |
|
|
|
44 |
public function consulter($ressources, $parametres) {
|
718 |
gduche |
45 |
|
702 |
gduche |
46 |
$resultat = '';
|
|
|
47 |
$reponseHttp = new ReponseHttp();
|
|
|
48 |
try {
|
|
|
49 |
$this->initialiserRessourcesEtParametres($ressources, $parametres);
|
718 |
gduche |
50 |
$this->conteneur = new Conteneur($this->parametres);
|
702 |
gduche |
51 |
$resultat = $this->traiterRessources();
|
|
|
52 |
$reponseHttp->setResultatService($resultat);
|
|
|
53 |
} catch (Exception $e) {
|
|
|
54 |
$reponseHttp->ajouterErreur($e);
|
|
|
55 |
}
|
|
|
56 |
$reponseHttp->emettreLesEntetes();
|
|
|
57 |
$corps = $reponseHttp->getCorps();
|
|
|
58 |
return $corps;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
private function initialiserRessourcesEtParametres($ressources, $parametres) {
|
|
|
62 |
$this->ressources = $ressources;
|
|
|
63 |
$this->parametres = $parametres;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
private function traiterRessources() {
|
|
|
67 |
$retour = '';
|
751 |
delphine |
68 |
$this->initialiserProjet();
|
|
|
69 |
if ($this->avoirRessourceService()) {
|
|
|
70 |
$retour = $this->initialiserService();
|
702 |
gduche |
71 |
}
|
|
|
72 |
return $retour;
|
|
|
73 |
}
|
751 |
delphine |
74 |
|
|
|
75 |
private function avoirRessourceIdentifiant() {
|
|
|
76 |
$presenceId = false;
|
|
|
77 |
if (is_numeric($this->ressources[0])) {
|
|
|
78 |
$presenceId = true;
|
754 |
delphine |
79 |
} else {
|
|
|
80 |
$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
|
|
|
81 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
82 |
throw new Exception($message, $code);
|
751 |
delphine |
83 |
}
|
|
|
84 |
return $presenceId;
|
702 |
gduche |
85 |
}
|
751 |
delphine |
86 |
/*------------------------------------------------------------------------------------------------------------------
|
|
|
87 |
CONFIGURATION DU PROJET
|
|
|
88 |
------------------------------------------------------------------------------------------------------------------*/
|
702 |
gduche |
89 |
private function initialiserProjet() {
|
|
|
90 |
$this->chargerNomDuProjet();
|
|
|
91 |
$this->chargerConfigProjet();
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
private function chargerNomDuProjet() {
|
746 |
gduche |
96 |
$this->projetNom = 'images';
|
702 |
gduche |
97 |
}
|
|
|
98 |
|
|
|
99 |
private function chargerConfigProjet() {
|
|
|
100 |
$projet = $this->projetNom;
|
|
|
101 |
$chemin = Config::get('chemin_configurations')."config_$projet.ini";
|
|
|
102 |
Config::charger($chemin);
|
|
|
103 |
}
|
|
|
104 |
|
751 |
delphine |
105 |
/*------------------------------------------------------------------------------------------------------------------
|
|
|
106 |
CONFIGURATION DU SERVICE
|
|
|
107 |
------------------------------------------------------------------------------------------------------------------*/
|
702 |
gduche |
108 |
private function avoirRessourceService() {
|
751 |
delphine |
109 |
/*
|
|
|
110 |
* url possibles :
|
|
|
111 |
* http://localhost/del/services/0.1/images/ => toutes les images, appel à la classe ListeImages
|
|
|
112 |
* http://localhost/del/services/0.1/images/#id => une image donnée => non utilisé sur DEL pour l'instant
|
|
|
113 |
* http://localhost/del/services/0.1/images/#id/votes/ => tous les votes d'une image classés par protocole
|
|
|
114 |
* http://localhost/del/services/0.1/images/#id/votes/protocole/#id => tous les votes d'une image et d'un protocole donné
|
|
|
115 |
* http://localhost/del/services/0.1/images/#id/votes/#id => un vote donné pour une image donnée.
|
|
|
116 |
* */
|
702 |
gduche |
117 |
$presenceRessourceService = false;
|
754 |
delphine |
118 |
if (isset($this->ressources[0])) {
|
751 |
delphine |
119 |
if ($this->avoirRessourceIdentifiant()) {
|
754 |
delphine |
120 |
if (isset($this->ressources[1])) {
|
|
|
121 |
$presenceRessourceService = $this->avoirRessourceSousService();
|
751 |
delphine |
122 |
} else {
|
754 |
delphine |
123 |
$message = "Le service demandé 'image/#id' n'est pas disponible pour le projet {$this->projetNom} !";
|
751 |
delphine |
124 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
125 |
throw new Exception($message, $code);
|
|
|
126 |
}
|
754 |
delphine |
127 |
}
|
702 |
gduche |
128 |
} else {
|
751 |
delphine |
129 |
$presenceRessourceService = true;
|
|
|
130 |
$this->serviceNom = 'liste-images';
|
702 |
gduche |
131 |
}
|
|
|
132 |
return $presenceRessourceService;
|
|
|
133 |
}
|
754 |
delphine |
134 |
|
|
|
135 |
private function avoirRessourceSousService() {
|
|
|
136 |
$presenceRessourceService = false;
|
|
|
137 |
$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
|
|
|
138 |
$service = $this->ressources[1];
|
|
|
139 |
if (in_array($service, $servicesDispo)) {
|
|
|
140 |
$presenceRessourceService = true;
|
|
|
141 |
$this->serviceNom = 'votes-image';
|
|
|
142 |
} else {
|
|
|
143 |
$message = "Le service demandé '$service' n'est pas disponible pour le projet {$this->projetNom} !\n".
|
|
|
144 |
"Les services disponibles sont : ".implode(', ', $servicesDispo);
|
|
|
145 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
146 |
throw new Exception($message, $code);
|
|
|
147 |
}
|
|
|
148 |
return $presenceRessourceService;
|
|
|
149 |
}
|
702 |
gduche |
150 |
|
|
|
151 |
private function initialiserService() {
|
751 |
delphine |
152 |
//$this->chargerNomDuService();
|
746 |
gduche |
153 |
|
702 |
gduche |
154 |
$classe = $this->obtenirNomClasseService($this->serviceNom);
|
|
|
155 |
$chemins = array();
|
718 |
gduche |
156 |
$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
|
|
|
157 |
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
|
702 |
gduche |
158 |
$retour = '';
|
|
|
159 |
$service = null;
|
|
|
160 |
foreach ($chemins as $chemin) {
|
|
|
161 |
if (file_exists($chemin)) {
|
718 |
gduche |
162 |
$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
|
751 |
delphine |
163 |
require_once $chemin;
|
724 |
gduche |
164 |
$service = new $classe($this->conteneur);
|
751 |
delphine |
165 |
$retour = $service->consulter($this->ressources, $this->parametres);
|
702 |
gduche |
166 |
}
|
|
|
167 |
}
|
746 |
gduche |
168 |
|
702 |
gduche |
169 |
if (is_null($service)) {
|
751 |
delphine |
170 |
$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
|
702 |
gduche |
171 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
172 |
throw new Exception($message, $code);
|
|
|
173 |
}
|
|
|
174 |
return $retour;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
private function obtenirNomClasseService($mot) {
|
|
|
178 |
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
|
|
|
179 |
return $classeNom;
|
|
|
180 |
}
|
|
|
181 |
|
751 |
delphine |
182 |
|
702 |
gduche |
183 |
}
|
|
|
184 |
?>
|