| Line 27... |
Line 27... |
| 27 |
protected $table="";
|
27 |
protected $table="";
|
| 28 |
private $requete_condition = "";
|
28 |
private $requete_condition = "";
|
| 29 |
/** Permet de stocker la requete formulée: /informations/bdnt.nn | */
|
29 |
/** Permet de stocker la requete formulée: /informations/bdnt.nn | */
|
| 30 |
private $format_reponse = 'informations';
|
30 |
private $format_reponse = 'informations';
|
| 31 |
private $total_resultat;
|
31 |
private $total_resultat;
|
| - |
|
32 |
private $retour_format = 'max';
|
| 32 |
protected $limite_requete = array( 'depart' => 0, 'limite' => 10);
|
33 |
protected $limite_requete = array( 'depart' => 0, 'limite' => 10);
|
| 33 |
private $champs_recherches='*';
|
34 |
private $champs_recherches = '*';
|
| 34 |
|
- |
|
| - |
|
35 |
private $champs_ontologiques = array ('ve_lumiere' => 'VEL', 've_temperature' => 'VET',
|
| - |
|
36 |
've_continentalite' => 'VEC', 've_humidite_atmos' => 'VEHA',
|
| - |
|
37 |
've_humidite_edaph' => 'VEHE', 've_reaction_sol' => 'VER' ,
|
| - |
|
38 |
've_nutriments_sol' => 'VEN', 've_salinite'=> 'VES' ,
|
| - |
|
39 |
've_texture_sol' => 'VETX', 've_mat_org_sol' => 'VEMO');
|
| 35 |
|
40 |
|
| - |
|
41 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
| 36 |
public function traiterParametres() {
|
42 |
public function traiterParametres() {
|
| 37 |
if (isset($this->parametres) && !empty($this->parametres)) {
|
43 |
if (isset($this->parametres) && !empty($this->parametres)) {
|
| 38 |
foreach ($this->parametres as $param => $valeur) {
|
44 |
foreach ($this->parametres as $param => $valeur) {
|
| 39 |
switch ($param) {
|
45 |
switch ($param) {
|
| 40 |
case 'navigation.depart' :
|
46 |
case 'navigation.depart' :
|
| Line 52... |
Line 58... |
| 52 |
}else {
|
58 |
}else {
|
| 53 |
$e = 'Valeur de paramètre inconnue pour \'test\'. ';
|
59 |
$e = 'Valeur de paramètre inconnue pour \'test\'. ';
|
| 54 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
60 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
| 55 |
}
|
61 |
}
|
| 56 |
break;
|
62 |
break;
|
| - |
|
63 |
case 'retour.format' :
|
| - |
|
64 |
$this->retour_format = $valeur;
|
| - |
|
65 |
break;
|
| 57 |
default :
|
66 |
default :
|
| 58 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
67 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
| 59 |
.$param.' " n\'existe pas.';
|
68 |
.$param.' " n\'existe pas.';
|
| 60 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e); break;
|
69 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e); break;
|
| 61 |
}
|
70 |
}
|
| Line 87... |
Line 96... |
| 87 |
}
|
96 |
}
|
| 88 |
} else {
|
97 |
} else {
|
| 89 |
$this->champs_recherches=" cle, catminat_code, BDNT, num_taxon, num_nomen ";
|
98 |
$this->champs_recherches=" cle, catminat_code, BDNT, num_taxon, num_nomen ";
|
| 90 |
}
|
99 |
}
|
| 91 |
}
|
100 |
}
|
| 92 |
|
101 |
|
| - |
|
102 |
//+--------------------------formatages de resultats -------------------------------------------+
|
| 93 |
public function retournerResultatFormate($resultat) {
|
103 |
public function retournerResultatFormate($resultat) {
|
| 94 |
if ((count($this->ressources)) == 0){
|
104 |
if ((count($this->ressources)) == 0) {
|
| 95 |
$table_retour_json=array();
|
- |
|
| 96 |
$table_retour_json['entete'] = $this->ajouterEnteteResultat();
|
- |
|
| 97 |
$table_retour_json['resultat'] = $this->formaterResultats($resultat);
|
105 |
$table_retour_json['resultat'] = $this->formaterResultats($resultat);
|
| 98 |
|
- |
|
| 99 |
} else {
|
106 |
} else {
|
| 100 |
$table_retour_json = $resultat[0];
|
107 |
$table_retour_json = $this->formaterResultatsInformationsBDNTnn($resultat);
|
| 101 |
}
|
108 |
}
|
| 102 |
return $table_retour_json;
|
109 |
return $table_retour_json;
|
| 103 |
}
|
110 |
}
|
| Line -... |
Line 111... |
| - |
|
111 |
|
| - |
|
112 |
public function formaterResultatsInformationsBDNTnn($resultat){
|
| - |
|
113 |
$resultat_json=array();
|
| - |
|
114 |
$resultat_json = $resultat[0];
|
| - |
|
115 |
if ($this->retour_format == 'max'){
|
| - |
|
116 |
if ($resultat_json['type_bio'] != ""){
|
| - |
|
117 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($resultat_json['type_bio']);
|
| - |
|
118 |
unset($resultat_json['type_bio']);
|
| - |
|
119 |
$resultat_json= array_merge($resultat_json,$tab_ontologie);
|
| - |
|
120 |
}
|
| - |
|
121 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
| - |
|
122 |
if ($resultat_json[$cle] != ""){
|
| - |
|
123 |
$tab_ontologie = $this->recupererOntologies($resultat_json[$cle], $cle);
|
| - |
|
124 |
unset($resultat_json[$cle]);
|
| - |
|
125 |
$resultat_json= array_merge($resultat_json,$tab_ontologie);
|
| - |
|
126 |
}
|
| - |
|
127 |
}
|
| - |
|
128 |
}
|
| - |
|
129 |
return $resultat_json;
|
| - |
|
130 |
}
|
| 104 |
|
131 |
|
| - |
|
132 |
public function formaterResultatsInformations($resultat) {
|
| - |
|
133 |
$resultat_json=array();
|
| 105 |
public function formaterResultats($resultat) {
|
134 |
$resultat_json['entete'] = $this->ajouterEnteteResultat();
|
| 106 |
foreach ($resultat as $tab) {
|
135 |
foreach ($resultat as $tab) {
|
| 107 |
$num = $tab['cle'];
|
136 |
$num = $tab['cle'];
|
| 108 |
unset($tab['cle']);
|
137 |
unset($tab['cle']);
|
| 109 |
foreach ($tab as $param => $valeur) {
|
138 |
foreach ($tab as $param => $valeur) {
|
| Line 112... |
Line 141... |
| 112 |
$resultat_json[$num]['href'] = $this->ajouterHref('ontologies', $num);
|
141 |
$resultat_json[$num]['href'] = $this->ajouterHref('ontologies', $num);
|
| 113 |
}
|
142 |
}
|
| 114 |
return $resultat_json;
|
143 |
return $resultat_json;
|
| 115 |
}
|
144 |
}
|
| 116 |
public function ajouterEnteteResultat() {
|
145 |
public function ajouterEnteteResultat() {
|
| 117 |
|
- |
|
| 118 |
$entete['depart'] = $this->limite_requete['depart'];
|
146 |
$entete['depart'] = $this->limite_requete['depart'];
|
| 119 |
$entete['limite'] = $this->limite_requete['limite'];
|
147 |
$entete['limite'] = $this->limite_requete['limite'];
|
| 120 |
$entete['total'] = $this->total_resultat;
|
148 |
$entete['total'] = $this->total_resultat;
|
| 121 |
$entete['version'] = $this->version_projet;
|
149 |
$entete['version'] = $this->version_projet;
|
| 122 |
$url = $this->formulerUrl($this->total_resultat, '/informations');
|
150 |
$url = $this->formulerUrl($this->total_resultat, '/informations');
|
| Line 124... |
Line 152... |
| 124 |
$entete['href.precedent'] = $url['precedent'];
|
152 |
$entete['href.precedent'] = $url['precedent'];
|
| 125 |
}
|
153 |
}
|
| 126 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
154 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
| 127 |
$entete['href.suivant'] = $url['suivant'];
|
155 |
$entete['href.suivant'] = $url['suivant'];
|
| 128 |
}
|
156 |
}
|
| 129 |
|
- |
|
| 130 |
return $entete;
|
157 |
return $entete;
|
| 131 |
}
|
158 |
}
|
| Line -... |
Line 159... |
| - |
|
159 |
|
| - |
|
160 |
|
| - |
|
161 |
//+--------------------------traitement ontologies -------------------------------------------+
|
| - |
|
162 |
public function recupererOntologies($valeur, $champs){
|
| - |
|
163 |
$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
|
| - |
|
164 |
$val = $this->consulterHref($url);
|
| - |
|
165 |
$resultat_json[$champs.'.libelle'] = $val->nom;
|
| - |
|
166 |
$resultat_json[$champs.'.code'] = $valeur;
|
| - |
|
167 |
$resultat_json[$champs.'.href'] = $url;
|
| - |
|
168 |
return $resultat_json;
|
| - |
|
169 |
}
|
| - |
|
170 |
|
| - |
|
171 |
|
| - |
|
172 |
|
| - |
|
173 |
public function recupererOntologiePrTypeBio($type_a_traiter){
|
| - |
|
174 |
$resultat_typeBio = "";
|
| - |
|
175 |
if ($type_a_traiter != ""){
|
| - |
|
176 |
$resultat_typeBio['type_bio.code'] = $type_a_traiter;
|
| - |
|
177 |
$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
|
| - |
|
178 |
foreach ($types_prim_sec as $cle => $tb){
|
| - |
|
179 |
$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
|
| - |
|
180 |
}
|
| - |
|
181 |
switch (count($types_sstypes)){
|
| - |
|
182 |
case 1 :
|
| - |
|
183 |
$types_sstypes = $types_sstypes['principal'];
|
| - |
|
184 |
break;
|
| - |
|
185 |
case 2 :
|
| - |
|
186 |
$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
|
| - |
|
187 |
break;
|
| - |
|
188 |
case 3 :
|
| - |
|
189 |
$types_sstypes = array_merge($types_sstypes['principal'],
|
| - |
|
190 |
$types_sstypes['secondaire'],
|
| - |
|
191 |
$types_sstypes['special']);
|
| - |
|
192 |
break;
|
| - |
|
193 |
default :
|
| - |
|
194 |
break;
|
| - |
|
195 |
|
| - |
|
196 |
}
|
| - |
|
197 |
|
| - |
|
198 |
foreach ($types_sstypes as $cle => $tb){
|
| - |
|
199 |
if (($cle == 'type.principal') || ($cle == 'type.secondaire')){
|
| - |
|
200 |
$url = $this->ajouterHref('ontologies','TB:'.urlencode(urlencode($tb)));
|
| - |
|
201 |
$val = $this->consulterHref($url);
|
| - |
|
202 |
$libelle[$cle]= $val->nom;
|
| - |
|
203 |
$detail[$cle]['libelle'] = $val->nom;
|
| - |
|
204 |
$detail[$cle]['code'] = $val->code;
|
| - |
|
205 |
$detail[$cle]['href'] = $url;
|
| - |
|
206 |
}
|
| - |
|
207 |
if ( ($cle == 'sous_type.principal') || ($cle == 'sous_type.secondaire') || ($cle == 'sous_type.special') ){
|
| - |
|
208 |
$i = 0;
|
| - |
|
209 |
foreach ($tb as $sstypes){
|
| - |
|
210 |
$url = $this->ajouterHref('ontologies','ssTT:'.urlencode(urlencode($sstypes)));
|
| - |
|
211 |
$val = $this->consulterHref($url);
|
| - |
|
212 |
$libelle[$cle]=$val->nom;
|
| - |
|
213 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
| - |
|
214 |
$detail[$cle][$i]['code'] = $val->code;
|
| - |
|
215 |
$detail[$cle][$i]['href'] = $url;
|
| - |
|
216 |
$i++;
|
| - |
|
217 |
}
|
| - |
|
218 |
}
|
| - |
|
219 |
}
|
| - |
|
220 |
$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
|
| - |
|
221 |
$resultat_typeBio['type_bio.detail'] = $detail;
|
| - |
|
222 |
}
|
| - |
|
223 |
return $resultat_typeBio;
|
| - |
|
224 |
}
|
| - |
|
225 |
|
| - |
|
226 |
|
| - |
|
227 |
public function formaterTypeBioPrLibelle($info){
|
| - |
|
228 |
$libelle = $info['type.principal']." ";
|
| - |
|
229 |
$libelle .= isset($info['sous_type.principal']) ? " (".$info['sous_type.principal'].") " : "";
|
| - |
|
230 |
$libelle .= isset($info['type.secondaire']) ? ", ".$info['type.secondaire']." " : "";
|
| - |
|
231 |
$libelle .= isset($info['sous_type.secondaire']) ? "(".$info['sous_type.secondaire'].") " : "";
|
| - |
|
232 |
$libelle .= isset($info['sous_type.special']) ? "(".$info['sous_type.special'].") " : "";
|
| - |
|
233 |
return $libelle;
|
| - |
|
234 |
}
|
| Line -... |
Line 235... |
| - |
|
235 |
|
| - |
|
236 |
|
| - |
|
237 |
public function separerTypesPrimairesSecondaires($type){
|
| - |
|
238 |
$types = array();
|
| - |
|
239 |
//séparation des principaux et des secondaires
|
| - |
|
240 |
if (( preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour) == 1 )){
|
| - |
|
241 |
$types['principal'] = $retour[1];
|
| - |
|
242 |
$types['secondaire'] = $retour[2];
|
| - |
|
243 |
if (isset($retour[3])){$types['special'] = $retour[3];}
|
| - |
|
244 |
}else {
|
| - |
|
245 |
$types['principal'] = $type;
|
| - |
|
246 |
}
|
| - |
|
247 |
return $types;
|
| - |
|
248 |
}
|
| - |
|
249 |
|
| - |
|
250 |
public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec){
|
| - |
|
251 |
$types = array();
|
| - |
|
252 |
if(( preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $type_a_traiter, $retour) == 1 )){
|
| - |
|
253 |
//recupère le type unique
|
| - |
|
254 |
|
| - |
|
255 |
$type = (isset($retour[3]) && ($typePrimOuSec != 'special') ) ? $retour[3] : $retour[1] ;
|
| - |
|
256 |
$types['type.'.$typePrimOuSec]= $type;
|
| - |
|
257 |
//recupère le ou les sous-types
|
| - |
|
258 |
if ((isset($retour[3]) && ($typePrimOuSec == 'special') )){
|
| - |
|
259 |
$ss_types[0] = (isset($retour[3]) && ($typePrimOuSec == 'special') ) ? $retour[3] : "" ;
|
| - |
|
260 |
}elseif(isset($retour[2]) && ($retour[2] != "")){
|
| - |
|
261 |
$ss_types[0]= (isset($retour[2]) && ($retour[2] != "") ) ? $retour[2] : "" ;
|
| - |
|
262 |
}
|
| - |
|
263 |
if (isset($ss_types[0])){
|
| - |
|
264 |
if (( preg_match("/\-/", $ss_types[0])) == 1 ){
|
| - |
|
265 |
$ss_types = preg_split("/\-/", $ss_types[0]);
|
| - |
|
266 |
}
|
| - |
|
267 |
for($i = 0 ; $i < count($ss_types); $i++){
|
| - |
|
268 |
$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
|
| - |
|
269 |
}
|
| - |
|
270 |
}
|
| - |
|
271 |
}
|
| - |
|
272 |
|
| Line 132... |
Line 273... |
| 132 |
|
273 |
return $types;
|
| Line 133... |
Line 274... |
| 133 |
|
274 |
}
|
| 134 |
|
275 |
|
| 135 |
|
276 |
|
| 136 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
277 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|