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