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