| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| Line -... |
Line 2... |
| - |
|
2 |
|
| - |
|
3 |
/**
|
| - |
|
4 |
* classe pour web service qui affiche les images de Coste.
|
| - |
|
5 |
* il n'existe qu'une seule version pour les images de Coste : 2.00
|
| - |
|
6 |
* retour en application/json
|
| - |
|
7 |
*
|
| - |
|
8 |
* exemple d'appel du service :
|
| - |
|
9 |
* .../service:eflore:0.1/coste/images?masque.nt=1053
|
| - |
|
10 |
* .../service:eflore:0.1/coste/images?masque.nn=39594,39601
|
| - |
|
11 |
* .../service:eflore:0.1/coste/images
|
| - |
|
12 |
*
|
| - |
|
13 |
* paramètres disponibles : navigation.depart, navigation.limite, masque.nn, masque.nt
|
| - |
|
14 |
*
|
| - |
|
15 |
* @package eFlore/services
|
| - |
|
16 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
| - |
|
17 |
* @author Mathilde Salthun-Lassalle <mathilde@tela-botanica.org>
|
| - |
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
| - |
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
| - |
|
20 |
* @version 1.0
|
| - |
|
21 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
| Line 2... |
Line 22... |
| 2 |
|
22 |
*/
|
| Line 3... |
Line -... |
| 3 |
|
- |
|
| 4 |
class Images extends Commun {
|
23 |
|
| 5 |
|
24 |
class Images extends Commun {
|
| 6 |
protected $limite_requete = array('depart' => 0, 'limite' => 100);
|
25 |
|
| 7 |
protected $requete_champ = '*';
|
- |
|
| 8 |
protected $requete_condition = null;
|
- |
|
| 9 |
protected $requete_group_by = ' ORDER BY CAST( id_image AS DECIMAL )';
|
- |
|
| 10 |
protected $entete_http;
|
- |
|
| 11 |
protected $corps_http;
|
- |
|
| 12 |
protected $table_retour;
|
- |
|
| 13 |
protected $retour_format = 'max';
|
26 |
protected $table ;
|
| 14 |
protected $format_reponse = 'images';
|
27 |
private $requete_condition = array(" image != '' ");
|
| 15 |
protected $table_param = array();
|
- |
|
| 16 |
protected $total_resultat;
|
- |
|
| 17 |
protected $table_ressources = array();
|
28 |
private $champs_recherches = " num_nom, image, flore_bdtfx_nn, flore_bdtfx_nt ";
|
| Line -... |
Line 29... |
| - |
|
29 |
private $total_resultat;
|
| Line 18... |
Line 30... |
| 18 |
protected $html = 'txt';
|
30 |
protected $limite_requete = array('depart' => 0, 'limite' => 100);
|
| 19 |
protected $recherche = 'stricte';
|
31 |
private $masque = array();
|
| 20 |
protected $service = 'images';
|
- |
|
| 21 |
|
32 |
|
| 22 |
|
33 |
|
| - |
|
34 |
|
| 23 |
public function consulter($ressources, $parametres) {
|
35 |
public function consulter($ressources, $parametres) {
|
| 24 |
$resultat_formate = '';
|
36 |
$this->ressources = $ressources;
|
| 25 |
$this->table[] = Config::get("bdd_images"); //." t1,".Config::get("bdd_triples")." t2, ".Config::get("bdd_pages")." p";
|
37 |
$this->parametres = $parametres;
|
| 26 |
$this->traiterParametres($parametres);
|
38 |
$this->traiterRessources();
|
| - |
|
39 |
$this->traiterParametres();
|
| - |
|
40 |
$this->table = config::get('bdd_table').'_v2_00';
|
| 27 |
$this->traiterRessources($ressources);
|
41 |
$requete = $this->assemblerLaRequete();
|
| - |
|
42 |
$resultat = $this->getBdd()->recupererTous($requete);
|
| 28 |
if ($this->corps_http == '' && $this->entete_http == '') {
|
43 |
$versionResultat = $this->traiterResultat($resultat, $this->table, $requete);
|
| 29 |
$requete = $this->assemblerLaRequete();
|
44 |
$resultats = $versionResultat;
|
| 30 |
$resultat = $this->getBdd()->recupererTous($requete);
|
45 |
return $resultats;
|
| 31 |
$this->testerResultat($resultat, $resultat_formate, $requete);
|
46 |
}
|
| 32 |
}
|
47 |
|
| 33 |
return $this->formerReponseHTTP($resultat_formate);
|
48 |
//+-----------------------------------traitement ressources et paramètres --------------------------------+
|
| 34 |
}
|
49 |
|
| 35 |
|
- |
|
| 36 |
public function testerResultat($resultat, &$resultat_formate, $requete) {
|
- |
|
| 37 |
if ($resultat == '') { //cas ou coste/services/ ou la requete comporte des erreurs
|
50 |
|
| 38 |
$e = 'La requête SQL formée comporte une erreur!';
|
51 |
public function traiterRessources() {
|
| 39 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
|
- |
|
| 40 |
Debug::printr($requete);
|
- |
|
| 41 |
} elseif ($resultat) {
|
52 |
if (empty($this->ressources) ) {
|
| 42 |
$resultat_formate = $this->retournerResultatFormate($resultat);
|
53 |
if (isset($this->parametres['masque.nn']) == false
|
| 43 |
} else {
|
54 |
&& isset($this->parametres['masque.nt']) == false) {
|
| 44 |
if ($this->format_reponse == 'images/relations') {
|
- |
|
| 45 |
$resultat_formate = 'null';
|
55 |
$this->requete_condition[] = " flore_bdtfx_nt != '' AND flore_bdtfx_nn != '' ";
|
| 46 |
} else {
|
- |
|
| 47 |
$m = 'Données introuvables dans la base';
|
56 |
}
|
| Line 48... |
Line -... |
| 48 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$m);
|
- |
|
| 49 |
Debug::printr($requete);
|
- |
|
| 50 |
}
|
57 |
} else {
|
| 51 |
}
|
58 |
$e = "La ressource {$this->ressources[0]} n'existe pas.";
|
| - |
|
59 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
| - |
|
60 |
}
|
| 52 |
}
|
61 |
}
|
| - |
|
62 |
|
| 53 |
|
63 |
public function traiterParametres() {
|
| 54 |
//-------------------------------------------------------TRAITER RESSOURCES----------------------------------------------
|
64 |
foreach ($this->parametres as $param => $val ) {
|
| - |
|
65 |
switch ($param) {
|
| 55 |
|
66 |
case 'masque.nt' :
|
| 56 |
public function traiterRessources(&$ressources) {
|
67 |
$this->analyserMasque($val,'nt');
|
| - |
|
68 |
break;
|
| 57 |
if (isset($ressources) && !empty($ressources)) {
|
69 |
case 'masque.nn' :
|
| 58 |
$this->table_ressources = $ressources;
|
70 |
$this->analyserMasque($val,'nn');
|
| - |
|
71 |
break;
|
| 59 |
//traiter ressources/id
|
72 |
case 'navigation.depart' :
|
| 60 |
if ($ressources[0] == 'relations') {
|
73 |
$this->limite_requete['depart'] = $val;
|
| 61 |
$this->traiterRelationsProjet($ressources);
|
74 |
break;
|
| - |
|
75 |
case 'navigation.limite' :
|
| 62 |
$this->format_reponse .= '/relations';
|
76 |
$this->limite_requete['limite'] = $val;
|
| 63 |
} elseif (isset($this->table_ressources[0]) && !empty($this->table_ressources[0])) {
|
77 |
break;
|
| 64 |
$this->traiterRessourceId($this->table_ressources[0]);
|
78 |
default :
|
| 65 |
//traiter ressources/id/champ
|
79 |
$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le parametre " '
|
| Line 66... |
Line 80... |
| 66 |
if (isset($this->table_ressources[1]) && !empty($this->table_ressources[1])) {
|
80 |
.$param.' " n\'existe pas.';
|
| - |
|
81 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
| - |
|
82 |
break;
|
| - |
|
83 |
}
|
| 67 |
$this->format_reponse .= '/id/champ';
|
84 |
}
|
| - |
|
85 |
}
|
| - |
|
86 |
|
| - |
|
87 |
/*private function traiterVersion() {
|
| - |
|
88 |
if( isset($this->parametres['version.projet']) ) {
|
| - |
|
89 |
$version = $this->parametres['version.projet'];
|
| 68 |
}
|
90 |
if (preg_match('/^([0-9]+(?:[._][0-9]+|))$/', $version, $retour)) {
|
| - |
|
91 |
$this->version[] = $retour[0];
|
| 69 |
}
|
92 |
$this->version_projet[] = 'v'.str_replace('.', '_', $this->version[0]);
|
| - |
|
93 |
$this->table_version[] = Config::get('bdd_table').''.$this->version_projet[0];
|
| - |
|
94 |
} elseif ($version == '+') {
|
| - |
|
95 |
$this->obtenirDerniereVersion();
|
| - |
|
96 |
} elseif ($version == '*' && empty($this->ressources) == false ) {
|
| - |
|
97 |
$this->chargerVersions();
|
| 70 |
}
|
98 |
$total = count($this->metadonnees);
|
| 71 |
}
|
99 |
for($i = 0 ; $i < $total ; $i++) {
|
| - |
|
100 |
$this->version[$i] = $this->metadonnees[$i]['version'];
|
| - |
|
101 |
$this->version_projet[$i] = 'v'.str_replace('.', '_',$this->version[$i]);
|
| - |
|
102 |
$this->table_version[$i] = Config::get('bdd_table').''.$this->version_projet[$i];
|
| 72 |
|
103 |
}
|
| 73 |
public function traiterRelationsProjet($tab_ress) {
|
- |
|
| 74 |
$projet = $tab_ress[1];
|
- |
|
| Line 75... |
Line -... |
| 75 |
$num_nom = $tab_ress[2];
|
- |
|
| 76 |
if (isset($tab_ress[3])) {
|
- |
|
| 77 |
$e = "Pas de type pour le service images";
|
- |
|
| 78 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
104 |
}else {
|
| Line -... |
Line 105... |
| - |
|
105 |
$e = 'Erreur parametre version inconnu. ';
|
| - |
|
106 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
| - |
|
107 |
}
|
| - |
|
108 |
} else {
|
| - |
|
109 |
$this->obtenirDerniereVersion();
|
| - |
|
110 |
}
|
| - |
|
111 |
|
| - |
|
112 |
}
|
| - |
|
113 |
|
| - |
|
114 |
private function obtenirDerniereVersion(){
|
| - |
|
115 |
$this->chargerVersions();
|
| - |
|
116 |
$this->version[] = $this->metadonnees[0]['version'];
|
| - |
|
117 |
$this->version_projet[] ='v'.str_replace('.', '_',$this->metadonnees[0]['version']);
|
| - |
|
118 |
$this->table_version[] = Config::get('bdd_table').''.$this->version_projet[0];
|
| - |
|
119 |
}
|
| - |
|
120 |
|
| - |
|
121 |
private function chargerVersions() {
|
| - |
|
122 |
$requete = "SELECT version ".
|
| - |
|
123 |
"FROM ".Config::get('bdd_table_meta')." ".
|
| - |
|
124 |
"ORDER BY date_creation DESC ";
|
| - |
|
125 |
$resultats = $this->Bdd->recupererTous($requete);
|
| - |
|
126 |
if (!is_array($resultats) || count($resultats) <= 0) {
|
| Line 79... |
Line -... |
| 79 |
}
|
- |
|
| 80 |
$this->requete_condition[] = "num_nom = ".$this->getBdd()->proteger($num_nom);
|
- |
|
| 81 |
}
|
127 |
$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
|
| 82 |
|
- |
|
| 83 |
public function traiterRessourceId($id) {
|
128 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
| 84 |
$this->format_reponse .= '/id';
|
129 |
throw new Exception($message, $code);
|
| 85 |
$this->requete_condition[] = 'id_image LIKE '.$this->getBdd()->proteger($id.'.png');
|
130 |
}
|
| 86 |
}
|
131 |
|
| 87 |
|
- |
|
| 88 |
|
132 |
$this->metadonnees = $resultats;
|
| 89 |
//-------------------------------------------------------TRAITER PARAMETRES----------------------------------------------
|
- |
|
| 90 |
|
133 |
}*/
|
| 91 |
public function traiterParametres($parametres) {
|
- |
|
| 92 |
if (isset($parametres) && !empty($parametres)) {
|
- |
|
| 93 |
$this->table_param = $parametres;
|
134 |
|
| 94 |
//print_r($parametres);
|
135 |
|
| 95 |
if (isset($parametres['recherche']) && $parametres['recherche'] != '') {
|
- |
|
| 96 |
$this->recherche = $parametres['recherche'];
|
- |
|
| 97 |
}
|
- |
|
| 98 |
foreach ($parametres as $param => $val) {
|
136 |
|
| 99 |
switch ($param) {
|
137 |
private function analyserMasque($valeur, $type_masque) {
|
| 100 |
case 'retour_format' : $this->retour_format = $val; break;
|
- |
|
| 101 |
case 'masque_nn' : $this->ajouterLeFiltreMasque('num_nom', $val); break;
|
138 |
$this->masque[] = "$type_masque=$valeur";
|
| 102 |
case 'masque_no' : $this->ajouterLeFiltreMasque('nom_photographe', $val); break;
|
139 |
if (empty($valeur)) {
|
| - |
|
140 |
$e = 'renseignez une valeur pour masque.nn';
|
| 103 |
case 'masque_ns' : $this->ajouterLeFiltreMasque('nom_sci', $val); break;
|
141 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
| 104 |
case 'masque_date' : $this->ajouterLeFiltreMasque('date', $val); break;
|
142 |
} elseif (preg_match('/^[0-9]+$/', $valeur)) {
|
| 105 |
case 'masque_station' : $this->ajouterLeFiltreMasque('station', $val); break;
|
143 |
$this->requete_condition[] = " flore_bdtfx_".$type_masque." = $valeur";
|
| - |
|
144 |
} elseif (preg_match('/[0-9]+/', $valeur)){
|
| - |
|
145 |
$nums = explode(',', $valeur);
|
| - |
|
146 |
$total = count($nums);
|
| - |
|
147 |
$condition = '';
|
| 106 |
case 'navigation_depart': $this->limite_requete['depart'] = $val; break;
|
148 |
for ($i = 0; $i < $total; $i++) {
|
| 107 |
case 'navigation_limite': $this->limite_requete['limite'] = $val; break;
|
149 |
$condition .= " flore_bdtfx_".$type_masque." = {$nums[$i]}";
|
| Line 108... |
Line -... |
| 108 |
case 'recherche' : break;
|
- |
|
| 109 |
default :
|
- |
|
| 110 |
$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le parametre " '
|
- |
|
| 111 |
.$param.' " n\'existe pas.';
|
150 |
if ($i < ($total-1) ) {
|
| 112 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
- |
|
| 113 |
break;
|
- |
|
| 114 |
}
|
- |
|
| 115 |
}
|
- |
|
| 116 |
}
|
- |
|
| - |
|
151 |
$condition .= " OR ";
|
| - |
|
152 |
}
|
| 117 |
}
|
153 |
}
|
| 118 |
|
154 |
$this->requete_condition[] = $condition;
|
| 119 |
public function ajouterLeFiltreMasque($masque, $valeur) {
|
- |
|
| 120 |
if ($this->recherche == 'etendue') {
|
155 |
} else {
|
| 121 |
$valeur = '%'.str_replace(' ','%', $valeur).'%';
|
156 |
$e = "valeur incorrecte pour masque.".$type_masque;
|
| 122 |
}
|
- |
|
| 123 |
//$this->table .= ', '.Config::get("bdd_table").'_v0_1 c';
|
157 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
| 124 |
switch ($masque) {
|
158 |
}
|
| 125 |
case 'nom_sci' :
|
- |
|
| 126 |
$this->requete_champ = 'cb.*';
|
- |
|
| 127 |
$this->table[] = ' cb , '.Config::get("bdd_table").'_v0_1 c';
|
- |
|
| 128 |
$this->requete_condition[] = 'c.nom_sci LIKE '
|
159 |
}
|
| - |
|
160 |
|
| - |
|
161 |
|
| - |
|
162 |
|
| - |
|
163 |
|
| - |
|
164 |
/*public function verifierFormat($format) {
|
| - |
|
165 |
if (in_array($format, $this->formats_supportes)) {
|
| - |
|
166 |
$this->format_retour = $format;
|
| - |
|
167 |
} else {
|
| - |
|
168 |
$e = "Le format $format demandé n'est pas disponible.";
|
| - |
|
169 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
| - |
|
170 |
}
|
| - |
|
171 |
}*/
|
| - |
|
172 |
|
| - |
|
173 |
|
| - |
|
174 |
//+-------------------------------------------formatage résultats---------------------------------------------+
|
| - |
|
175 |
|
| - |
|
176 |
public function retournerResultatFormate($resultat, $table) {
|
| - |
|
177 |
$resultat_json = array();
|
| - |
|
178 |
$resultat_json['entete'] = $this->formaterEnteteResultat();
|
| - |
|
179 |
foreach ($resultat as $tab) {
|
| - |
|
180 |
$num_coste = $tab['num_nom'];
|
| - |
|
181 |
unset($tab['num_nom']);
|
| 129 |
.$this->getBdd()->proteger($valeur);
|
182 |
$resultat_json['resultats'][$num_coste]['num_nomenclatural'] = $tab['flore_bdtfx_nn'];
|
| Line -... |
Line 183... |
| - |
|
183 |
$resultat_json['resultats'][$num_coste]['num_taxonomique'] = $tab['flore_bdtfx_nt'];
|
| 130 |
$this->requete_condition[] = 'c.num_nom_coste = CONCAT(cb.id_image,\',.png\')';
|
184 |
$resultat_json['resultats'][$num_coste]['binaire.href'] = $this->formaterUrlImage($tab['image']);
|
| 131 |
$this->ajouterRechercheFloue('nom_sci', $valeur);
|
185 |
$resultat_json['resultats'][$num_coste]['mime'] = "images/png";
|
| - |
|
186 |
}
|
| 132 |
break;
|
187 |
return $resultat_json;
|
| - |
|
188 |
}
|
| - |
|
189 |
|
| - |
|
190 |
public function formaterUrlImage($fichier) {
|
| - |
|
191 |
$chemin = config::get('donnees')."2.00/img/$fichier";
|
| 133 |
case 'num_nom' :
|
192 |
return $chemin;
|
| 134 |
$val = (strrpos($valeur, ',') !== false)? " IN (".str_replace(',', '.png,', $valeur).")" : " = ".$this->getBdd()->proteger($valeur.".png");
|
193 |
}
|
| 135 |
$this->requete_condition[] = "id_image $val";
|
194 |
|
| - |
|
195 |
|
| - |
|
196 |
/*public function donnerVersionDuneTable($table) {
|
| - |
|
197 |
$version = strstr($table,'v');
|
| 136 |
break;
|
198 |
$version = str_replace('v','', $version);
|
| - |
|
199 |
$version = str_replace('_','.', $version);
|
| 137 |
default :
|
200 |
return $version;
|
| - |
|
201 |
}*/
|
| 138 |
break;
|
202 |
|
| - |
|
203 |
public function formaterEnteteResultat() {
|
| 139 |
}
|
204 |
$entete['depart'] = $this->limite_requete['depart'];
|
| Line 140... |
Line -... |
| 140 |
}
|
- |
|
| 141 |
|
- |
|
| 142 |
public function ajouterRechercheFloue($nom_champ, $id) {
|
205 |
$entete['limite'] = $this->limite_requete['limite'];
|
| Line 143... |
Line 206... |
| 143 |
if ($this->recherche == 'floue') {
|
206 |
$entete['total'] = $this->total_resultat;
|
| 144 |
$id = $this->getBdd()->proteger($id);
|
207 |
$entete['masque'] = empty($this->masque) ? 'aucun' : implode('&', $this->masque);
|
| 145 |
$this->requete_condition[array_search("$nom_champ LIKE $id",
|
- |
|
| 146 |
$this->requete_condition)] =
|
208 |
$url = $this->formulerUrl($this->total_resultat, '/images');
|
| 147 |
"($nom_champ LIKE $id)".
|
- |
|
| 148 |
" OR ( SOUNDEX($nom_champ) = SOUNDEX($id))".
|
209 |
if (isset($url['precedent']) && $url['precedent'] != '') {
|
| 149 |
" OR SOUNDEX(REVERSE($nom_champ)) = SOUNDEX(REVERSE($id))))";
|
210 |
$entete['href.precedent'] = $url['precedent'];
|
| 150 |
}
|
211 |
}
|
| - |
|
212 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
| Line -... |
Line 213... |
| - |
|
213 |
$entete['href.suivant'] = $url['suivant'];
|
| 151 |
}
|
214 |
}
|
| 152 |
|
215 |
return $entete;
|
| 153 |
|
216 |
}
|
| 154 |
|
217 |
|
| 155 |
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
|
218 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
| 156 |
|
219 |
|
| 157 |
public function assemblerLaRequete() {
|
220 |
public function assemblerLaRequete() {
|
| Line 158... |
Line -... |
| 158 |
$requete = ' SELECT '.$this->requete_champ.
|
- |
|
| 159 |
' FROM '.implode(', ', $this->table)
|
- |
|
| 160 |
.$this->formerRequeteCondition()
|
- |
|
| 161 |
.$this->requete_group_by
|
- |
|
| 162 |
.$this->formerRequeteLimite();
|
- |
|
| 163 |
return $requete;
|
- |
|
| 164 |
}
|
- |
|
| 165 |
|
- |
|
| 166 |
public function formerRequeteCondition() {
|
- |
|
| 167 |
$condition = '';
|
- |
|
| 168 |
if ($this->requete_condition !== null) {
|
- |
|
| 169 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
221 |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
|
| Line 170... |
Line -... |
| 170 |
}
|
- |
|
| 171 |
return $condition;
|
- |
|
| 172 |
}
|
- |
|
| 173 |
|
- |
|
| 174 |
public function formerRequeteLimite() {
|
- |
|
| 175 |
if (in_array($this->format_reponse , array('images/id', 'images/id/relations'))) {
|
222 |
.$this->retournerRequeteCondition().' '
|
| 176 |
$this->requete_limite = '';
|
- |
|
| 177 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
223 |
.$this->delimiterResultatsRequete();
|
| - |
|
224 |
return $requete;
|
| 178 |
$this->limite_requete['depart'] =
|
225 |
}
|
| 179 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
226 |
|
| 180 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
227 |
|
| 181 |
} else {
|
228 |
|
| - |
|
229 |
public function retournerRequeteCondition() {
|
| 182 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
230 |
$condition = '';
|
| 183 |
}
|
231 |
if (empty($this->requete_condition) == false) {
|
| 184 |
return $this->requete_limite;
|
232 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
| 185 |
}
|
- |
|
| 186 |
|
233 |
}
|
| Line 187... |
Line -... |
| 187 |
/**
|
- |
|
| Line 188... |
Line 234... |
| 188 |
* Recupere le nombre total de résultat d'une requete lancée.
|
234 |
return $condition;
|
| 189 |
* Est utilisée lors de l'affichage du total dans le résultat retourné et pr déterminer les limites et départ
|
- |
|
| 190 |
* @return nombre total de résultat
|
- |
|
| 191 |
*/
|
- |
|
| 192 |
public function recupererTotalResultat() {
|
- |
|
| 193 |
$total = null;
|
- |
|
| 194 |
$requete = 'SELECT count(*) as nombre FROM '.implode(', ', $this->table).$this->formerRequeteCondition().$this->requete_group_by;
|
- |
|
| 195 |
$res = $this->getBdd()->recuperer($requete);
|
- |
|
| 196 |
if ($res) {
|
- |
|
| 197 |
$total = $res['nombre'];
|
- |
|
| 198 |
} else {
|
- |
|
| 199 |
$e = 'Données introuvables dans la base ou erreur dans la requête SQL';
|
- |
|
| 200 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
- |
|
| 201 |
}
|
- |
|
| 202 |
return $total;
|
- |
|
| 203 |
}
|
235 |
}
|
| 204 |
|
- |
|
| 205 |
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
|
236 |
|
| 206 |
|
- |
|
| 207 |
public function retournerResultatFormate($resultat) {
|
- |
|
| 208 |
$reponse = '';
|
237 |
|
| 209 |
switch ($this->format_reponse) {
|
- |
|
| 210 |
case 'images' : $reponse = $this->formaterImages($resultat); break;
|
- |
|
| 211 |
case 'images/relations' : $reponse = $this->formaterImagesRelations($resultat[0]); break;
|
- |
|
| 212 |
case 'images/id' : $reponse = $this->formaterImagesId($resultat[0]); break;
|
- |
|
| 213 |
case 'images/id/champ' : $reponse = $this->formaterImagesIdChamp($resultat[0]); break;
|
- |
|
| 214 |
default : break;
|
- |
|
| 215 |
}
|
- |
|
| 216 |
$reponse = json_encode($reponse);
|
- |
|
| 217 |
return $reponse;
|
- |
|
| 218 |
}
|
- |
|
| 219 |
|
- |
|
| 220 |
public function formaterImages($resultat) {
|
- |
|
| 221 |
//print_r($resultat);
|
238 |
|
| 222 |
$this->ajouterEnteteResultat($resultat);
|
239 |
public function calculerTotalResultat() {
|
| 223 |
$reponse['entete'] = $this->table_retour;
|
- |
|
| 224 |
$this->table_retour = array();
|
- |
|
| 225 |
foreach ($resultat as $images) {
|
- |
|
| 226 |
$id = str_replace('.png', '', $images['id_image']);
|
- |
|
| 227 |
$id_coste = $this->recupererNumNom($id);
|
- |
|
| 228 |
if ($id != '') {
|
- |
|
| 229 |
$this->table_retour['url.image'] = Config::get('url_images').$images['id_image'];
|
- |
|
| 230 |
$this->afficherDonnees('id', $id_coste);
|
- |
|
| 231 |
$reponse['resultat'][$id] = $this->table_retour;
|
- |
|
| 232 |
$this->table_retour = array();
|
- |
|
| 233 |
$reponse['resultat'][$id]['href'] = $this->ajouterHref('images', $id);
|
- |
|
| 234 |
}
|
- |
|
| 235 |
}
|
- |
|
| 236 |
return $reponse;
|
- |
|
| 237 |
}
|
- |
|
| 238 |
|
- |
|
| 239 |
public function ajouterEnteteResultat($resultat) {
|
- |
|
| 240 |
$this->table_retour['depart'] = $this->limite_requete['depart'];
|
- |
|
| 241 |
$this->table_retour['limite'] = $this->limite_requete['limite'];
|
- |
|
| 242 |
$this->table_retour['total'] = $this->total_resultat;
|
- |
|
| 243 |
//formuler les urls
|
- |
|
| 244 |
$url = $this->formulerUrl($this->total_resultat, '/'.$this->service);
|
- |
|
| 245 |
if ($url['precedent'] != '') { $this->table_retour['href.precedent'] = $url['precedent']; }
|
- |
|
| 246 |
if ($url['suivant'] != '') { $this->table_retour['href.suivant'] = $url['suivant']; }
|
- |
|
| 247 |
}
|
- |
|
| 248 |
|
- |
|
| 249 |
|
- |
|
| 250 |
public function formaterImagesRelations($resultat) {
|
- |
|
| 251 |
$reponse['url.image'] = Config::get('url_images').$resultat['id_image'];
|
- |
|
| 252 |
return $reponse;
|
- |
|
| 253 |
}
|
- |
|
| 254 |
|
- |
|
| 255 |
|
- |
|
| 256 |
public function formaterImagesId($resultat) {
|
- |
|
| 257 |
$id = str_replace('.png', '', $resultat['id_image']);
|
- |
|
| 258 |
$id_coste = $this->recupererNumNom($id);
|
- |
|
| 259 |
$this->table_retour['url.image'] = Config::get('url_images').$resultat['id_image'];
|
- |
|
| 260 |
$this->table_retour['id'] = $id;
|
- |
|
| 261 |
$this->table_retour['auteur'] = $resultat['auteur'];
|
- |
|
| 262 |
$this->table_retour['station.pays'] = "ISO-3166-1.FR";
|
240 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '
|
| 263 |
$this->afficherDonnees('id', $id_coste);
|
- |
|
| 264 |
$res = $this->ajouterRelationBdnff($resultat['num_nom']);
|
- |
|
| 265 |
return $res;
|
- |
|
| 266 |
}
|
- |
|
| 267 |
|
- |
|
| 268 |
|
- |
|
| 269 |
|
- |
|
| 270 |
public function recupererNumNom($num_nom_coste) {
|
- |
|
| 271 |
$req = "SELECT num_nom FROM coste_v0_1 WHERE num_nom_coste = "
|
241 |
.$this->retournerRequeteCondition();
|
| 272 |
.$this->getBdd()->proteger($num_nom_coste)." AND num_nom = num_nom_retenu";
|
242 |
$res = $this->getBdd()->recuperer($requete);
|
| 273 |
$res = $this->getBdd()->recuperer($req);
|
- |
|
| 274 |
if ($res) {
|
- |
|
| 275 |
$num_nom = $res['num_nom'];
|
- |
|
| 276 |
}
|
- |
|
| 277 |
return $num_nom;
|
- |
|
| 278 |
}
|
- |
|
| 279 |
|
- |
|
| 280 |
public function ajouterRelationBdnff($num_nom) {
|
- |
|
| 281 |
$res = $this->table_retour;
|
- |
|
| 282 |
$this->table_retour = array();
|
- |
|
| 283 |
$this->afficherDonnees('id', $num_nom, 'bdtfx');
|
243 |
if ($res) {
|
| 284 |
$res['relations']['nom'] = $this->table_retour;
|
244 |
$this->total_resultat = $res['nombre'];
|
| 285 |
return $res;
|
- |
|
| 286 |
}
|
- |
|
| 287 |
|
- |
|
| 288 |
public function formaterImagesIdChamp($resultat) {
|
- |
|
| 289 |
//on recupère tous les resultats possibles
|
- |
|
| 290 |
$reponse_id = $this->formaterImagesId($resultat);
|
- |
|
| 291 |
$this->table_retour = array();
|
- |
|
| 292 |
//on recupère les résultats demandés à partir du tableau de résultat complet
|
- |
|
| 293 |
$this->table_retour['id'] = $resultat['tag'];
|
- |
|
| 294 |
$champs = explode(' ', $this->table_ressources[1]);
|
- |
|
| 295 |
foreach ($champs as $champ) {
|
- |
|
| 296 |
if ($this->verifierValiditeChamp($champ, $reponse_id)) {
|
- |
|
| 297 |
if (preg_match('/^[^.]+\.\*$/', $champ)) {
|
- |
|
| 298 |
$this->afficherPointEtoile($champ, $reponse_id);
|
- |
|
| 299 |
} else {
|
- |
|
| 300 |
$this->table_retour[$champ] = $reponse_id[$champ];
|
- |
|
| 301 |
}
|
- |
|
| 302 |
}
|
- |
|
| 303 |
}
|
- |
|
| 304 |
return $this->table_retour;
|
- |
|
| 305 |
}
|
- |
|
| 306 |
|
- |
|
| 307 |
public function afficherPointEtoile($champ, $reponse_id) {
|
- |
|
| 308 |
preg_match('/^([^.]+\.)\*$/', $champ, $match);
|
- |
|
| 309 |
foreach ($reponse_id as $chp => $valeur) {
|
- |
|
| 310 |
if (strrpos($chp, $match[1]) !== false) {
|
- |
|
| 311 |
$this->table_retour[$chp] = $valeur;
|
- |
|
| 312 |
}
|
- |
|
| 313 |
}
|
- |
|
| 314 |
}
|
- |
|
| 315 |
|
- |
|
| 316 |
public function verifierValiditeChamp($champ, $reponse_id) {
|
- |
|
| 317 |
$validite = false;
|
245 |
} else {
|
| 318 |
preg_match('/^([^.]+)(:?\.([^.]+))?$/', $champ, $match);
|
- |
|
| 319 |
if (array_key_exists($match[1], $reponse_id)) {
|
- |
|
| 320 |
$validite = true;
|
- |
|
| 321 |
if (isset($match[2]) && !empty($match[2])) {
|
- |
|
| 322 |
if ($match[1] == 'type') {
|
- |
|
| 323 |
$suffixes = array('.code', '.href', '.*');
|
- |
|
| 324 |
$validite = (in_array($match[2], $suffixes)) ? true : false;
|
- |
|
| 325 |
} else {
|
- |
|
| 326 |
$validite = false;
|
- |
|
| 327 |
}
|
- |
|
| 328 |
}
|
- |
|
| 329 |
}
|
- |
|
| 330 |
if (!$validite) {
|
- |
|
| 331 |
$champs = implode('</li><li>', array_keys($reponse_id));
|
- |
|
| 332 |
$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas. Les champs disponibles
|
- |
|
| 333 |
sont : <li>'.$champs.'</li>';
|
- |
|
| 334 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
- |
|
| 335 |
}
|
- |
|
| 336 |
return $validite;
|
- |
|
| 337 |
}
|
- |
|
| 338 |
|
- |
|
| 339 |
|
- |
|
| 340 |
//------------------------------------------------Fonction d'affichage ------------------------------------------------
|
- |
|
| 341 |
|
- |
|
| 342 |
public function afficherDonnees($champ, $valeur, $projet = null) {
|
- |
|
| 343 |
if ($this->retour_format == 'min') {
|
- |
|
| 344 |
$champ = ($champ == 'type') ? $champ.'.code' : $champ;
|
- |
|
| 345 |
$this->table_retour[$champ] = $valeur;
|
- |
|
| 346 |
} else {
|
- |
|
| 347 |
$this->afficherDonneesMax($champ, $valeur, $projet);
|
- |
|
| 348 |
}
|
- |
|
| 349 |
}
|
- |
|
| 350 |
|
- |
|
| 351 |
public function afficherDonneesMax($champ, $valeur, $projet = null) {
|
- |
|
| 352 |
if (!$projet) $projet = 'coste';
|
- |
|
| 353 |
if ($champ == 'id') {
|
- |
|
| 354 |
$this->table_retour['nom_sci.id'] = $projet.'.'.$valeur;
|
- |
|
| 355 |
$fct = "recupererNomSci".ucfirst($projet);
|
- |
|
| 356 |
$this->table_retour['nom_sci'] = $this->$fct($valeur);
|
- |
|
| 357 |
$this->table_retour['nom_sci.href'] = $this->ajouterHrefAutreProjet('noms', '', $valeur, $projet);
|
- |
|
| 358 |
} elseif (in_array($champ, array('type'))) {
|
- |
|
| 359 |
$this->table_retour[$champ.'.code'] = $valeur;
|
- |
|
| 360 |
$this->table_retour[$champ] = $this->recupererSignificationCode($valeur);
|
- |
|
| 361 |
$this->table_retour[$champ.'.href'] = $this->ajouterHrefAutreProjet($champ, '', $valeur, 'commun');
|
246 |
$this->total_resultat = 0;
|
| Line 362... |
Line -... |
| 362 |
} else {
|
- |
|
| 363 |
$this->table_retour[$champ] = $valeur;
|
- |
|
| 364 |
}
|
- |
|
| 365 |
}
|
- |
|
| 366 |
|
- |
|
| 367 |
public function recupererSignificationCode($code) {
|
247 |
$e = 'Données introuvables dans la base';
|
| 368 |
$url = $this->ajouterHrefAutreProjet('ontologies', 'texteType:', $code.'/nom', 'commun');
|
- |
|
| 369 |
$res = $this->consulterHref($url);
|
- |
|
| 370 |
return $res->nom;
|
- |
|
| 371 |
}
|
248 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
| 372 |
|
249 |
}
|