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;
|
702 |
gduche |
77 |
if (isset($this->ressources) && count($this->ressources) > 0) {
|
751 |
delphine |
78 |
if (is_numeric($this->ressources[0])) {
|
|
|
79 |
$presenceId = true;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
return $presenceId;
|
702 |
gduche |
83 |
}
|
751 |
delphine |
84 |
/*------------------------------------------------------------------------------------------------------------------
|
|
|
85 |
CONFIGURATION DU PROJET
|
|
|
86 |
------------------------------------------------------------------------------------------------------------------*/
|
702 |
gduche |
87 |
private function initialiserProjet() {
|
|
|
88 |
$this->chargerNomDuProjet();
|
|
|
89 |
$this->chargerConfigProjet();
|
|
|
90 |
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
private function chargerNomDuProjet() {
|
746 |
gduche |
94 |
$this->projetNom = 'images';
|
702 |
gduche |
95 |
}
|
|
|
96 |
|
|
|
97 |
private function chargerConfigProjet() {
|
|
|
98 |
$projet = $this->projetNom;
|
|
|
99 |
$chemin = Config::get('chemin_configurations')."config_$projet.ini";
|
|
|
100 |
Config::charger($chemin);
|
|
|
101 |
}
|
|
|
102 |
|
751 |
delphine |
103 |
/*------------------------------------------------------------------------------------------------------------------
|
|
|
104 |
CONFIGURATION DU SERVICE
|
|
|
105 |
------------------------------------------------------------------------------------------------------------------*/
|
702 |
gduche |
106 |
private function avoirRessourceService() {
|
751 |
delphine |
107 |
/*
|
|
|
108 |
* url possibles :
|
|
|
109 |
* http://localhost/del/services/0.1/images/ => toutes les images, appel à la classe ListeImages
|
|
|
110 |
* http://localhost/del/services/0.1/images/#id => une image donnée => non utilisé sur DEL pour l'instant
|
|
|
111 |
* http://localhost/del/services/0.1/images/#id/votes/ => tous les votes d'une image classés par protocole
|
|
|
112 |
* http://localhost/del/services/0.1/images/#id/votes/protocole/#id => tous les votes d'une image et d'un protocole donné
|
|
|
113 |
* http://localhost/del/services/0.1/images/#id/votes/#id => un vote donné pour une image donnée.
|
|
|
114 |
* */
|
702 |
gduche |
115 |
$presenceRessourceService = false;
|
|
|
116 |
$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
|
718 |
gduche |
117 |
|
751 |
delphine |
118 |
if (isset($this->ressources[1])) {
|
|
|
119 |
$service = $this->ressources[1];
|
|
|
120 |
if ($this->avoirRessourceIdentifiant()) {
|
|
|
121 |
if (in_array($service, $servicesDispo)) {
|
|
|
122 |
$presenceRessourceService = true;
|
|
|
123 |
$this->serviceNom = 'votes-image';
|
|
|
124 |
} else {
|
|
|
125 |
$message = "Le service demandé '$service' n'est pas disponible pour le projet {$this->projetNom} !\n".
|
|
|
126 |
"Les services disponibles sont : ".implode(', ', $servicesDispo);
|
|
|
127 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
128 |
throw new Exception($message, $code);
|
|
|
129 |
}
|
702 |
gduche |
130 |
} else {
|
751 |
delphine |
131 |
$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
|
702 |
gduche |
132 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
133 |
throw new Exception($message, $code);
|
|
|
134 |
}
|
|
|
135 |
} else {
|
751 |
delphine |
136 |
$presenceRessourceService = true;
|
|
|
137 |
$this->serviceNom = 'liste-images';
|
702 |
gduche |
138 |
}
|
|
|
139 |
return $presenceRessourceService;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
private function initialiserService() {
|
751 |
delphine |
143 |
//$this->chargerNomDuService();
|
746 |
gduche |
144 |
|
702 |
gduche |
145 |
$classe = $this->obtenirNomClasseService($this->serviceNom);
|
|
|
146 |
$chemins = array();
|
718 |
gduche |
147 |
$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
|
|
|
148 |
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
|
702 |
gduche |
149 |
$retour = '';
|
|
|
150 |
$service = null;
|
|
|
151 |
foreach ($chemins as $chemin) {
|
|
|
152 |
if (file_exists($chemin)) {
|
718 |
gduche |
153 |
$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
|
751 |
delphine |
154 |
require_once $chemin;
|
724 |
gduche |
155 |
$service = new $classe($this->conteneur);
|
751 |
delphine |
156 |
$retour = $service->consulter($this->ressources, $this->parametres);
|
702 |
gduche |
157 |
}
|
|
|
158 |
}
|
746 |
gduche |
159 |
|
702 |
gduche |
160 |
if (is_null($service)) {
|
751 |
delphine |
161 |
$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
|
702 |
gduche |
162 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
163 |
throw new Exception($message, $code);
|
|
|
164 |
}
|
|
|
165 |
return $retour;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
private function obtenirNomClasseService($mot) {
|
|
|
169 |
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
|
|
|
170 |
return $classeNom;
|
|
|
171 |
}
|
|
|
172 |
|
751 |
delphine |
173 |
|
702 |
gduche |
174 |
}
|
|
|
175 |
?>
|