452 |
mathilde |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Classe InformationsBaseflor.php permet de faire des requetes de baseflor en fonction d'un référentiel
|
|
|
5 |
*( BDTFX, BDAFX, BDBFX ) et d'un numéro nomenclatural ( différent de 0 ).
|
|
|
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
|
|
|
10 |
* /informations --> retourne les 10 premiers résultats
|
|
|
11 |
* /informations?navigation.limite=..&navigation.depart=.. --> retourne les 10 premiers résultats avec limites
|
|
|
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
|
|
|
22 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
class InformationsBaseflor extends Commun{
|
|
|
26 |
|
|
|
27 |
protected $table = "";
|
|
|
28 |
private $requete_condition = "";
|
|
|
29 |
private $format_reponse = 'informations';
|
|
|
30 |
private $total_resultat;
|
|
|
31 |
private $retour_format = 'max';
|
|
|
32 |
protected $limite_requete = array( 'depart' => 0, 'limite' => 10);
|
|
|
33 |
private $champs_recherches = '*';
|
|
|
34 |
private $champs_ontologiques = array();
|
|
|
35 |
protected $serviceNom = 'informations';
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
public function consulter($ressources, $parametres) {
|
|
|
40 |
|
|
|
41 |
$this->ressources = $ressources;
|
|
|
42 |
$this->parametres = $parametres;
|
|
|
43 |
$this->traiterParametres();
|
|
|
44 |
$this->traiterVersionProjet();
|
|
|
45 |
$resultats = null;
|
|
|
46 |
foreach ($this->table_version as $version) {
|
|
|
47 |
$this->table = $version;
|
|
|
48 |
$this->recupererNomChamp($this->table);
|
|
|
49 |
$this->traiterRessources();
|
|
|
50 |
$requete = $this->assemblerLaRequete();
|
|
|
51 |
$resultat = $this->getBdd()->recupererTous($requete);
|
|
|
52 |
$versionResultat = $this->traiterResultat($resultat, $version, $requete);
|
|
|
53 |
if (count($this->table_version) > 1) {
|
|
|
54 |
$resultats[$version] = $versionResultat;
|
|
|
55 |
} else {
|
|
|
56 |
$resultats = $versionResultat;
|
|
|
57 |
}
|
|
|
58 |
}
|
466 |
mathilde |
59 |
return $resultats;
|
452 |
mathilde |
60 |
}
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
public function traiterResultat($resultat, $version, $requete) {
|
|
|
65 |
$versionResultat = null;
|
|
|
66 |
if ($resultat == '') {
|
|
|
67 |
$message = 'La requête SQL formée comporte une erreur!';
|
|
|
68 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
69 |
throw new Exception($message, $code);
|
|
|
70 |
} elseif ($resultat) {
|
|
|
71 |
$versionResultat = $this->retournerResultatFormate($resultat, $version);
|
|
|
72 |
}
|
|
|
73 |
return $versionResultat;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
|
|
77 |
public function traiterParametres() {
|
|
|
78 |
if (isset($this->parametres) && !empty($this->parametres)) {
|
|
|
79 |
foreach ($this->parametres as $param => $valeur) {
|
|
|
80 |
switch ($param) {
|
|
|
81 |
case 'navigation.depart' :
|
|
|
82 |
$this->limite_requete['depart'] = $valeur; break;
|
|
|
83 |
case 'navigation.limite' : $this->limite_requete['limite'] = $valeur; break;
|
|
|
84 |
case 'champs' :
|
|
|
85 |
if ($valeur == "description") {
|
|
|
86 |
$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
|
|
|
87 |
." sexualite, ordre_maturation, "
|
|
|
88 |
."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
|
|
|
89 |
."form_vegetale ";
|
466 |
mathilde |
90 |
$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
|
|
|
91 |
"OR sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
|
|
|
92 |
"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
|
|
|
93 |
"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
|
452 |
mathilde |
94 |
}elseif ($valeur == "ecologie"){
|
466 |
mathilde |
95 |
$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
|
452 |
mathilde |
96 |
." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
|
|
|
97 |
." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol ";
|
466 |
mathilde |
98 |
$this->requete_condition[] = "( ve_lumiere != '' OR ve_temperature != '' ".
|
|
|
99 |
"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
|
|
|
100 |
"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
|
|
|
101 |
"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
|
|
|
102 |
"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
|
452 |
mathilde |
103 |
}else {
|
|
|
104 |
$e = 'Valeur de paramètre inconnue pour \'test\'. ';
|
|
|
105 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
106 |
}
|
|
|
107 |
break;
|
|
|
108 |
case 'retour.format' :
|
|
|
109 |
$this->retour_format = $valeur;
|
|
|
110 |
break;
|
|
|
111 |
default :
|
|
|
112 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
|
|
113 |
.$param.' " n\'existe pas.';
|
|
|
114 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e); break;
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public function traiterRessources() {
|
|
|
121 |
if (isset($this->ressources) && !empty($this->ressources[0])) {
|
|
|
122 |
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)==1){
|
|
|
123 |
switch ($retour[1]) {
|
|
|
124 |
case 'bdtfx' :
|
|
|
125 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
|
|
|
126 |
break;
|
|
|
127 |
case 'bdafx' :
|
|
|
128 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
|
|
|
129 |
break;
|
|
|
130 |
case 'bdbfx' :
|
|
|
131 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
|
|
|
132 |
break;
|
|
|
133 |
default :
|
|
|
134 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource " '
|
|
|
135 |
.$retour[1].' " n\'existe pas.';
|
|
|
136 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
137 |
break;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
} else {
|
|
|
142 |
$this->champs_recherches=" cle, catminat_code, BDNT, num_taxon, num_nomen ";
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
//+--------------------------formatages de resultats -------------------------------------------+
|
|
|
147 |
public function retournerResultatFormate($resultat) {
|
|
|
148 |
if ((count($this->ressources)) == 0) {
|
|
|
149 |
$table_retour_json['resultat'] = $this->formaterResultatsInformations($resultat);
|
|
|
150 |
} else {
|
|
|
151 |
$table_retour_json = $this->formaterResultatsInformationsBDNTnn($resultat);
|
|
|
152 |
}
|
|
|
153 |
return $table_retour_json;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public function formaterResultatsInformationsBDNTnn($resultat){
|
|
|
157 |
$resultat_json = $resultat[0];
|
|
|
158 |
if ($this->retour_format == 'max'){
|
|
|
159 |
if (!isset($this->parametres['champs']) ) {
|
|
|
160 |
$resultat_json = $this->formaterResultatsTousChamps($resultat_json);
|
|
|
161 |
} elseif ($this->parametres['champs'] == 'ecologie') {
|
|
|
162 |
$resultat_json = $this->formaterResultatsChampsEcologie($resultat_json);
|
|
|
163 |
} elseif ($this->parametres['champs'] == 'description') {
|
|
|
164 |
$resultat_json = $this->formaterResultatsChampsDescription($resultat_json);
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
return $resultat_json;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
public function formaterResultatsTousChamps($resultat) {
|
|
|
172 |
$resultat_json = $resultat;
|
|
|
173 |
|
|
|
174 |
if ($resultat_json['type_bio'] != ""){
|
|
|
175 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($resultat_json['type_bio']);
|
|
|
176 |
unset($resultat_json['type_bio']);
|
|
|
177 |
$resultat_json= array_merge($resultat_json,$tab_ontologie);
|
|
|
178 |
}
|
|
|
179 |
$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
|
|
|
180 |
|
|
|
181 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
|
|
182 |
if ($resultat_json[$cle] != ""){
|
|
|
183 |
$tab_ontologie = $this->recupererOntologies($resultat_json[$cle], $cle);
|
|
|
184 |
unset($resultat_json[$cle]);
|
|
|
185 |
$resultat_json = array_merge($resultat_json,$tab_ontologie);
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
$resultat_json['graphique_climat']['libelle'] = 'climat';
|
|
|
189 |
$resultat_json['graphique_climat']['href'] = $this->ajouterHref('graphiques/climat', strtolower($resultat_json['BDNT']).'.nn:'.$resultat_json['num_nomen']);
|
|
|
190 |
$resultat_json['graphique_sol']['libelle'] = 'sol';
|
|
|
191 |
$resultat_json['graphique_sol']['href'] = $this->ajouterHref('graphiques/sol', strtolower($resultat_json['BDNT']).'.nn:'.$resultat_json['num_nomen']);
|
|
|
192 |
|
|
|
193 |
return $resultat_json ;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public function formaterResultatsChampsEcologie($resultat) {
|
|
|
197 |
$resultat_json = $resultat;
|
|
|
198 |
$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
|
|
|
199 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
|
|
200 |
if ($resultat_json[$cle] != ""){
|
|
|
201 |
$tab_ontologie = $this->recupererOntologies($resultat_json[$cle], $cle);
|
|
|
202 |
unset($resultat_json[$cle]);
|
|
|
203 |
$resultat_json= array_merge($resultat_json,$tab_ontologie);
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
$resultat_json['graphique_climat']['libelle'] = 'climat';
|
|
|
207 |
$resultat_json['graphique_climat']['href'] = $this->ajouterHref('graphiques/climat', strtolower($resultat_json['BDNT']).'.nn:'.$resultat_json['num_nomen']);
|
|
|
208 |
$resultat_json['graphique_sol']['libelle'] = 'sol';
|
|
|
209 |
$resultat_json['graphique_sol']['href'] = $this->ajouterHref('graphiques/sol', strtolower($resultat_json['BDNT']).'.nn:'.$resultat_json['num_nomen']);
|
|
|
210 |
return $resultat_json ;
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public function formaterResultatsChampsDescription($resultat) {
|
|
|
214 |
$resultat_json = $resultat;
|
|
|
215 |
if ($resultat_json['type_bio'] != ""){
|
|
|
216 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($resultat_json['type_bio']);
|
|
|
217 |
unset($resultat_json['type_bio']);
|
|
|
218 |
$resultat_json = array_merge($resultat_json,$tab_ontologie);
|
|
|
219 |
}
|
|
|
220 |
return $resultat_json ;
|
|
|
221 |
}
|
|
|
222 |
public function formaterResultatsInformations($resultat) {
|
|
|
223 |
$resultat_json = array();
|
|
|
224 |
$resultat_json['entete'] = $this->ajouterEnteteResultat();
|
|
|
225 |
foreach ($resultat as $tab) {
|
|
|
226 |
if ($tab['BDNT'] != 'nc'){
|
|
|
227 |
$num = $tab['cle'];
|
|
|
228 |
unset($tab['cle']);
|
|
|
229 |
foreach ($tab as $param => $valeur) {
|
|
|
230 |
$resultat_json[$num][$param] = $valeur;
|
|
|
231 |
}
|
|
|
232 |
$resultat_json[$num]['href'] = $this->ajouterHref('informations',strtolower($tab['BDNT']).".nn:".$tab['num_nomen']);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
return $resultat_json;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
public function ajouterEnteteResultat() {
|
|
|
241 |
$entete['depart'] = $this->limite_requete['depart'];
|
|
|
242 |
$entete['limite'] = $this->limite_requete['limite'];
|
|
|
243 |
$entete['total'] = $this->total_resultat;
|
|
|
244 |
$entete['version'] = $this->version_projet;
|
|
|
245 |
$url = $this->formulerUrl($this->total_resultat, '/informations');
|
|
|
246 |
if (isset($url['precedent']) && $url['precedent'] != '') {
|
|
|
247 |
$entete['href.precedent'] = $url['precedent'];
|
|
|
248 |
}
|
|
|
249 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
|
|
250 |
$entete['href.suivant'] = $url['suivant'];
|
|
|
251 |
}
|
|
|
252 |
return $entete;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
//+--------------------------traitement ontologies -------------------------------------------+
|
|
|
257 |
public function recupererOntologies($valeur, $champs){
|
|
|
258 |
$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
|
|
|
259 |
$val = $this->consulterHref($url);
|
|
|
260 |
$resultat_json[$champs.'.libelle'] = $val->nom;
|
|
|
261 |
$resultat_json[$champs.'.code'] = $valeur;
|
|
|
262 |
$resultat_json[$champs.'.href'] = $url;
|
|
|
263 |
return $resultat_json;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
public function recupererOntologiePrTypeBio($type_a_traiter){
|
|
|
269 |
$resultat_typeBio = "";
|
|
|
270 |
if ($type_a_traiter != ""){
|
|
|
271 |
$resultat_typeBio['type_bio.code'] = $type_a_traiter;
|
|
|
272 |
$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
|
|
|
273 |
foreach ($types_prim_sec as $cle => $tb){
|
|
|
274 |
$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
|
|
|
275 |
}
|
|
|
276 |
switch (count($types_sstypes)){
|
|
|
277 |
case 1 :
|
|
|
278 |
$types_sstypes = $types_sstypes['principal'];
|
|
|
279 |
break;
|
|
|
280 |
case 2 :
|
|
|
281 |
$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
|
|
|
282 |
break;
|
|
|
283 |
case 3 :
|
|
|
284 |
$types_sstypes = array_merge($types_sstypes['principal'],
|
|
|
285 |
$types_sstypes['secondaire'],
|
|
|
286 |
$types_sstypes['special']);
|
|
|
287 |
break;
|
|
|
288 |
default :
|
|
|
289 |
break;
|
|
|
290 |
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
foreach ($types_sstypes as $cle => $tb){
|
|
|
294 |
if (($cle == 'type.principal') || ($cle == 'type.secondaire')){
|
|
|
295 |
$url = $this->ajouterHref('ontologies','TB:'.urlencode(urlencode($tb)));
|
|
|
296 |
$val = $this->consulterHref($url);
|
|
|
297 |
$libelle[$cle]= $val->nom;
|
|
|
298 |
$detail[$cle]['libelle'] = $val->nom;
|
|
|
299 |
$detail[$cle]['code'] = $val->code;
|
|
|
300 |
$detail[$cle]['href'] = $url;
|
|
|
301 |
}
|
|
|
302 |
if ( ($cle == 'sous_type.principal') || ($cle == 'sous_type.secondaire') || ($cle == 'sous_type.special') ){
|
|
|
303 |
$i = 0;
|
|
|
304 |
foreach ($tb as $sstypes){
|
|
|
305 |
$url = $this->ajouterHref('ontologies','ssTT:'.urlencode(urlencode($sstypes)));
|
|
|
306 |
$val = $this->consulterHref($url);
|
|
|
307 |
$libelle[$cle]=$val->nom;
|
|
|
308 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
|
|
309 |
$detail[$cle][$i]['code'] = $val->code;
|
|
|
310 |
$detail[$cle][$i]['href'] = $url;
|
|
|
311 |
$i++;
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
}
|
|
|
315 |
$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
|
|
|
316 |
$resultat_typeBio['type_bio.detail'] = $detail;
|
|
|
317 |
}
|
|
|
318 |
return $resultat_typeBio;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
public function formaterTypeBioPrLibelle($info){
|
|
|
323 |
$libelle = $info['type.principal']." ";
|
|
|
324 |
$libelle .= isset($info['sous_type.principal']) ? " (".$info['sous_type.principal'].") " : "";
|
|
|
325 |
$libelle .= isset($info['type.secondaire']) ? ", ".$info['type.secondaire']." " : "";
|
|
|
326 |
$libelle .= isset($info['sous_type.secondaire']) ? "(".$info['sous_type.secondaire'].") " : "";
|
|
|
327 |
$libelle .= isset($info['sous_type.special']) ? "(".$info['sous_type.special'].") " : "";
|
|
|
328 |
return $libelle;
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
public function separerTypesPrimairesSecondaires($type){
|
|
|
333 |
$types = array();
|
|
|
334 |
//séparation des principaux et des secondaires
|
|
|
335 |
if (( preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour) == 1 )){
|
|
|
336 |
$types['principal'] = $retour[1];
|
|
|
337 |
$types['secondaire'] = $retour[2];
|
|
|
338 |
if (isset($retour[3])){$types['special'] = $retour[3];}
|
|
|
339 |
}else {
|
|
|
340 |
$types['principal'] = $type;
|
|
|
341 |
}
|
|
|
342 |
return $types;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec){
|
|
|
346 |
$types = array();
|
|
|
347 |
if(( preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $type_a_traiter, $retour) == 1 )){
|
|
|
348 |
//recupère le type unique
|
|
|
349 |
|
|
|
350 |
$type = (isset($retour[3]) && ($typePrimOuSec != 'special') ) ? $retour[3] : $retour[1] ;
|
|
|
351 |
$types['type.'.$typePrimOuSec]= $type;
|
|
|
352 |
//recupère le ou les sous-types
|
|
|
353 |
if ((isset($retour[3]) && ($typePrimOuSec == 'special') )){
|
|
|
354 |
$ss_types[0] = (isset($retour[3]) && ($typePrimOuSec == 'special') ) ? $retour[3] : "" ;
|
|
|
355 |
}elseif(isset($retour[2]) && ($retour[2] != "")){
|
|
|
356 |
$ss_types[0]= (isset($retour[2]) && ($retour[2] != "") ) ? $retour[2] : "" ;
|
|
|
357 |
}
|
|
|
358 |
if (isset($ss_types[0])){
|
|
|
359 |
if (( preg_match("/\-/", $ss_types[0])) == 1 ){
|
|
|
360 |
$ss_types = preg_split("/\-/", $ss_types[0]);
|
|
|
361 |
}
|
|
|
362 |
for($i = 0 ; $i < count($ss_types); $i++){
|
|
|
363 |
$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
return $types;
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
|
|
373 |
|
|
|
374 |
public function assemblerLaRequete() {
|
466 |
mathilde |
375 |
|
452 |
mathilde |
376 |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
|
|
|
377 |
.$this->retournerRequeteCondition().' '
|
|
|
378 |
.$this->delimiterResultatsRequete();
|
466 |
mathilde |
379 |
|
452 |
mathilde |
380 |
return $requete;
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
|
|
|
385 |
public function retournerRequeteCondition() {
|
|
|
386 |
$condition = '';
|
|
|
387 |
if ($this->requete_condition !== "") {
|
|
|
388 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
389 |
}
|
|
|
390 |
return $condition;
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
public function calculerTotalResultat() {
|
|
|
396 |
//on récupère le nombre total de résultats de la requete
|
|
|
397 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '
|
|
|
398 |
.$this->retournerRequeteCondition();
|
|
|
399 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
400 |
if ($res) {
|
|
|
401 |
$this->total_resultat = $res['nombre'];
|
|
|
402 |
} else {
|
|
|
403 |
$this->total_resultat = 0;
|
|
|
404 |
$e = 'Données introuvables dans la base';
|
|
|
405 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
406 |
}
|
|
|
407 |
}
|
|
|
408 |
|
480 |
mathilde |
409 |
|
452 |
mathilde |
410 |
public function delimiterResultatsRequete() {
|
|
|
411 |
$this->calculerTotalResultat();
|
483 |
mathilde |
412 |
$this->requete_limite = '';
|
480 |
mathilde |
413 |
if ((count($this->ressources)) == 0) {
|
452 |
mathilde |
414 |
if (($this->limite_requete['depart'] < $this->total_resultat) &&
|
481 |
mathilde |
415 |
(($this->limite_requete['limite'] + $this->limite_requete['depart'] )
|
|
|
416 |
< $this->total_resultat )) {
|
452 |
mathilde |
417 |
$this->requete_limite = 'LIMIT '.$this->limite_requete['depart'].', '
|
|
|
418 |
.$this->limite_requete['limite'];
|
481 |
mathilde |
419 |
}
|
452 |
mathilde |
420 |
}
|
|
|
421 |
return $this->requete_limite;
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
?>
|