Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 553 | Rev 580 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 553 Rev 579
1
<?php
1
<?php
2
 
2
 
3
/**
3
/**
4
* Classe InformationsBaseflor.php permet de faire des requetes de baseflor en fonction d'un référentiel
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 ).
5
*( BDTFX, BDAFX, BDBFX ) et d'un numéro nomenclatural ( différent de 0 ).
6
*  fin d'url possibles :
6
*  fin d'url possibles :
7
*  /informations/#bdnt.nn:#num_nomen --> retourne tous les champs pour un BDNT et un num_nomen
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
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
9
*  /informations/#bdnt.nn:#num_nomen?champs=ecologie --> retourne champs ecologiques pour un BDNT et un num_nomen
10
*  
10
*  
11
*
11
*
12
* Encodage en entrée : utf8
12
* Encodage en entrée : utf8
13
* Encodage en sortie : utf8
13
* Encodage en sortie : utf8
14
* @package eflore-projets
14
* @package eflore-projets
15
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
15
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
16
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
16
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
17
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
17
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
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>
19
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
* @version 1.0
20
* @version 1.0
21
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
21
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
22
*/
22
*/
23
 
23
 
24
class InformationsBaseflor extends Commun{
24
class InformationsBaseflor extends Commun{
25
 
25
 
26
	protected $table = "";
26
	protected $table = "";
27
	private $format_reponse = 'informations';
27
	private $format_reponse = 'informations';
28
	private $retour_format = 'max';
28
	private $retour_format = 'max';
29
	private $champs_ontologiques = array();
29
	private $champs_ontologiques = array();
30
	protected $serviceNom = 'informations';
30
	protected $serviceNom = 'informations';
31
	private $Bdd;
31
	private $Bdd;
32
	private $requete_condition = "";
32
	private $requete_condition = "";
33
	private $champs_recherches = '*';
33
	private $champs_recherches = '*';
34
	private $resultat_json;
34
	private $resultat_json;
-
 
35
	private $nb_ressources;
-
 
36
	protected $limite_requete = array( 'depart' => 0, 'limite' => 10);
35
	
37
	
36
 
38
 
37
	public function consulter($ressources, $parametres) {
39
	public function consulter($ressources, $parametres) {
38
		$this->ressources = $ressources;
40
		$this->ressources = $ressources;
39
		$this->parametres = $parametres;
41
		$this->parametres = $parametres;
-
 
42
		$this->nb_ressources = count($ressources);
40
		$this->traiterParametres();
43
		$this->traiterParametres();
41
		$this->definirTables();
44
		$this->definirTables();
42
		$this->traiterRessources();
45
		$this->traiterRessources();
43
		$resultats = null;
46
		$resultats = null;
44
		foreach ($this->table_version as $version) {
47
		foreach ($this->table_version as $version) {
45
			$this->table = $version;
48
			$this->table = $version;
46
			$requete = $this->assemblerLaRequete();
49
			$requete = $this->assemblerLaRequete($table);
47
			$resultat =  $this->Bdd->recupererTous($requete);
50
			$resultat =  $this->Bdd->recupererTous($requete);
48
			$versionResultat = $this->analyserResultat($resultat);
51
			$versionResultat = $this->analyserResultat($resultat);
49
			if (count($this->table_version) > 1) {
52
			if (count($this->table_version) > 1) {
50
				$resultats[$version] = $versionResultat;
53
				$resultats[$version] = $versionResultat;
51
			} else {
54
			} else {
52
				$resultats = $versionResultat;
55
				$resultats = $versionResultat;
53
			}
56
			}
54
		}
57
		}
55
		return $resultats;
58
		return $resultats;
56
	}
59
	}
57
 
60
 
58
	public function __construct(Conteneur $Conteneur) {
61
	public function __construct(Conteneur $Conteneur) {
59
		$this->Bdd = $Conteneur->getBdd();
62
		$this->Bdd = $Conteneur->getBdd();
60
	}
63
	}
61
	
64
	
62
	
65
	
63
	public function analyserResultat($resultat) {
66
	public function analyserResultat($resultat) {
64
		$versionResultat = null;
67
		$versionResultat = null;
65
		if ($resultat == '') {
68
		if ($resultat == '') {
66
			$message = 'La requête SQL formée comporte une erreur!';
69
			$message = 'La requête SQL formée comporte une erreur!';
67
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
70
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
68
			throw new Exception($message, $code);
71
			throw new Exception($message, $code);
69
		} elseif ($resultat) {
72
		} elseif ($resultat) {
70
			$versionResultat = $this->retournerResultatFormate($resultat);
73
			$versionResultat = $this->retournerResultatFormate($resultat);
71
		}
74
		}
72
		return $versionResultat;
75
		return $versionResultat;
73
	}
76
	}
74
 
77
 
75
//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
78
//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
76
	public function traiterParametres() {
79
	public function traiterParametres() {
77
		if (isset($this->parametres) && !empty($this->parametres)) {
80
		if (isset($this->parametres) && !empty($this->parametres)) {
78
			foreach ($this->parametres as $param => $valeur) {
81
			foreach ($this->parametres as $param => $valeur) {
79
				switch ($param) {
82
				switch ($param) {
80
					case 'categorie'  :
83
					case 'categorie'  :
81
						if ($valeur == "description") {
84
						if ($valeur == "description" &&  $this->nb_ressources == 1 ) {
82
							$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
85
							$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
83
								." sexualite, ordre_maturation, "
86
								." sexualite, ordre_maturation, "
84
								."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
87
								."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
85
						 		."form_vegetale ";
88
						 		."form_vegetale ";
86
							$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
89
							$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
87
								"OR  sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
90
								"OR  sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
88
								"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
91
								"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
89
								"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
92
								"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
90
						}elseif ($valeur == "ecologie") {
93
						}elseif ($valeur == "ecologie" && $this->nb_ressources == 1) {
91
							$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
94
							$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
92
								." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
95
								." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
93
								." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
96
								." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
94
								." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
97
								." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
95
								." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
98
								." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
96
							$this->requete_condition[] = "( ve_lumiere  != '' OR ve_temperature != '' ".
99
							$this->requete_condition[] = "( ve_lumiere  != '' OR ve_temperature != '' ".
97
								"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
100
								"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
98
								"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
101
								"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
99
								"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
102
								"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
100
								"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
103
								"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
101
						} else {
104
						} else {
102
							$e = "Valeur de paramètre inconnue pour 'categorie'.";
105
							$e = "Valeur de paramètre inconnue pour 'categorie'. Ce paramètre n'est pas autorisé pour informations/#id/relations/catminat";
103
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
106
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
104
						}
107
						}
105
						break;
108
						break;
106
					case 'retour.format'  :
109
					case 'retour.format'  :
107
						if ($valeur == 'min' || $valeur == 'max') {
110
						if ($valeur == 'min' || $valeur == 'max' && $this->nb_ressources == 1) {
108
							$this->retour_format = $valeur;
111
							$this->retour_format = $valeur;
109
							break;
112
							
110
						} else {
113
						} else {
111
							$e = "Valeur de paramètre inconnue pour 'retour.format'.";
114
							$e = "Valeur de paramètre inconnue pour 'retour.format'. Ce paramètre n'est pas autorisé pour informations/#id/relations/catminat";
112
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
115
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
113
						}
116
						}
-
 
117
						break;
-
 
118
					case 'navigation.depart'  :
-
 
119
						$this->definirNavigationDepart($valeur);
-
 
120
						break;
-
 
121
					case 'navigation.limite'  :
-
 
122
						$this->definirNavigationLimite($valeur);
-
 
123
						break;
114
					case 'version.projet' :
124
					case 'version.projet' :
115
						$this->traiterVersion($valeur);
125
						$this->traiterVersion($valeur);
116
						break;
126
						break;
117
					default :
127
					default :
118
						$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
128
						$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
119
							.$param.' " n\'existe pas.';
129
							.$param.' " n\'existe pas.';
120
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);	
130
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);	
121
						break;
131
						break;
122
				}
132
				}
123
			}
133
			}
124
		}
134
		}
125
	}
135
	}
126
	
136
	
127
	
137
	
128
 
138
 
129
	public function traiterRessources() {
139
	public function traiterRessources() {
130
			if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
140
			if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
131
				switch ($retour[1]) {
141
				$id = $retour[2];
132
					case 'bdtfx' :
142
				$ref = $retour[1];
133
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
143
				if ($ref == 'bdtfx' || $ref == 'bdafx' || $ref == 'bdbfx') {
134
						break;
-
 
135
					case  'bdafx' :
144
					if($this->nb_ressources == 1) {
136
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
145
						$this->requete_condition[] = "num_nomen = ".$id." AND BDNT = '".strtoupper($ref)."' ";
137
						break;
146
					} else {
138
					case  'bdbfx' :
-
 
139
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
147
						$this->definirParametresRequeteRelations($ref, $id);
140
						break;
148
					}
141
					default :
149
				} else {
142
						$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
150
					$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
143
							.$retour[1].' " n\'existe pas.';
151
					.$ref.' " n\'existe pas.';
144
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
152
					throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
145
						break;
-
 
146
				}
153
				}
147
 
154
 
148
			} else {
155
			} else {
149
				$e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.';
156
				$e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.';
150
				throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
157
				throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
151
				break;
158
				break;
152
			}
159
			}
-
 
160
			
-
 
161
	}
-
 
162
	
-
 
163
	function definirParametresRequeteRelations($ref, $id){
-
 
164
		if ($this->ressources[1] == 'relations'){
-
 
165
			switch ($this->ressources[2]) {
-
 
166
				case 'catminat' :
-
 
167
					$this->requete_condition[] = "catminat_code = ( SELECT catminat_code from ".$this->table_version[0]." WHERE "
-
 
168
					." num_nomen = ".$id." AND BDNT = '".$ref. "' ) ";
-
 
169
					$this->champs_recherches = " catminat_code, num_nomen, BDNT ";
-
 
170
					break;
-
 
171
				default :
-
 
172
					$e = 'Erreur dans l\'url de votre requête : </br> Le type de relation " '
-
 
173
				.$this->ressources[2].' " n\'existe pas.';
-
 
174
				throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
-
 
175
				break;
-
 
176
			}
-
 
177
		} else {
-
 
178
			$e = 'Erreur dans l\'url de votre requête : </br> Le type de ressources " '
-
 
179
			.$this->ressources[1].' " n\'existe pas.';
-
 
180
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
-
 
181
		}
153
	}
182
	}
-
 
183
	
154
	
184
	
155
	//+++------------------------------traitement des versions----------------------------------------++
185
	//+++------------------------------traitement des versions----------------------------------------++
156
	
186
	
157
	public function traiterVersion($valeur) {
187
	public function traiterVersion($valeur) {
158
		if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '*' || $valeur == '+') {
188
		if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '+') {
159
			$this->version_projet = $valeur;
189
			$this->version_projet = $valeur;
-
 
190
		} elseif ($valeur == '*') {
-
 
191
			$this->version_projet = ($this->nb_ressources == 1) ? $valeur : '+' ;
160
		} else {
192
		} else {
161
			$e = "Erreur : La version est inconnue.";
193
			$e = "Erreur : La version est inconnue.";
162
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
194
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
163
		}
195
		}
164
		
196
		
165
	}
197
	}
166
	
198
	
167
	public function definirTables() {
199
	public function definirTables() {
168
		$table_num_version = $this->recupererVersionDisponible();
200
		$table_num_version = $this->recupererVersionDisponible();
169
		$prefixe_table = config::get('bdd_table');
201
		$prefixe_table = config::get('bdd_table');
170
		if ( in_array($this->version_projet,$table_num_version) ) {
202
		if ( in_array($this->version_projet,$table_num_version) ) {
171
			$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
203
			$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
172
		} elseif ($this->version_projet == '+') {
204
		} elseif ($this->version_projet == '+') {
173
					$derniere_version = $table_num_version[count($table_num_version) - 1];
205
					$derniere_version = $table_num_version[count($table_num_version) - 1];
174
					$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
206
					$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
175
		} elseif ($this->version_projet == '*') {
207
		} elseif ($this->version_projet == '*') {
176
			foreach ($table_num_version as $num_version) {
208
			foreach ($table_num_version as $num_version) {
177
				$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
209
				$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
178
			}
210
			}
179
		} else {
211
		} else {
180
			$e = "Erreur : La version est inconnue.";
212
			$e = "Erreur : La version est inconnue.";
181
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
213
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
182
		}
214
		}
183
	}
215
	}
184
	
216
	
185
//+--------------------------formatages de resultats  -------------------------------------------+
217
//+--------------------------formatages de resultats  -------------------------------------------+
186
	
218
	
187
	public function retournerResultatFormate($resultat) {
219
	public function retournerResultatFormate($resultat) {
188
		$resultat_json = $resultat[0];
220
		$resultat_json = $resultat[0];
189
		if ($this->retour_format == 'max'){
221
		if ($this->retour_format == 'max'){
-
 
222
			if ($this->nb_ressources == 1) {		
190
			if (!isset($this->parametres['categorie']) ) {
223
				if ($this->parametres['categorie'] == 'ecologie') {
191
				$this->formaterResultatsTousChamps($resultat_json);
224
					$this->formaterResultatsChampsEcologie($resultat_json);
192
			} elseif ($this->parametres['categorie'] == 'ecologie') {
225
				} elseif ($this->parametres['categorie'] == 'description') {
193
				 $this->formaterResultatsChampsEcologie($resultat_json);
226
					$this->formaterResultatsChampsDescription($resultat_json);
-
 
227
				}else {
194
			} elseif ($this->parametres['categorie'] == 'description') {
228
					$this->formaterResultatsTousChamps($resultat_json);
-
 
229
				}
-
 
230
			} else {
195
				 $this->formaterResultatsChampsDescription($resultat_json);
231
				$this->formaterResultatsRelations($resultat);
196
			}
232
			}
197
		} else {
233
		} else {
198
			$this->resultat_json = $resultat_json;
234
			$this->resultat_json = $resultat_json;
199
		}
235
		}
200
		return $this->resultat_json;
236
		return $this->resultat_json;
201
	}
237
	}
-
 
238
	
-
 
239
	public function formaterResultatsRelations($resultat) {
-
 
240
		$this->resultat_json['entete'] = $this->ajouterEnteteResultat();
-
 
241
		$resultat_json = array();
-
 
242
		foreach ($resultat as $cle => $res){
-
 
243
			$resultat_json[$cle] = $res ;
-
 
244
			$resultat_json[$cle]['href'] = $this->ajouterHref('informations',strtolower($res['BDNT']).".nn:".$res['num_nomen']);
-
 
245
		}
-
 
246
		$this->resultat_json['resultat'] = $resultat_json;
-
 
247
	}
-
 
248
	
-
 
249
	public function ajouterEnteteResultat($id) {
-
 
250
		$entete['depart'] = $this->limite_requete['depart'];
-
 
251
		$entete['limite'] = $this->limite_requete['limite'];
-
 
252
		$entete['total']  =  $this->total_resultat;
-
 
253
		$entete['version']  = $this->version_projet;
-
 
254
		$url = $this->formulerUrl($this->total_resultat, '/informations/'.$this->ressources[0].'/relations/catminat');
-
 
255
		if (isset($url['precedent']) && $url['precedent'] != '') {
-
 
256
			$entete['href.precedent'] = $url['precedent'];
-
 
257
		}
-
 
258
		if (isset($url['suivant']) && $url['suivant'] != '') {
-
 
259
			$entete['href.suivant']   = $url['suivant'];
-
 
260
		}
-
 
261
		return $entete;
-
 
262
	}
202
 
263
 
203
	public function formaterResultatsTousChamps($resultat) {
264
	public function formaterResultatsTousChamps($resultat) {
204
		$this->resultat_json = $resultat;
265
		$this->resultat_json = $resultat;
205
		$this->traiterTypeBio();	
266
		$this->traiterTypeBio();	
206
		$graphique_presence = $this->traiterOntologieEcologie() ;
267
		$graphique_presence = $this->traiterOntologieEcologie() ;
207
		if ($graphique_presence) {
268
		if ($graphique_presence) {
208
			$graphique = $this->ajouterLiensGraphique();
269
			$graphique = $this->ajouterLiensGraphique();
209
					}
270
					}
210
	}
271
	}
211
	
272
	
212
	public function formaterResultatsChampsEcologie($resultat) {
273
	public function formaterResultatsChampsEcologie($resultat) {
213
		$this->resultat_json = $resultat;
274
		$this->resultat_json = $resultat;
214
		$graphique_presence = $this->traiterOntologieEcologie() ;
275
		$graphique_presence = $this->traiterOntologieEcologie() ;
215
		if ($graphique_presence) {
276
		if ($graphique_presence) {
216
			$graphique = $this->ajouterLiensGraphique();
277
			$graphique = $this->ajouterLiensGraphique();
217
		}
278
		}
218
	}
279
	}
219
	
280
	
220
	
281
	
221
	public function formaterResultatsChampsDescription($resultat) {
282
	public function formaterResultatsChampsDescription($resultat) {
222
	$this->resultat_json = $resultat;
283
	$this->resultat_json = $resultat;
223
	$this->traiterTypeBio();
284
	$this->traiterTypeBio();
224
	}
285
	}
225
	
286
	
226
	public function traiterOntologieEcologie() {
287
	public function traiterOntologieEcologie() {
227
		$donnees_presence =  false;
288
		$donnees_presence =  false;
228
		$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
289
		$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
229
		foreach ($this->champs_ontologiques as $cle => $valeur){
290
		foreach ($this->champs_ontologiques as $cle => $valeur){
230
			if ($this->resultat_json[$cle] != ""){
291
			if ($this->resultat_json[$cle] != ""){
231
				$donnees_presence =  true;
292
				$donnees_presence =  true;
232
				$this->recupererOntologies($this->resultat_json[$cle], $cle);
293
				$this->recupererOntologies($this->resultat_json[$cle], $cle);
233
				unset($this->resultat_json[$cle]);
294
				unset($this->resultat_json[$cle]);
234
			}
295
			}
235
		}
296
		}
236
		return $donnees_presence;
297
		return $donnees_presence;
237
	}
298
	}
238
	
299
	
239
	public function traiterTypeBio() {
300
	public function traiterTypeBio() {
240
		if ($this->resultat_json['type_bio'] != ""){
301
		if ($this->resultat_json['type_bio'] != ""){
241
			$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
302
			$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
242
			unset($this->resultat_json['type_bio']);
303
			unset($this->resultat_json['type_bio']);
243
			$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
304
			$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
244
		}
305
		}
245
	}
306
	}
246
 
307
 
247
	public function ajouterLiensGraphique() {
308
	public function ajouterLiensGraphique() {
248
		$this->resultat_json['graphique_climat']['libelle'] = 'climat';
309
		$this->resultat_json['graphique_climat']['libelle'] = 'climat';
249
		$this->resultat_json['graphique_climat']['href'] = 
310
		$this->resultat_json['graphique_climat']['href'] = 
250
			$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
311
			$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
251
		$this->resultat_json['graphique_sol']['libelle'] = 'sol';
312
		$this->resultat_json['graphique_sol']['libelle'] = 'sol';
252
		$this->resultat_json['graphique_sol']['href'] = 
313
		$this->resultat_json['graphique_sol']['href'] = 
253
			$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
314
			$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
254
	}
315
	}
255
	
316
	
256
	
317
	
257
//+--------------------------traitement ontologies -------------------------------------------+
318
//+--------------------------traitement ontologies -------------------------------------------+
258
 
319
 
259
	public function recupererOntologies($valeur, $champs){
320
	public function recupererOntologies($valeur, $champs){
260
		$url = Config::get('url_service_base').Config::get('nom_projet').
321
		$url = Config::get('url_service_base').Config::get('nom_projet').
261
			'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
322
			'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
262
		$val = $this->consulterHref($url);
323
		$val = $this->consulterHref($url);
263
		$this->resultat_json[$champs.'.libelle'] = $val->nom;
324
		$this->resultat_json[$champs.'.libelle'] = $val->nom;
264
		$this->resultat_json[$champs.'.code'] = $valeur;
325
		$this->resultat_json[$champs.'.code'] = $valeur;
265
		$this->resultat_json[$champs.'.href'] = $url;
326
		$this->resultat_json[$champs.'.href'] = $url;
266
	}
327
	}
267
	
328
	
268
	//+-------------ontologie pour le champs type biologique (lire le .txt)---+
329
	//+-------------ontologie pour le champs type biologique (lire le .txt)---+
269
 
330
 
270
	public function recupererOntologiePrTypeBio($type_a_traiter){
331
	public function recupererOntologiePrTypeBio($type_a_traiter){
271
		$resultat_typeBio = "";
332
		$resultat_typeBio = "";
272
		if ($type_a_traiter != "") {
333
		if ($type_a_traiter != "") {
273
			$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
334
			$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
274
			$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
335
			$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
275
			$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
336
			$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
276
		}
337
		}
277
		return $resultat_typeBio;
338
		return $resultat_typeBio;
278
	}
339
	}
279
	
340
	
280
	public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
341
	public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
281
		$types_sstypes = '';
342
		$types_sstypes = '';
282
		foreach ($types_prim_sec as $cle => $tb) {
343
		foreach ($types_prim_sec as $cle => $tb) {
283
			$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
344
			$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
284
		}
345
		}
285
		switch (count($types_sstypes)) {
346
		switch (count($types_sstypes)) {
286
			case 1 : 
347
			case 1 : 
287
				$types_sstypes = $types_sstypes['principal'];
348
				$types_sstypes = $types_sstypes['principal'];
288
				break;
349
				break;
289
			case 2 : 
350
			case 2 : 
290
				$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
351
				$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
291
				break;
352
				break;
292
		}
353
		}
293
		return $types_sstypes;
354
		return $types_sstypes;
294
	}
355
	}
295
	
356
	
296
 
357
 
297
	public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
358
	public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
298
		$resultat_typeBio['type_bio.code'] = $type_a_traiter;
359
		$resultat_typeBio['type_bio.code'] = $type_a_traiter;
299
		foreach ($types_sstypes as $cle => $tb) {
360
		foreach ($types_sstypes as $cle => $tb) {
300
			if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
361
			if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
301
				$i = 0;
362
				$i = 0;
302
				foreach ($tb as $types) {
363
				foreach ($tb as $types) {
303
					$url = Config::get('url_service_base').Config::get('nom_projet').
364
					$url = Config::get('url_service_base').Config::get('nom_projet').
304
						'/ontologies/TB:'.urlencode(urlencode($types));
365
						'/ontologies/TB:'.urlencode(urlencode($types));
305
					$val = $this->consulterHref($url);
366
					$val = $this->consulterHref($url);
306
					$libelle[$cle][$i]= $val->nom;
367
					$libelle[$cle][$i]= $val->nom;
307
					$detail[$cle][$i]['libelle'] = $val->nom;
368
					$detail[$cle][$i]['libelle'] = $val->nom;
308
					$detail[$cle][$i]['code'] = $val->code;
369
					$detail[$cle][$i]['code'] = $val->code;
309
					$detail[$cle][$i]['href'] = $url;
370
					$detail[$cle][$i]['href'] = $url;
310
					$i++;
371
					$i++;
311
				}
372
				}
312
			}
373
			}
313
			if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
374
			if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
314
				$i = 0;
375
				$i = 0;
315
				foreach ($tb as $sstypes) {
376
				foreach ($tb as $sstypes) {
316
					$url = Config::get('url_service_base').Config::get('nom_projet').
377
					$url = Config::get('url_service_base').Config::get('nom_projet').
317
								'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
378
								'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
318
					$val = $this->consulterHref($url);
379
					$val = $this->consulterHref($url);
319
					$libelle[$cle][$i]=$val->nom;
380
					$libelle[$cle][$i]=$val->nom;
320
					$detail[$cle][$i]['libelle'] = $val->nom;
381
					$detail[$cle][$i]['libelle'] = $val->nom;
321
					$detail[$cle][$i]['code'] = $val->code;
382
					$detail[$cle][$i]['code'] = $val->code;
322
					$detail[$cle][$i]['href'] = $url;
383
					$detail[$cle][$i]['href'] = $url;
323
					$i++;
384
					$i++;
324
				}
385
				}
325
			}
386
			}
326
		}
387
		}
327
		//var_dump($libelle); exit;
388
		//var_dump($libelle); exit;
328
		$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
389
		$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
329
		$resultat_typeBio['type_bio.detail'] = $detail;
390
		$resultat_typeBio['type_bio.detail'] = $detail;
330
		return $resultat_typeBio;
391
		return $resultat_typeBio;
331
	}
392
	}
332
	
393
	
333
	
394
	
334
	
395
	
335
	public function formaterTypeBioPrLibelle($info) {
396
	public function formaterTypeBioPrLibelle($info) {
336
		$libelle = implode(', ',$info['type.principal'])." ";
397
		$libelle = implode(', ',$info['type.principal'])." ";
337
			$libelle .= isset($info['sous_type.principal']) ? " (".implode(', ',$info['sous_type.principal']).") " : "";
398
			$libelle .= isset($info['sous_type.principal']) ? " (".implode(', ',$info['sous_type.principal']).") " : "";
338
			$libelle .= isset($info['type.secondaire']) ? ", ".implode(', ',$info['type.secondaire'])." " : "";
399
			$libelle .= isset($info['type.secondaire']) ? ", ".implode(', ',$info['type.secondaire'])." " : "";
339
			$libelle .= isset($info['sous_type.secondaire']) ? "(".implode(', ',$info['sous_type.secondaire']).") " : "";
400
			$libelle .= isset($info['sous_type.secondaire']) ? "(".implode(', ',$info['sous_type.secondaire']).") " : "";
340
		return $libelle;
401
		return $libelle;
341
	}
402
	}
342
 
403
 
343
	//séparation des principaux et des secondaires
404
	//séparation des principaux et des secondaires
344
	public function separerTypesPrimairesSecondaires($type) {
405
	public function separerTypesPrimairesSecondaires($type) {
345
		$types = array();	
406
		$types = array();	
346
		if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
407
		if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
347
			$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
408
			$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
348
			$types['secondaire'] = $retour[2];
409
			$types['secondaire'] = $retour[2];
349
		} else {
410
		} else {
350
			$types['principal'] = $type;
411
			$types['principal'] = $type;
351
		}
412
		}
352
		return $types;
413
		return $types;
353
	}
414
	}
354
 
415
 
355
	
416
	
356
	public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
417
	public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
357
		$types = array();
418
		$types = array();
358
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
419
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
359
			//type
420
			//type
360
			$type = array();
421
			$type = array();
361
			$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
422
			$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
362
			$type = explode(",", $type[0]);
423
			$type = explode(",", $type[0]);
363
			for ($i = 0 ; $i < count($type); $i++) {
424
			for ($i = 0 ; $i < count($type); $i++) {
364
				$types['type.'.$typePrimOuSec][$i] = $type[$i];
425
				$types['type.'.$typePrimOuSec][$i] = $type[$i];
365
			}
426
			}
366
			//sous types
427
			//sous types
367
			$ss_types = array();
428
			$ss_types = array();
368
			if (isset($retour[2]) && $retour[2] != '') {
429
			if (isset($retour[2]) && $retour[2] != '') {
369
 				$ss_types[0] =  $retour[2] ;
430
 				$ss_types[0] =  $retour[2] ;
370
 				$ss_types = explode("-", $ss_types[0]);
431
 				$ss_types = explode("-", $ss_types[0]);
371
				for ($i = 0 ; $i < count($ss_types); $i++) {
432
				for ($i = 0 ; $i < count($ss_types); $i++) {
372
					$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
433
					$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
373
				}
434
				}
374
			}
435
			}
375
    	}
436
    	}
376
 		return $types;
437
 		return $types;
377
 	}
438
 	}
378
 	
439
 	
379
 
440
 
380
 	
441
 	
381
 	
442
 	
382
	
443
	
383
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
444
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
384
	
445
	
385
	public function assemblerLaRequete() {
446
	public function assemblerLaRequete() {
386
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
447
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
387
		.$this->retournerRequeteCondition();
448
		.$this->retournerRequeteCondition().' ';
-
 
449
			if ($this->nb_ressources != 1) {
-
 
450
				$requete .= $this->delimiterResultatsRequete();
-
 
451
		}
388
		return $requete;
452
		return $requete;
389
	}
453
	}
-
 
454
	
-
 
455
	public function calculerTotalResultat() {
-
 
456
		$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '.$this->retournerRequeteCondition();
-
 
457
		$res = $this->getBdd()->recuperer($requete);
-
 
458
		if ($res) {
-
 
459
			$this->total_resultat = $res['nombre'];
-
 
460
		} else {
-
 
461
			$this->total_resultat = 0;
-
 
462
			$e = 'Données introuvables dans la base';
-
 
463
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
-
 
464
		}
-
 
465
	}
-
 
466
	
-
 
467
	public function delimiterResultatsRequete() {
-
 
468
		$this->calculerTotalResultat();
-
 
469
		$requete_limite = '';
-
 
470
		if (($this->limite_requete['depart'] <=  $this->total_resultat) ){
-
 
471
			if (($this->limite_requete['limite'] + $this->limite_requete['depart'] )
-
 
472
			< $this->total_resultat  ){
-
 
473
				$requete_limite = 'LIMIT '.$this->limite_requete['depart'].', '
-
 
474
				.$this->limite_requete['limite'];
-
 
475
			}
-
 
476
		} else {
-
 
477
			$e = "Erreur : la valeur pour le paramètre navigation.départ est supérieure".
-
 
478
						" au nombre total de résultats.";
-
 
479
			throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
-
 
480
		}
-
 
481
		return $requete_limite;
-
 
482
	}
390
	
483
	
391
	
484
	
392
	
485
	
393
	public  function retournerRequeteCondition() {
486
	public  function retournerRequeteCondition() {
394
		$condition = '';
487
		$condition = '';
395
		if (empty($this->requete_condition) == false) {
488
		if (empty($this->requete_condition) == false) {
396
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
489
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
397
		}
490
		}
398
		return $condition;
491
		return $condition;
399
	}
492
	}
400
 
493
 
401
 
494
 
402
	
495
	
403
}
496
}
404
?>
497
?>