452 |
mathilde |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Classe InformationsBaseflor.php permet de faire des requetes de baseflor en fonction d'un référentiel
|
499 |
jpm |
5 |
*( BDTFX, BDAFX, BDBFX ) et d'un numéro nomenclatural ( différent de 0 ).
|
452 |
mathilde |
6 |
* fin d'url possibles :
|
|
|
7 |
* /informations/#bdnt.nn:#num_nomen --> retourne tous les champs pour un BDNT et un num_nomen
|
|
|
8 |
* /informations/#bdnt.nn:#num_nomen?champs=description --> retourne champs description pour un BDNT et un num_nomen
|
|
|
9 |
* /informations/#bdnt.nn:#num_nomen?champs=ecologie --> retourne champs ecologiques pour un BDNT et un num_nomen
|
580 |
mathilde |
10 |
* /informations/#bdnt.nn:#num_nomen/relations/catminat --> donne les num nomen et les bdnt pour tous
|
|
|
11 |
* les taxons qui ont le même code catminat ( code milieu ) que celui entré
|
452 |
mathilde |
12 |
*
|
|
|
13 |
* Encodage en entrée : utf8
|
|
|
14 |
* Encodage en sortie : utf8
|
|
|
15 |
* @package eflore-projets
|
|
|
16 |
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
|
|
|
17 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
|
|
18 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
19 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
20 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
21 |
* @version 1.0
|
585 |
mathilde |
22 |
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
|
452 |
mathilde |
23 |
*/
|
|
|
24 |
|
|
|
25 |
class InformationsBaseflor extends Commun{
|
499 |
jpm |
26 |
|
452 |
mathilde |
27 |
protected $table = "";
|
|
|
28 |
private $format_reponse = 'informations';
|
|
|
29 |
private $retour_format = 'max';
|
|
|
30 |
private $champs_ontologiques = array();
|
|
|
31 |
protected $serviceNom = 'informations';
|
525 |
mathilde |
32 |
private $Bdd;
|
548 |
mathilde |
33 |
private $requete_condition = "";
|
|
|
34 |
private $champs_recherches = '*';
|
|
|
35 |
private $resultat_json;
|
579 |
mathilde |
36 |
private $nb_ressources;
|
|
|
37 |
protected $limite_requete = array( 'depart' => 0, 'limite' => 10);
|
525 |
mathilde |
38 |
|
499 |
jpm |
39 |
|
452 |
mathilde |
40 |
public function consulter($ressources, $parametres) {
|
|
|
41 |
$this->ressources = $ressources;
|
|
|
42 |
$this->parametres = $parametres;
|
579 |
mathilde |
43 |
$this->nb_ressources = count($ressources);
|
585 |
mathilde |
44 |
|
452 |
mathilde |
45 |
$this->traiterParametres();
|
548 |
mathilde |
46 |
$this->definirTables();
|
518 |
mathilde |
47 |
$this->traiterRessources();
|
452 |
mathilde |
48 |
$resultats = null;
|
499 |
jpm |
49 |
foreach ($this->table_version as $version) {
|
548 |
mathilde |
50 |
$this->table = $version;
|
585 |
mathilde |
51 |
$requete = $this->assemblerLaRequete();
|
525 |
mathilde |
52 |
$resultat = $this->Bdd->recupererTous($requete);
|
|
|
53 |
$versionResultat = $this->analyserResultat($resultat);
|
452 |
mathilde |
54 |
if (count($this->table_version) > 1) {
|
|
|
55 |
$resultats[$version] = $versionResultat;
|
|
|
56 |
} else {
|
|
|
57 |
$resultats = $versionResultat;
|
|
|
58 |
}
|
|
|
59 |
}
|
499 |
jpm |
60 |
return $resultats;
|
452 |
mathilde |
61 |
}
|
499 |
jpm |
62 |
|
525 |
mathilde |
63 |
public function __construct(Conteneur $Conteneur) {
|
|
|
64 |
$this->Bdd = $Conteneur->getBdd();
|
|
|
65 |
}
|
|
|
66 |
|
548 |
mathilde |
67 |
|
525 |
mathilde |
68 |
public function analyserResultat($resultat) {
|
452 |
mathilde |
69 |
$versionResultat = null;
|
|
|
70 |
if ($resultat == '') {
|
|
|
71 |
$message = 'La requête SQL formée comporte une erreur!';
|
|
|
72 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
73 |
throw new Exception($message, $code);
|
|
|
74 |
} elseif ($resultat) {
|
525 |
mathilde |
75 |
$versionResultat = $this->retournerResultatFormate($resultat);
|
499 |
jpm |
76 |
}
|
452 |
mathilde |
77 |
return $versionResultat;
|
|
|
78 |
}
|
499 |
jpm |
79 |
|
|
|
80 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
452 |
mathilde |
81 |
public function traiterParametres() {
|
|
|
82 |
if (isset($this->parametres) && !empty($this->parametres)) {
|
|
|
83 |
foreach ($this->parametres as $param => $valeur) {
|
|
|
84 |
switch ($param) {
|
516 |
mathilde |
85 |
case 'categorie' :
|
761 |
raphael |
86 |
if($this->nb_ressources != 1 ) {
|
|
|
87 |
$e = "Nombre de ressource != 1 pour informations/#id/relations/catminat";
|
|
|
88 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
if ($valeur == "description") {
|
548 |
mathilde |
92 |
$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
|
499 |
jpm |
93 |
." sexualite, ordre_maturation, "
|
|
|
94 |
."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
|
|
|
95 |
."form_vegetale ";
|
548 |
mathilde |
96 |
$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
|
499 |
jpm |
97 |
"OR sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
|
|
|
98 |
"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
|
|
|
99 |
"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
|
761 |
raphael |
100 |
} elseif ($valeur == "ecologie") {
|
548 |
mathilde |
101 |
$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
|
499 |
jpm |
102 |
." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
|
517 |
mathilde |
103 |
." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
|
|
|
104 |
." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
|
|
|
105 |
." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
|
548 |
mathilde |
106 |
$this->requete_condition[] = "( ve_lumiere != '' OR ve_temperature != '' ".
|
466 |
mathilde |
107 |
"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
|
|
|
108 |
"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
|
|
|
109 |
"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
|
499 |
jpm |
110 |
"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
|
|
|
111 |
} else {
|
579 |
mathilde |
112 |
$e = "Valeur de paramètre inconnue pour 'categorie'. Ce paramètre n'est pas autorisé pour informations/#id/relations/catminat";
|
525 |
mathilde |
113 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
452 |
mathilde |
114 |
}
|
|
|
115 |
break;
|
|
|
116 |
case 'retour.format' :
|
579 |
mathilde |
117 |
if ($valeur == 'min' || $valeur == 'max' && $this->nb_ressources == 1) {
|
517 |
mathilde |
118 |
$this->retour_format = $valeur;
|
579 |
mathilde |
119 |
|
517 |
mathilde |
120 |
} else {
|
579 |
mathilde |
121 |
$e = "Valeur de paramètre inconnue pour 'retour.format'. Ce paramètre n'est pas autorisé pour informations/#id/relations/catminat";
|
525 |
mathilde |
122 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
517 |
mathilde |
123 |
}
|
579 |
mathilde |
124 |
break;
|
|
|
125 |
case 'navigation.depart' :
|
|
|
126 |
$this->definirNavigationDepart($valeur);
|
|
|
127 |
break;
|
|
|
128 |
case 'navigation.limite' :
|
|
|
129 |
$this->definirNavigationLimite($valeur);
|
|
|
130 |
break;
|
518 |
mathilde |
131 |
case 'version.projet' :
|
|
|
132 |
$this->traiterVersion($valeur);
|
|
|
133 |
break;
|
452 |
mathilde |
134 |
default :
|
|
|
135 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
|
|
136 |
.$param.' " n\'existe pas.';
|
525 |
mathilde |
137 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
|
|
138 |
break;
|
452 |
mathilde |
139 |
}
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
517 |
mathilde |
143 |
|
|
|
144 |
|
452 |
mathilde |
145 |
|
|
|
146 |
public function traiterRessources() {
|
525 |
mathilde |
147 |
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
|
579 |
mathilde |
148 |
$id = $retour[2];
|
|
|
149 |
$ref = $retour[1];
|
|
|
150 |
if ($ref == 'bdtfx' || $ref == 'bdafx' || $ref == 'bdbfx') {
|
|
|
151 |
if($this->nb_ressources == 1) {
|
|
|
152 |
$this->requete_condition[] = "num_nomen = ".$id." AND BDNT = '".strtoupper($ref)."' ";
|
|
|
153 |
} else {
|
|
|
154 |
$this->definirParametresRequeteRelations($ref, $id);
|
|
|
155 |
}
|
|
|
156 |
} else {
|
|
|
157 |
$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
|
|
|
158 |
.$ref.' " n\'existe pas.';
|
|
|
159 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
499 |
jpm |
160 |
}
|
|
|
161 |
|
516 |
mathilde |
162 |
} else {
|
|
|
163 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.';
|
525 |
mathilde |
164 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
585 |
mathilde |
165 |
|
452 |
mathilde |
166 |
}
|
579 |
mathilde |
167 |
|
452 |
mathilde |
168 |
}
|
518 |
mathilde |
169 |
|
579 |
mathilde |
170 |
function definirParametresRequeteRelations($ref, $id){
|
|
|
171 |
if ($this->ressources[1] == 'relations'){
|
|
|
172 |
switch ($this->ressources[2]) {
|
|
|
173 |
case 'catminat' :
|
|
|
174 |
$this->requete_condition[] = "catminat_code = ( SELECT catminat_code from ".$this->table_version[0]." WHERE "
|
592 |
mathilde |
175 |
." num_nomen = ".$id." AND BDNT = '".$ref. "' ) AND num_nomen != ".$id." ";
|
580 |
mathilde |
176 |
$this->champs_recherches = " catminat_code, num_nomen, BDNT, idiotaxon ";
|
579 |
mathilde |
177 |
break;
|
|
|
178 |
default :
|
|
|
179 |
$e = 'Erreur dans l\'url de votre requête : </br> Le type de relation " '
|
|
|
180 |
.$this->ressources[2].' " n\'existe pas.';
|
|
|
181 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
|
|
182 |
break;
|
|
|
183 |
}
|
|
|
184 |
} else {
|
|
|
185 |
$e = 'Erreur dans l\'url de votre requête : </br> Le type de ressources " '
|
|
|
186 |
.$this->ressources[1].' " n\'existe pas.';
|
|
|
187 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
|
518 |
mathilde |
192 |
//+++------------------------------traitement des versions----------------------------------------++
|
|
|
193 |
|
|
|
194 |
public function traiterVersion($valeur) {
|
579 |
mathilde |
195 |
if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '+') {
|
518 |
mathilde |
196 |
$this->version_projet = $valeur;
|
579 |
mathilde |
197 |
} elseif ($valeur == '*') {
|
|
|
198 |
$this->version_projet = ($this->nb_ressources == 1) ? $valeur : '+' ;
|
518 |
mathilde |
199 |
} else {
|
|
|
200 |
$e = "Erreur : La version est inconnue.";
|
525 |
mathilde |
201 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
518 |
mathilde |
202 |
}
|
525 |
mathilde |
203 |
|
518 |
mathilde |
204 |
}
|
|
|
205 |
|
548 |
mathilde |
206 |
public function definirTables() {
|
518 |
mathilde |
207 |
$table_num_version = $this->recupererVersionDisponible();
|
|
|
208 |
$prefixe_table = config::get('bdd_table');
|
|
|
209 |
if ( in_array($this->version_projet,$table_num_version) ) {
|
|
|
210 |
$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
|
|
|
211 |
} elseif ($this->version_projet == '+') {
|
|
|
212 |
$derniere_version = $table_num_version[count($table_num_version) - 1];
|
|
|
213 |
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
|
|
|
214 |
} elseif ($this->version_projet == '*') {
|
|
|
215 |
foreach ($table_num_version as $num_version) {
|
|
|
216 |
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
|
|
|
217 |
}
|
|
|
218 |
} else {
|
|
|
219 |
$e = "Erreur : La version est inconnue.";
|
525 |
mathilde |
220 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
518 |
mathilde |
221 |
}
|
|
|
222 |
}
|
|
|
223 |
|
452 |
mathilde |
224 |
//+--------------------------formatages de resultats -------------------------------------------+
|
525 |
mathilde |
225 |
|
452 |
mathilde |
226 |
public function retournerResultatFormate($resultat) {
|
499 |
jpm |
227 |
$resultat_json = $resultat[0];
|
|
|
228 |
if ($this->retour_format == 'max'){
|
579 |
mathilde |
229 |
if ($this->nb_ressources == 1) {
|
|
|
230 |
if ($this->parametres['categorie'] == 'ecologie') {
|
|
|
231 |
$this->formaterResultatsChampsEcologie($resultat_json);
|
|
|
232 |
} elseif ($this->parametres['categorie'] == 'description') {
|
|
|
233 |
$this->formaterResultatsChampsDescription($resultat_json);
|
|
|
234 |
}else {
|
|
|
235 |
$this->formaterResultatsTousChamps($resultat_json);
|
|
|
236 |
}
|
|
|
237 |
} else {
|
|
|
238 |
$this->formaterResultatsRelations($resultat);
|
499 |
jpm |
239 |
}
|
553 |
mathilde |
240 |
} else {
|
|
|
241 |
$this->resultat_json = $resultat_json;
|
452 |
mathilde |
242 |
}
|
548 |
mathilde |
243 |
return $this->resultat_json;
|
452 |
mathilde |
244 |
}
|
579 |
mathilde |
245 |
|
|
|
246 |
public function formaterResultatsRelations($resultat) {
|
|
|
247 |
$this->resultat_json['entete'] = $this->ajouterEnteteResultat();
|
|
|
248 |
$resultat_json = array();
|
|
|
249 |
foreach ($resultat as $cle => $res){
|
|
|
250 |
$resultat_json[$cle] = $res ;
|
|
|
251 |
$resultat_json[$cle]['href'] = $this->ajouterHref('informations',strtolower($res['BDNT']).".nn:".$res['num_nomen']);
|
|
|
252 |
}
|
|
|
253 |
$this->resultat_json['resultat'] = $resultat_json;
|
|
|
254 |
}
|
|
|
255 |
|
647 |
aurelien |
256 |
public function ajouterEnteteResultat() {
|
579 |
mathilde |
257 |
$entete['depart'] = $this->limite_requete['depart'];
|
|
|
258 |
$entete['limite'] = $this->limite_requete['limite'];
|
|
|
259 |
$entete['total'] = $this->total_resultat;
|
|
|
260 |
$entete['version'] = $this->version_projet;
|
592 |
mathilde |
261 |
if ($this->limite_requete['limite'] != '*') {
|
|
|
262 |
$url = $this->formulerUrl($this->total_resultat, '/informations/'.$this->ressources[0].'/relations/catminat');
|
|
|
263 |
if (isset($url['precedent']) && $url['precedent'] != '') {
|
|
|
264 |
$entete['href.precedent'] = $url['precedent'];
|
|
|
265 |
}
|
|
|
266 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
|
|
267 |
$entete['href.suivant'] = $url['suivant'];
|
|
|
268 |
}
|
579 |
mathilde |
269 |
}
|
|
|
270 |
return $entete;
|
|
|
271 |
}
|
499 |
jpm |
272 |
|
452 |
mathilde |
273 |
public function formaterResultatsTousChamps($resultat) {
|
548 |
mathilde |
274 |
$this->resultat_json = $resultat;
|
|
|
275 |
$this->traiterTypeBio();
|
617 |
mathilde |
276 |
$graphique_presence = $this->traiterEcologie() ;
|
548 |
mathilde |
277 |
if ($graphique_presence) {
|
617 |
mathilde |
278 |
$graphique = $this->ajouterLiensGraphique($graphique_presence);
|
|
|
279 |
}
|
548 |
mathilde |
280 |
}
|
|
|
281 |
|
|
|
282 |
public function formaterResultatsChampsEcologie($resultat) {
|
|
|
283 |
$this->resultat_json = $resultat;
|
617 |
mathilde |
284 |
$graphique_presence = $this->traiterEcologie() ;
|
548 |
mathilde |
285 |
if ($graphique_presence) {
|
617 |
mathilde |
286 |
$graphique = $this->ajouterLiensGraphique($graphique_presence);
|
452 |
mathilde |
287 |
}
|
548 |
mathilde |
288 |
}
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
public function formaterResultatsChampsDescription($resultat) {
|
|
|
292 |
$this->resultat_json = $resultat;
|
|
|
293 |
$this->traiterTypeBio();
|
|
|
294 |
}
|
|
|
295 |
|
617 |
mathilde |
296 |
//vérifie la présence de données écologiques pour les graphiques et récupère leur ontologie
|
|
|
297 |
public function traiterEcologie() {
|
548 |
mathilde |
298 |
$donnees_presence = false;
|
452 |
mathilde |
299 |
$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
|
|
|
300 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
548 |
mathilde |
301 |
if ($this->resultat_json[$cle] != ""){
|
617 |
mathilde |
302 |
$donnees_presence[$this->getNomGraphique($valeur)] = true;
|
548 |
mathilde |
303 |
$this->recupererOntologies($this->resultat_json[$cle], $cle);
|
|
|
304 |
unset($this->resultat_json[$cle]);
|
452 |
mathilde |
305 |
}
|
|
|
306 |
}
|
548 |
mathilde |
307 |
return $donnees_presence;
|
452 |
mathilde |
308 |
}
|
548 |
mathilde |
309 |
|
617 |
mathilde |
310 |
//donne le nom du graphique correspondant à un champ écologique
|
|
|
311 |
public function getNomGraphique($code_ecolo) {
|
|
|
312 |
$graphique = null;
|
|
|
313 |
if (in_array($code_ecolo, explode(',',Config::get('Paramètres.climat')))) {
|
|
|
314 |
$graphique = 'climat';
|
|
|
315 |
} elseif (in_array($code_ecolo, explode(',', Config::get('Paramètres.sol')) )) {
|
|
|
316 |
$graphique = 'sol';
|
|
|
317 |
}
|
|
|
318 |
return $graphique;
|
|
|
319 |
}
|
|
|
320 |
|
548 |
mathilde |
321 |
public function traiterTypeBio() {
|
|
|
322 |
if ($this->resultat_json['type_bio'] != ""){
|
|
|
323 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
|
|
|
324 |
unset($this->resultat_json['type_bio']);
|
|
|
325 |
$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
|
452 |
mathilde |
326 |
}
|
|
|
327 |
}
|
499 |
jpm |
328 |
|
617 |
mathilde |
329 |
public function ajouterLiensGraphique($graphique_presence) {
|
|
|
330 |
if ($graphique_presence['climat']) {
|
|
|
331 |
$this->resultat_json['graphique_climat']['libelle'] = 'climat';
|
|
|
332 |
$this->resultat_json['graphique_climat']['href'] =
|
548 |
mathilde |
333 |
$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
617 |
mathilde |
334 |
|
|
|
335 |
}
|
|
|
336 |
if ($graphique_presence['sol']) {
|
|
|
337 |
$this->resultat_json['graphique_sol']['libelle'] = 'sol';
|
|
|
338 |
$this->resultat_json['graphique_sol']['href'] =
|
548 |
mathilde |
339 |
$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
617 |
mathilde |
340 |
}
|
452 |
mathilde |
341 |
}
|
517 |
mathilde |
342 |
|
|
|
343 |
|
452 |
mathilde |
344 |
//+--------------------------traitement ontologies -------------------------------------------+
|
518 |
mathilde |
345 |
|
452 |
mathilde |
346 |
public function recupererOntologies($valeur, $champs){
|
518 |
mathilde |
347 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
|
|
348 |
'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
|
452 |
mathilde |
349 |
$val = $this->consulterHref($url);
|
548 |
mathilde |
350 |
$this->resultat_json[$champs.'.libelle'] = $val->nom;
|
|
|
351 |
$this->resultat_json[$champs.'.code'] = $valeur;
|
|
|
352 |
$this->resultat_json[$champs.'.href'] = $url;
|
452 |
mathilde |
353 |
}
|
548 |
mathilde |
354 |
|
|
|
355 |
//+-------------ontologie pour le champs type biologique (lire le .txt)---+
|
499 |
jpm |
356 |
|
452 |
mathilde |
357 |
public function recupererOntologiePrTypeBio($type_a_traiter){
|
|
|
358 |
$resultat_typeBio = "";
|
499 |
jpm |
359 |
if ($type_a_traiter != "") {
|
452 |
mathilde |
360 |
$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
|
548 |
mathilde |
361 |
$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
|
|
|
362 |
$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
|
|
|
363 |
}
|
|
|
364 |
return $resultat_typeBio;
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
|
|
|
368 |
$types_sstypes = '';
|
|
|
369 |
foreach ($types_prim_sec as $cle => $tb) {
|
|
|
370 |
$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
|
|
|
371 |
}
|
|
|
372 |
switch (count($types_sstypes)) {
|
|
|
373 |
case 1 :
|
|
|
374 |
$types_sstypes = $types_sstypes['principal'];
|
|
|
375 |
break;
|
|
|
376 |
case 2 :
|
|
|
377 |
$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
|
|
|
378 |
break;
|
|
|
379 |
}
|
|
|
380 |
return $types_sstypes;
|
|
|
381 |
}
|
|
|
382 |
|
499 |
jpm |
383 |
|
548 |
mathilde |
384 |
public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
|
|
|
385 |
$resultat_typeBio['type_bio.code'] = $type_a_traiter;
|
|
|
386 |
foreach ($types_sstypes as $cle => $tb) {
|
|
|
387 |
if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
|
|
|
388 |
$i = 0;
|
|
|
389 |
foreach ($tb as $types) {
|
518 |
mathilde |
390 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
548 |
mathilde |
391 |
'/ontologies/TB:'.urlencode(urlencode($types));
|
452 |
mathilde |
392 |
$val = $this->consulterHref($url);
|
550 |
mathilde |
393 |
$libelle[$cle][$i]= $val->nom;
|
549 |
mathilde |
394 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
|
|
395 |
$detail[$cle][$i]['code'] = $val->code;
|
|
|
396 |
$detail[$cle][$i]['href'] = $url;
|
|
|
397 |
$i++;
|
452 |
mathilde |
398 |
}
|
548 |
mathilde |
399 |
}
|
|
|
400 |
if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
|
|
|
401 |
$i = 0;
|
|
|
402 |
foreach ($tb as $sstypes) {
|
|
|
403 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
|
|
404 |
'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
|
|
|
405 |
$val = $this->consulterHref($url);
|
550 |
mathilde |
406 |
$libelle[$cle][$i]=$val->nom;
|
548 |
mathilde |
407 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
|
|
408 |
$detail[$cle][$i]['code'] = $val->code;
|
|
|
409 |
$detail[$cle][$i]['href'] = $url;
|
|
|
410 |
$i++;
|
452 |
mathilde |
411 |
}
|
|
|
412 |
}
|
|
|
413 |
}
|
550 |
mathilde |
414 |
//var_dump($libelle); exit;
|
548 |
mathilde |
415 |
$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
|
|
|
416 |
$resultat_typeBio['type_bio.detail'] = $detail;
|
452 |
mathilde |
417 |
return $resultat_typeBio;
|
|
|
418 |
}
|
548 |
mathilde |
419 |
|
|
|
420 |
|
549 |
mathilde |
421 |
|
499 |
jpm |
422 |
public function formaterTypeBioPrLibelle($info) {
|
552 |
mathilde |
423 |
$libelle = implode(', ',$info['type.principal'])." ";
|
|
|
424 |
$libelle .= isset($info['sous_type.principal']) ? " (".implode(', ',$info['sous_type.principal']).") " : "";
|
|
|
425 |
$libelle .= isset($info['type.secondaire']) ? ", ".implode(', ',$info['type.secondaire'])." " : "";
|
|
|
426 |
$libelle .= isset($info['sous_type.secondaire']) ? "(".implode(', ',$info['sous_type.secondaire']).") " : "";
|
452 |
mathilde |
427 |
return $libelle;
|
|
|
428 |
}
|
|
|
429 |
|
548 |
mathilde |
430 |
//séparation des principaux et des secondaires
|
499 |
jpm |
431 |
public function separerTypesPrimairesSecondaires($type) {
|
548 |
mathilde |
432 |
$types = array();
|
|
|
433 |
if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
|
|
|
434 |
$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
|
452 |
mathilde |
435 |
$types['secondaire'] = $retour[2];
|
499 |
jpm |
436 |
} else {
|
452 |
mathilde |
437 |
$types['principal'] = $type;
|
|
|
438 |
}
|
|
|
439 |
return $types;
|
|
|
440 |
}
|
499 |
jpm |
441 |
|
548 |
mathilde |
442 |
|
499 |
jpm |
443 |
public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
|
452 |
mathilde |
444 |
$types = array();
|
548 |
mathilde |
445 |
if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
|
|
|
446 |
//type
|
|
|
447 |
$type = array();
|
|
|
448 |
$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
|
549 |
mathilde |
449 |
$type = explode(",", $type[0]);
|
548 |
mathilde |
450 |
for ($i = 0 ; $i < count($type); $i++) {
|
|
|
451 |
$types['type.'.$typePrimOuSec][$i] = $type[$i];
|
|
|
452 |
}
|
|
|
453 |
//sous types
|
|
|
454 |
$ss_types = array();
|
|
|
455 |
if (isset($retour[2]) && $retour[2] != '') {
|
|
|
456 |
$ss_types[0] = $retour[2] ;
|
549 |
mathilde |
457 |
$ss_types = explode("-", $ss_types[0]);
|
499 |
jpm |
458 |
for ($i = 0 ; $i < count($ss_types); $i++) {
|
548 |
mathilde |
459 |
$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
|
|
|
460 |
}
|
|
|
461 |
}
|
452 |
mathilde |
462 |
}
|
|
|
463 |
return $types;
|
548 |
mathilde |
464 |
}
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
|
|
471 |
|
|
|
472 |
public function assemblerLaRequete() {
|
|
|
473 |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
|
579 |
mathilde |
474 |
.$this->retournerRequeteCondition().' ';
|
592 |
mathilde |
475 |
if ($this->nb_ressources != 1 ) {
|
579 |
mathilde |
476 |
$requete .= $this->delimiterResultatsRequete();
|
592 |
mathilde |
477 |
}
|
548 |
mathilde |
478 |
return $requete;
|
452 |
mathilde |
479 |
}
|
548 |
mathilde |
480 |
|
579 |
mathilde |
481 |
public function calculerTotalResultat() {
|
|
|
482 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '.$this->retournerRequeteCondition();
|
|
|
483 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
484 |
if ($res) {
|
|
|
485 |
$this->total_resultat = $res['nombre'];
|
|
|
486 |
} else {
|
|
|
487 |
$this->total_resultat = 0;
|
|
|
488 |
$e = 'Données introuvables dans la base';
|
|
|
489 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
490 |
}
|
|
|
491 |
}
|
548 |
mathilde |
492 |
|
579 |
mathilde |
493 |
public function delimiterResultatsRequete() {
|
|
|
494 |
$this->calculerTotalResultat();
|
|
|
495 |
$requete_limite = '';
|
592 |
mathilde |
496 |
if ($this->limite_requete['limite'] != '*') {
|
|
|
497 |
if ( ($this->limite_requete['depart'] <= $this->total_resultat)){
|
|
|
498 |
if (($this->limite_requete['limite'] + $this->limite_requete['depart'] )
|
|
|
499 |
< $this->total_resultat ){
|
|
|
500 |
$requete_limite = 'LIMIT '.$this->limite_requete['depart'].', '
|
|
|
501 |
.$this->limite_requete['limite'];
|
|
|
502 |
}
|
|
|
503 |
} else {
|
|
|
504 |
$e = "Erreur : la valeur pour le paramètre navigation.départ est supérieure".
|
|
|
505 |
" au nombre total de résultats.";
|
|
|
506 |
throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
|
579 |
mathilde |
507 |
}
|
|
|
508 |
}
|
|
|
509 |
return $requete_limite;
|
|
|
510 |
}
|
548 |
mathilde |
511 |
|
579 |
mathilde |
512 |
|
|
|
513 |
|
548 |
mathilde |
514 |
public function retournerRequeteCondition() {
|
|
|
515 |
$condition = '';
|
|
|
516 |
if (empty($this->requete_condition) == false) {
|
|
|
517 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
518 |
}
|
|
|
519 |
return $condition;
|
|
|
520 |
}
|
499 |
jpm |
521 |
|
|
|
522 |
|
525 |
mathilde |
523 |
|
452 |
mathilde |
524 |
}
|
|
|
525 |
?>
|