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 |
|
|
|
251 |
public function ajouterEnteteResultat($id) {
|
|
|
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();
|
|
|
271 |
$graphique_presence = $this->traiterOntologieEcologie() ;
|
|
|
272 |
if ($graphique_presence) {
|
|
|
273 |
$graphique = $this->ajouterLiensGraphique();
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public function formaterResultatsChampsEcologie($resultat) {
|
|
|
278 |
$this->resultat_json = $resultat;
|
|
|
279 |
$graphique_presence = $this->traiterOntologieEcologie() ;
|
|
|
280 |
if ($graphique_presence) {
|
|
|
281 |
$graphique = $this->ajouterLiensGraphique();
|
452 |
mathilde |
282 |
}
|
548 |
mathilde |
283 |
}
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
public function formaterResultatsChampsDescription($resultat) {
|
|
|
287 |
$this->resultat_json = $resultat;
|
|
|
288 |
$this->traiterTypeBio();
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
public function traiterOntologieEcologie() {
|
|
|
292 |
$donnees_presence = false;
|
452 |
mathilde |
293 |
$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
|
|
|
294 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
548 |
mathilde |
295 |
if ($this->resultat_json[$cle] != ""){
|
|
|
296 |
$donnees_presence = true;
|
|
|
297 |
$this->recupererOntologies($this->resultat_json[$cle], $cle);
|
|
|
298 |
unset($this->resultat_json[$cle]);
|
452 |
mathilde |
299 |
}
|
|
|
300 |
}
|
548 |
mathilde |
301 |
return $donnees_presence;
|
452 |
mathilde |
302 |
}
|
548 |
mathilde |
303 |
|
|
|
304 |
public function traiterTypeBio() {
|
|
|
305 |
if ($this->resultat_json['type_bio'] != ""){
|
|
|
306 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
|
|
|
307 |
unset($this->resultat_json['type_bio']);
|
|
|
308 |
$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
|
452 |
mathilde |
309 |
}
|
|
|
310 |
}
|
499 |
jpm |
311 |
|
548 |
mathilde |
312 |
public function ajouterLiensGraphique() {
|
|
|
313 |
$this->resultat_json['graphique_climat']['libelle'] = 'climat';
|
|
|
314 |
$this->resultat_json['graphique_climat']['href'] =
|
|
|
315 |
$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
|
|
316 |
$this->resultat_json['graphique_sol']['libelle'] = 'sol';
|
|
|
317 |
$this->resultat_json['graphique_sol']['href'] =
|
|
|
318 |
$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
452 |
mathilde |
319 |
}
|
517 |
mathilde |
320 |
|
|
|
321 |
|
452 |
mathilde |
322 |
//+--------------------------traitement ontologies -------------------------------------------+
|
518 |
mathilde |
323 |
|
452 |
mathilde |
324 |
public function recupererOntologies($valeur, $champs){
|
518 |
mathilde |
325 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
|
|
326 |
'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
|
452 |
mathilde |
327 |
$val = $this->consulterHref($url);
|
548 |
mathilde |
328 |
$this->resultat_json[$champs.'.libelle'] = $val->nom;
|
|
|
329 |
$this->resultat_json[$champs.'.code'] = $valeur;
|
|
|
330 |
$this->resultat_json[$champs.'.href'] = $url;
|
452 |
mathilde |
331 |
}
|
548 |
mathilde |
332 |
|
|
|
333 |
//+-------------ontologie pour le champs type biologique (lire le .txt)---+
|
499 |
jpm |
334 |
|
452 |
mathilde |
335 |
public function recupererOntologiePrTypeBio($type_a_traiter){
|
|
|
336 |
$resultat_typeBio = "";
|
499 |
jpm |
337 |
if ($type_a_traiter != "") {
|
452 |
mathilde |
338 |
$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
|
548 |
mathilde |
339 |
$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
|
|
|
340 |
$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
|
|
|
341 |
}
|
|
|
342 |
return $resultat_typeBio;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
|
|
|
346 |
$types_sstypes = '';
|
|
|
347 |
foreach ($types_prim_sec as $cle => $tb) {
|
|
|
348 |
$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
|
|
|
349 |
}
|
|
|
350 |
switch (count($types_sstypes)) {
|
|
|
351 |
case 1 :
|
|
|
352 |
$types_sstypes = $types_sstypes['principal'];
|
|
|
353 |
break;
|
|
|
354 |
case 2 :
|
|
|
355 |
$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
|
|
|
356 |
break;
|
|
|
357 |
}
|
|
|
358 |
return $types_sstypes;
|
|
|
359 |
}
|
|
|
360 |
|
499 |
jpm |
361 |
|
548 |
mathilde |
362 |
public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
|
|
|
363 |
$resultat_typeBio['type_bio.code'] = $type_a_traiter;
|
|
|
364 |
foreach ($types_sstypes as $cle => $tb) {
|
|
|
365 |
if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
|
|
|
366 |
$i = 0;
|
|
|
367 |
foreach ($tb as $types) {
|
518 |
mathilde |
368 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
548 |
mathilde |
369 |
'/ontologies/TB:'.urlencode(urlencode($types));
|
452 |
mathilde |
370 |
$val = $this->consulterHref($url);
|
550 |
mathilde |
371 |
$libelle[$cle][$i]= $val->nom;
|
549 |
mathilde |
372 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
|
|
373 |
$detail[$cle][$i]['code'] = $val->code;
|
|
|
374 |
$detail[$cle][$i]['href'] = $url;
|
|
|
375 |
$i++;
|
452 |
mathilde |
376 |
}
|
548 |
mathilde |
377 |
}
|
|
|
378 |
if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
|
|
|
379 |
$i = 0;
|
|
|
380 |
foreach ($tb as $sstypes) {
|
|
|
381 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
|
|
382 |
'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
|
|
|
383 |
$val = $this->consulterHref($url);
|
550 |
mathilde |
384 |
$libelle[$cle][$i]=$val->nom;
|
548 |
mathilde |
385 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
|
|
386 |
$detail[$cle][$i]['code'] = $val->code;
|
|
|
387 |
$detail[$cle][$i]['href'] = $url;
|
|
|
388 |
$i++;
|
452 |
mathilde |
389 |
}
|
|
|
390 |
}
|
|
|
391 |
}
|
550 |
mathilde |
392 |
//var_dump($libelle); exit;
|
548 |
mathilde |
393 |
$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
|
|
|
394 |
$resultat_typeBio['type_bio.detail'] = $detail;
|
452 |
mathilde |
395 |
return $resultat_typeBio;
|
|
|
396 |
}
|
548 |
mathilde |
397 |
|
|
|
398 |
|
549 |
mathilde |
399 |
|
499 |
jpm |
400 |
public function formaterTypeBioPrLibelle($info) {
|
552 |
mathilde |
401 |
$libelle = implode(', ',$info['type.principal'])." ";
|
|
|
402 |
$libelle .= isset($info['sous_type.principal']) ? " (".implode(', ',$info['sous_type.principal']).") " : "";
|
|
|
403 |
$libelle .= isset($info['type.secondaire']) ? ", ".implode(', ',$info['type.secondaire'])." " : "";
|
|
|
404 |
$libelle .= isset($info['sous_type.secondaire']) ? "(".implode(', ',$info['sous_type.secondaire']).") " : "";
|
452 |
mathilde |
405 |
return $libelle;
|
|
|
406 |
}
|
|
|
407 |
|
548 |
mathilde |
408 |
//séparation des principaux et des secondaires
|
499 |
jpm |
409 |
public function separerTypesPrimairesSecondaires($type) {
|
548 |
mathilde |
410 |
$types = array();
|
|
|
411 |
if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
|
|
|
412 |
$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
|
452 |
mathilde |
413 |
$types['secondaire'] = $retour[2];
|
499 |
jpm |
414 |
} else {
|
452 |
mathilde |
415 |
$types['principal'] = $type;
|
|
|
416 |
}
|
|
|
417 |
return $types;
|
|
|
418 |
}
|
499 |
jpm |
419 |
|
548 |
mathilde |
420 |
|
499 |
jpm |
421 |
public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
|
452 |
mathilde |
422 |
$types = array();
|
548 |
mathilde |
423 |
if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
|
|
|
424 |
//type
|
|
|
425 |
$type = array();
|
|
|
426 |
$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
|
549 |
mathilde |
427 |
$type = explode(",", $type[0]);
|
548 |
mathilde |
428 |
for ($i = 0 ; $i < count($type); $i++) {
|
|
|
429 |
$types['type.'.$typePrimOuSec][$i] = $type[$i];
|
|
|
430 |
}
|
|
|
431 |
//sous types
|
|
|
432 |
$ss_types = array();
|
|
|
433 |
if (isset($retour[2]) && $retour[2] != '') {
|
|
|
434 |
$ss_types[0] = $retour[2] ;
|
549 |
mathilde |
435 |
$ss_types = explode("-", $ss_types[0]);
|
499 |
jpm |
436 |
for ($i = 0 ; $i < count($ss_types); $i++) {
|
548 |
mathilde |
437 |
$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
|
|
|
438 |
}
|
|
|
439 |
}
|
452 |
mathilde |
440 |
}
|
|
|
441 |
return $types;
|
548 |
mathilde |
442 |
}
|
|
|
443 |
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
|
|
|
447 |
|
|
|
448 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
|
|
449 |
|
|
|
450 |
public function assemblerLaRequete() {
|
|
|
451 |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
|
579 |
mathilde |
452 |
.$this->retournerRequeteCondition().' ';
|
592 |
mathilde |
453 |
if ($this->nb_ressources != 1 ) {
|
579 |
mathilde |
454 |
$requete .= $this->delimiterResultatsRequete();
|
592 |
mathilde |
455 |
}
|
548 |
mathilde |
456 |
return $requete;
|
452 |
mathilde |
457 |
}
|
548 |
mathilde |
458 |
|
579 |
mathilde |
459 |
public function calculerTotalResultat() {
|
|
|
460 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '.$this->retournerRequeteCondition();
|
|
|
461 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
462 |
if ($res) {
|
|
|
463 |
$this->total_resultat = $res['nombre'];
|
|
|
464 |
} else {
|
|
|
465 |
$this->total_resultat = 0;
|
|
|
466 |
$e = 'Données introuvables dans la base';
|
|
|
467 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
468 |
}
|
|
|
469 |
}
|
548 |
mathilde |
470 |
|
579 |
mathilde |
471 |
public function delimiterResultatsRequete() {
|
|
|
472 |
$this->calculerTotalResultat();
|
|
|
473 |
$requete_limite = '';
|
592 |
mathilde |
474 |
if ($this->limite_requete['limite'] != '*') {
|
|
|
475 |
if ( ($this->limite_requete['depart'] <= $this->total_resultat)){
|
|
|
476 |
if (($this->limite_requete['limite'] + $this->limite_requete['depart'] )
|
|
|
477 |
< $this->total_resultat ){
|
|
|
478 |
$requete_limite = 'LIMIT '.$this->limite_requete['depart'].', '
|
|
|
479 |
.$this->limite_requete['limite'];
|
|
|
480 |
}
|
|
|
481 |
} else {
|
|
|
482 |
$e = "Erreur : la valeur pour le paramètre navigation.départ est supérieure".
|
|
|
483 |
" au nombre total de résultats.";
|
|
|
484 |
throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
|
579 |
mathilde |
485 |
}
|
|
|
486 |
}
|
|
|
487 |
return $requete_limite;
|
|
|
488 |
}
|
548 |
mathilde |
489 |
|
579 |
mathilde |
490 |
|
|
|
491 |
|
548 |
mathilde |
492 |
public function retournerRequeteCondition() {
|
|
|
493 |
$condition = '';
|
|
|
494 |
if (empty($this->requete_condition) == false) {
|
|
|
495 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
496 |
}
|
|
|
497 |
return $condition;
|
|
|
498 |
}
|
499 |
jpm |
499 |
|
|
|
500 |
|
525 |
mathilde |
501 |
|
452 |
mathilde |
502 |
}
|
|
|
503 |
?>
|