Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 6 | Rev 496 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 490
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 -... Line 23...
-
 
23
 
-
 
24
class Images extends Commun {
-
 
25
	
-
 
26
	protected  $table ;
3
 
27
	private $requete_condition = array(" image != '' ");
4
class Images extends Commun {
-
 
5
	
-
 
6
	protected $limite_requete	= array('depart' => 0, 'limite' => 100);
-
 
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;
28
	private $champs_recherches = " num_nom, image, flore_bdtfx_nn, flore_bdtfx_nt ";
13
	protected $retour_format = 'max';
-
 
14
	protected $format_reponse = 'images';
-
 
15
	protected $table_param = array();
-
 
16
	protected $total_resultat;
-
 
17
	protected $table_ressources = array();
-
 
-
 
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();
27
		$this->traiterRessources($ressources);
-
 
28
		if ($this->corps_http == '' && $this->entete_http == '') {
39
		$this->traiterParametres();
-
 
40
		$this->table = config::get('bdd_table').'_v2_00'; 
29
			$requete = $this->assemblerLaRequete(); 
41
		$requete = $this->assemblerLaRequete();
Line 30... Line -...
30
			$resultat = $this->getBdd()->recupererTous($requete); 
-
 
31
			$this->testerResultat($resultat, $resultat_formate, $requete);
42
		$resultat = $this->getBdd()->recupererTous($requete);
32
		}
-
 
33
		return $this->formerReponseHTTP($resultat_formate);
-
 
34
	}
-
 
35
	
-
 
36
	public function testerResultat($resultat, &$resultat_formate, $requete) {
-
 
37
		if ($resultat == '') { //cas ou coste/services/ ou la requete comporte des erreurs
-
 
38
			$e = 'La requête SQL formée comporte une erreur!';
-
 
39
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
-
 
40
			Debug::printr($requete);
-
 
41
		} elseif ($resultat) {
-
 
42
			$resultat_formate = $this->retournerResultatFormate($resultat);
-
 
43
		} else {
-
 
44
			if ($this->format_reponse == 'images/relations') {
-
 
45
				$resultat_formate = 'null';
-
 
46
			} else {
-
 
Line 47... Line -...
47
				$m = 'Données introuvables dans la base';
-
 
Line 48... Line 43...
48
				$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$m);
43
		$versionResultat = $this->traiterResultat($resultat, $this->table, $requete);
49
				Debug::printr($requete);
-
 
50
			}
-
 
51
		}
44
		$resultats = $versionResultat;
52
	}
-
 
53
	
-
 
54
//-------------------------------------------------------TRAITER RESSOURCES----------------------------------------------
45
		return $resultats;
55
		
46
	}
56
	public function traiterRessources(&$ressources) {
-
 
57
		if (isset($ressources) && !empty($ressources)) {
-
 
58
			$this->table_ressources = $ressources;
47
	
59
			//traiter ressources/id
-
 
60
			if ($ressources[0] == 'relations') {
-
 
61
				$this->traiterRelationsProjet($ressources);
-
 
62
				$this->format_reponse .= '/relations';
48
	//+-----------------------------------traitement ressources et paramètres --------------------------------+
63
			} elseif (isset($this->table_ressources[0]) && !empty($this->table_ressources[0])) {
-
 
64
				$this->traiterRessourceId($this->table_ressources[0]);
-
 
65
				//traiter ressources/id/champ
-
 
66
				if (isset($this->table_ressources[1]) && !empty($this->table_ressources[1])) {
-
 
67
					$this->format_reponse .= '/id/champ';
-
 
68
				}
49
	
69
			}
50
	
70
		} 
51
	public function traiterRessources() {
71
	}
52
			if (empty($this->ressources) ) {
72
	
-
 
73
	public function traiterRelationsProjet($tab_ress) {
53
				if (isset($this->parametres['masque.nn']) == false
Line 74... Line -...
74
		$projet = $tab_ress[1];
-
 
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);
-
 
79
		}
-
 
80
		$this->requete_condition[] = "num_nom = ".$this->getBdd()->proteger($num_nom);
-
 
81
	}
-
 
82
		
54
				&& isset($this->parametres['masque.nt']) == false) {
83
	public function traiterRessourceId($id) {
-
 
84
		$this->format_reponse .= '/id';
-
 
85
		$this->requete_condition[] = 'id_image LIKE '.$this->getBdd()->proteger($id.'.png');
-
 
86
	}
-
 
87
	
-
 
88
	
-
 
89
//-------------------------------------------------------TRAITER PARAMETRES----------------------------------------------
55
				$this->requete_condition[] = " flore_bdtfx_nt != '' AND flore_bdtfx_nn != '' ";
90
	
56
				}
91
	public function traiterParametres($parametres) {
57
			} else {
92
		if (isset($parametres) && !empty($parametres)) {
58
				$e = "La ressource {$this->ressources[0]} n'existe pas.";
-
 
59
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
93
			$this->table_param = $parametres;
60
			}
94
			//print_r($parametres);
61
	}
-
 
62
	
95
			if (isset($parametres['recherche']) && $parametres['recherche'] != '') {
63
	public function traiterParametres() {
96
				$this->recherche = $parametres['recherche'];
64
		foreach ($this->parametres as $param => $val ) {
-
 
65
			switch ($param) {
97
			}
66
				case 'masque.nt' :
98
			foreach ($parametres as $param => $val) {
67
					$this->analyserMasque($val,'nt');
99
				switch ($param) {
68
					break;
100
					case 'retour_format'	: $this->retour_format = $val;									break;
69
				case 'masque.nn' :
101
					case 'masque_nn' 		: $this->ajouterLeFiltreMasque('num_nom', $val);				break;
70
					$this->analyserMasque($val,'nn');
102
					case 'masque_no'		: $this->ajouterLeFiltreMasque('nom_photographe', $val);		break;
71
					break;
103
					case 'masque_ns'		: $this->ajouterLeFiltreMasque('nom_sci', $val);				break;
72
				case 'navigation.depart' :
104
					case 'masque_date'		: $this->ajouterLeFiltreMasque('date', $val);					break;
73
					$this->limite_requete['depart'] = $val;
105
					case 'masque_station'	: $this->ajouterLeFiltreMasque('station', $val);				break;
74
					break;
106
					case 'navigation_depart': $this->limite_requete['depart'] = $val;						break;
75
				case 'navigation.limite' :
107
					case 'navigation_limite': $this->limite_requete['limite'] = $val;						break;
76
					$this->limite_requete['limite'] = $val;
108
					case 'recherche'		: 																break;
-
 
Line 109... Line 77...
109
					default					: 
77
					break;
110
						$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le parametre " '
78
				default : 
111
							.$param.' " n\'existe pas.';
79
					$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le parametre " '
112
						$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
-
 
113
						break;
80
					.$param.' " n\'existe pas.';
114
				}
81
					$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
115
			}
-
 
116
		}
82
					break;
117
	}
83
			}
118
	
84
		}
119
	public function ajouterLeFiltreMasque($masque, $valeur) {
85
	}
120
		if ($this->recherche == 'etendue') {
86
	
121
			$valeur = '%'.str_replace(' ','%', $valeur).'%';
87
	/*private function traiterVersion() {
122
		}
88
		if( isset($this->parametres['version.projet']) ) {
123
		//$this->table .= ', '.Config::get("bdd_table").'_v0_1 c';
89
			$version = $this->parametres['version.projet'];
-
 
90
			if (preg_match('/^([0-9]+(?:[._][0-9]+|))$/', $version, $retour)) {
124
		switch ($masque) {
91
					$this->version[] = $retour[0];
125
			case 'nom_sci' : 
92
					$this->version_projet[] = 'v'.str_replace('.', '_', $this->version[0]);
126
				$this->requete_champ = 'cb.*';
-
 
127
				$this->table[] = ' cb , '.Config::get("bdd_table").'_v0_1 c';
-
 
128
				$this->requete_condition[] = 'c.nom_sci LIKE '
-
 
129
											.$this->getBdd()->proteger($valeur);
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();
-
 
98
					$total = count($this->metadonnees);
-
 
99
					for($i = 0 ; $i < $total ; $i++) {
130
				$this->requete_condition[] = 'c.num_nom_coste = CONCAT(cb.id_image,\',.png\')';
100
						$this->version[$i] = $this->metadonnees[$i]['version'];
Line 131... Line -...
131
				$this->ajouterRechercheFloue('nom_sci', $valeur);
-
 
132
				break;
-
 
133
			case 'num_nom'	: 
-
 
134
				$val = (strrpos($valeur, ',') !== false)? " IN (".str_replace(',', '.png,', $valeur).")" : " = ".$this->getBdd()->proteger($valeur.".png");
-
 
135
				$this->requete_condition[] =  "id_image $val";
-
 
136
				break;
-
 
137
			default 		: 	
-
 
138
				break;
-
 
139
		}
101
						$this->version_projet[$i] = 'v'.str_replace('.', '_',$this->version[$i]);
-
 
102
						$this->table_version[$i] = Config::get('bdd_table').''.$this->version_projet[$i];
-
 
103
					}
-
 
104
				}else {
-
 
105
					$e = 'Erreur parametre version inconnu. ';
-
 
106
					$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
-
 
107
				}
140
	}
108
		} else {
Line -... Line 109...
-
 
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];
Line -... Line 119...
-
 
119
	}
-
 
120
 
Line 141... Line -...
141
	
-
 
Line 142... Line -...
142
	public function ajouterRechercheFloue($nom_champ, $id) {
-
 
143
		if ($this->recherche == 'floue') {
-
 
144
			$id = $this->getBdd()->proteger($id);
-
 
145
			$this->requete_condition[array_search("$nom_champ LIKE $id", 
-
 
146
				$this->requete_condition)] = 
-
 
147
				"($nom_champ LIKE $id)".
-
 
148
				" OR ( SOUNDEX($nom_champ) = SOUNDEX($id))".
-
 
149
				" OR SOUNDEX(REVERSE($nom_champ)) = SOUNDEX(REVERSE($id))))";
-
 
Line 150... Line 121...
150
		}
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) {
-
 
127
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
-
 
128
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
129
			throw new Exception($message, $code);
-
 
130
		}
151
	}
131
	 
152
	
132
		$this->metadonnees = $resultats;
153
	
133
	}*/
-
 
134
 
-
 
135
 
154
	
136
	
155
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
-
 
156
	
137
	private function analyserMasque($valeur, $type_masque) {
157
	public function assemblerLaRequete() {
-
 
158
		$requete = 	' SELECT '.$this->requete_champ.
-
 
159
					' FROM '.implode(', ', $this->table)
-
 
160
					.$this->formerRequeteCondition()
138
		$this->masque[] = "$type_masque=$valeur";
161
					.$this->requete_group_by
-
 
162
					.$this->formerRequeteLimite();
-
 
163
		return $requete;
-
 
164
	}
-
 
165
 
139
		if (empty($valeur)) {
-
 
140
			$e = 'renseignez une valeur pour masque.nn';
166
	public  function formerRequeteCondition() {
141
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
167
		$condition = '';
142
		} elseif (preg_match('/^[0-9]+$/', $valeur)) {
168
		if ($this->requete_condition !== null) { 
-
 
169
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
143
			$this->requete_condition[] = " flore_bdtfx_".$type_masque." = $valeur";
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'))) {
-
 
176
			$this->requete_limite = ''; 
-
 
177
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
-
 
178
			$this->limite_requete['depart'] = 
-
 
179
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
-
 
180
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite']; 
-
 
181
		} else {
-
 
182
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite']; 
-
 
183
		}
-
 
184
		return $this->requete_limite;
-
 
185
	}
-
 
186
	
-
 
Line 187... Line -...
187
	/**
-
 
Line 188... Line -...
188
	 * Recupere le nombre total de résultat d'une requete lancée. 
-
 
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';
-
 
Line 200... Line 144...
200
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
144
		} elseif (preg_match('/[0-9]+/', $valeur)){
201
		}
-
 
202
		return $total;
-
 
203
	}
145
			$nums = explode(',', $valeur);
204
	
146
			$total = count($nums);
205
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
-
 
206
	
-
 
207
	public function retournerResultatFormate($resultat) {
-
 
208
		$reponse = '';
147
			$condition = '';
209
		switch ($this->format_reponse) {
-
 
210
			case 'images' 				: $reponse = $this->formaterImages($resultat);  		 break;
-
 
211
			case 'images/relations' 	: $reponse = $this->formaterImagesRelations($resultat[0]);  break;
148
			for ($i = 0; $i < $total;  $i++) {
212
			case 'images/id' 			: $reponse = $this->formaterImagesId($resultat[0]); 	 break;
-
 
213
			case 'images/id/champ' 		: $reponse = $this->formaterImagesIdChamp($resultat[0]); break;
149
				$condition .= " flore_bdtfx_".$type_masque." = {$nums[$i]}";
214
			default : break;
-
 
215
		}
-
 
216
		$reponse = json_encode($reponse);
-
 
217
		return $reponse;
150
				if ($i < ($total-1) ) {
-
 
151
					$condition .= " OR ";
Line 218... Line -...
218
	}
-
 
219
	
-
 
220
	public function formaterImages($resultat) {
-
 
221
		//print_r($resultat);
-
 
222
		$this->ajouterEnteteResultat($resultat);
-
 
223
		$reponse['entete'] = $this->table_retour;
-
 
224
		$this->table_retour = array();
-
 
225
		foreach ($resultat as $images) {
-
 
226
			$id = str_replace('.png', '', $images['id_image']);
-
 
Line -... Line 152...
-
 
152
				}
Line 227... Line 153...
227
			$id_coste = $this->recupererNumNom($id);
153
			}
-
 
154
			$this->requete_condition[] = $condition;
228
			if ($id != '') {
155
		} else {
-
 
156
			$e = "valeur incorrecte pour masque.".$type_masque;
-
 
157
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
-
 
158
		}
-
 
159
	}
-
 
160
	
-
 
161
	
-
 
162
	
-
 
163
	
229
				$this->table_retour['url.image'] = Config::get('url_images').$images['id_image'];
164
	/*public function verifierFormat($format) {
230
				$this->afficherDonnees('id', $id_coste);
165
		if (in_array($format, $this->formats_supportes)) {
Line 231... Line -...
231
				$reponse['resultat'][$id] = $this->table_retour;
-
 
232
				$this->table_retour = array();
166
			$this->format_retour = $format;
233
				$reponse['resultat'][$id]['href'] = $this->ajouterHref('images', $id);
-
 
234
			}
-
 
235
		}
-
 
236
		return $reponse;
-
 
237
	}
-
 
238
	
-
 
239
	public function ajouterEnteteResultat($resultat) {
167
		} else {
240
		$this->table_retour['depart'] = $this->limite_requete['depart'];
-
 
241
		$this->table_retour['limite'] = $this->limite_requete['limite'];
168
			$e = "Le format $format demandé n'est pas disponible.";
242
		$this->table_retour['total']  = $this->total_resultat;
169
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
Line -... Line 170...
-
 
170
		}
-
 
171
	}*/
-
 
172
	
-
 
173
	
-
 
174
//+-------------------------------------------formatage résultats---------------------------------------------+
-
 
175
 
Line 243... Line 176...
243
		//formuler les urls
176
	public function retournerResultatFormate($resultat, $table) {
-
 
177
		$resultat_json = array();
244
		$url = $this->formulerUrl($this->total_resultat, '/'.$this->service);
178
			$resultat_json['entete'] = $this->formaterEnteteResultat();
-
 
179
		foreach ($resultat as $tab) {
245
		if ($url['precedent'] != '') { $this->table_retour['href.precedent'] = $url['precedent']; }
180
			$num_coste = $tab['num_nom'];
246
		if ($url['suivant']   != '') { $this->table_retour['href.suivant']   = $url['suivant']; }
181
			unset($tab['num_nom']);
247
	}
182
			$resultat_json['resultats'][$num_coste]['num_nomenclatural'] = $tab['flore_bdtfx_nn'];
248
	
183
			$resultat_json['resultats'][$num_coste]['num_taxonomique'] = $tab['flore_bdtfx_nt'];
249
	
184
			$resultat_json['resultats'][$num_coste]['binaire.href'] = $this->formaterUrlImage($tab['image']);
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']);
185
			$resultat_json['resultats'][$num_coste]['mime'] = "images/png";
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";
-
 
263
		$this->afficherDonnees('id', $id_coste);
-
 
264
		$res = $this->ajouterRelationBdnff($resultat['num_nom']);
-
 
265
		return $res;
-
 
266
	}
186
		}
267
	
-
 
268
	
-
 
269
	
-
 
270
	public function recupererNumNom($num_nom_coste) {
-
 
271
		$req = "SELECT num_nom FROM coste_v0_1 WHERE num_nom_coste = "
-
 
272
			.$this->getBdd()->proteger($num_nom_coste)." AND num_nom = num_nom_retenu";
-
 
273
		$res = $this->getBdd()->recuperer($req);
-
 
274
		if ($res) {
187
		return $resultat_json;
275
			$num_nom = $res['num_nom'];
-
 
276
		}
-
 
277
		return $num_nom;
188
	}
278
	}
189
	
Line 279... Line 190...
279
	
190
	public function formaterUrlImage($fichier) {
280
	public function ajouterRelationBdnff($num_nom) {
-
 
281
		$res = $this->table_retour;
-
 
282
		$this->table_retour = array();
-
 
283
		$this->afficherDonnees('id', $num_nom, 'bdtfx');
-
 
284
		$res['relations']['nom'] = $this->table_retour;
-
 
285
		return $res;
-
 
286
	}
-
 
Line 287... Line 191...
287
	
191
		$chemin = config::get('donnees')."2.00/img/$fichier"; 
288
	public function formaterImagesIdChamp($resultat) {
-
 
289
		//on recupère tous les resultats possibles
192
		return $chemin;
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]);
193
	}
295
		foreach ($champs as $champ) {
-
 
296
			if ($this->verifierValiditeChamp($champ, $reponse_id)) {
-
 
297
				if (preg_match('/^[^.]+\.\*$/', $champ)) {
194
	
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) {
195
 
308
		preg_match('/^([^.]+\.)\*$/', $champ, $match);
196
	/*public function donnerVersionDuneTable($table) {
Line 309... Line -...
309
		foreach ($reponse_id as $chp => $valeur) {
-
 
Line 310... Line 197...
310
			if (strrpos($chp, $match[1]) !== false) {
197
		$version = strstr($table,'v');
311
				$this->table_retour[$chp] = $valeur;
198
		$version = str_replace('v','', $version);
312
			}
-
 
313
		}
199
		$version = str_replace('_','.', $version);
314
	}
-
 
315
	
200
		return $version;
316
	public function verifierValiditeChamp($champ, $reponse_id) {
201
	}*/
-
 
202
	
317
		$validite = false;
203
	public function formaterEnteteResultat() {
Line -... Line 204...
-
 
204
		$entete['depart'] = $this->limite_requete['depart'];
-
 
205
		$entete['limite'] = $this->limite_requete['limite'];
318
		preg_match('/^([^.]+)(:?\.([^.]+))?$/', $champ, $match);
206
		$entete['total']  =  $this->total_resultat;
319
		if (array_key_exists($match[1], $reponse_id)) {
207
		$entete['masque']  = empty($this->masque) ? 'aucun' : implode('&', $this->masque);
320
			$validite = true;
-
 
321
			if (isset($match[2]) && !empty($match[2])) {
208
		$url = $this->formulerUrl($this->total_resultat, '/images');
322
				if ($match[1] == 'type') {
209
		if (isset($url['precedent']) && $url['precedent'] != '') {
323
					$suffixes = array('.code', '.href', '.*');
-
 
324
				$validite = (in_array($match[2], $suffixes)) ? true : false;
-
 
325
				} else {
210
			$entete['href.precedent'] = $url['precedent'];
326
					$validite = false;
211
		}
327
				}
-
 
328
			}
-
 
329
		} 
212
		if (isset($url['suivant']) && $url['suivant'] != '') {
330
		if (!$validite) {
213
			$entete['href.suivant']   = $url['suivant'];
-
 
214
		}
-
 
215
		return $entete;
331
			$champs = implode('</li><li>', array_keys($reponse_id));
216
	}
332
			$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas. Les champs disponibles
217
	
Line 333... Line -...
333
				 sont : <li>'.$champs.'</li>';
-
 
334
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
-
 
335
		}
-
 
336
		return $validite;
-
 
337
	}
-
 
Line 338... Line 218...
338
	
218
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
-
 
219
	
-
 
220
	public function assemblerLaRequete() {
-
 
221
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
339
	
222
		.$this->retournerRequeteCondition().' '
-
 
223
		.$this->delimiterResultatsRequete();
340
//------------------------------------------------Fonction d'affichage ------------------------------------------------
224
		return $requete;
341
	
225
	}
-
 
226
	
342
	public function afficherDonnees($champ, $valeur, $projet = null) {
227
 
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) {
228
	
-
 
229
	public  function retournerRequeteCondition() {
352
		if (!$projet) $projet = 'coste';
230
		$condition = '';
Line 353... Line -...
353
		if ($champ == 'id') {
-
 
354
			$this->table_retour['nom_sci.id'] = $projet.'.'.$valeur;
231
		if (empty($this->requete_condition) == false) {
355
			$fct = "recupererNomSci".ucfirst($projet);
232
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
356
			$this->table_retour['nom_sci'] = $this->$fct($valeur);
233
		}