Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 548 Rev 549
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
	
35
	
36
 
36
 
37
	public function consulter($ressources, $parametres) {
37
	public function consulter($ressources, $parametres) {
38
		$this->ressources = $ressources;
38
		$this->ressources = $ressources;
39
		$this->parametres = $parametres;
39
		$this->parametres = $parametres;
40
		$this->traiterParametres();
40
		$this->traiterParametres();
41
		$this->definirTables();
41
		$this->definirTables();
42
		$this->traiterRessources();
42
		$this->traiterRessources();
43
		$resultats = null;
43
		$resultats = null;
44
		foreach ($this->table_version as $version) {
44
		foreach ($this->table_version as $version) {
45
			$this->table = $version;
45
			$this->table = $version;
46
			$requete = $this->assemblerLaRequete();
46
			$requete = $this->assemblerLaRequete();
47
			$resultat =  $this->Bdd->recupererTous($requete);
47
			$resultat =  $this->Bdd->recupererTous($requete);
48
			$versionResultat = $this->analyserResultat($resultat);
48
			$versionResultat = $this->analyserResultat($resultat);
49
			if (count($this->table_version) > 1) {
49
			if (count($this->table_version) > 1) {
50
				$resultats[$version] = $versionResultat;
50
				$resultats[$version] = $versionResultat;
51
			} else {
51
			} else {
52
				$resultats = $versionResultat;
52
				$resultats = $versionResultat;
53
			}
53
			}
54
		}
54
		}
55
		return $resultats;
55
		return $resultats;
56
	}
56
	}
57
 
57
 
58
	public function __construct(Conteneur $Conteneur) {
58
	public function __construct(Conteneur $Conteneur) {
59
		$this->Bdd = $Conteneur->getBdd();
59
		$this->Bdd = $Conteneur->getBdd();
60
	}
60
	}
61
	
61
	
62
	
62
	
63
	public function analyserResultat($resultat) {
63
	public function analyserResultat($resultat) {
64
		$versionResultat = null;
64
		$versionResultat = null;
65
		if ($resultat == '') {
65
		if ($resultat == '') {
66
			$message = 'La requête SQL formée comporte une erreur!';
66
			$message = 'La requête SQL formée comporte une erreur!';
67
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
67
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
68
			throw new Exception($message, $code);
68
			throw new Exception($message, $code);
69
		} elseif ($resultat) {
69
		} elseif ($resultat) {
70
			$versionResultat = $this->retournerResultatFormate($resultat);
70
			$versionResultat = $this->retournerResultatFormate($resultat);
71
		}
71
		}
72
		return $versionResultat;
72
		return $versionResultat;
73
	}
73
	}
74
 
74
 
75
//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
75
//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
76
	public function traiterParametres() {
76
	public function traiterParametres() {
77
		if (isset($this->parametres) && !empty($this->parametres)) {
77
		if (isset($this->parametres) && !empty($this->parametres)) {
78
			foreach ($this->parametres as $param => $valeur) {
78
			foreach ($this->parametres as $param => $valeur) {
79
				switch ($param) {
79
				switch ($param) {
80
					case 'categorie'  :
80
					case 'categorie'  :
81
						if ($valeur == "description") {
81
						if ($valeur == "description") {
82
							$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
82
							$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
83
								." sexualite, ordre_maturation, "
83
								." sexualite, ordre_maturation, "
84
								."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
84
								."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
85
						 		."form_vegetale ";
85
						 		."form_vegetale ";
86
							$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
86
							$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
87
								"OR  sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
87
								"OR  sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
88
								"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
88
								"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
89
								"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
89
								"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
90
						}elseif ($valeur == "ecologie") {
90
						}elseif ($valeur == "ecologie") {
91
							$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
91
							$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
92
								." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
92
								." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
93
								." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
93
								." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
94
								." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
94
								." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
95
								." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
95
								." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
96
							$this->requete_condition[] = "( ve_lumiere  != '' OR ve_temperature != '' ".
96
							$this->requete_condition[] = "( ve_lumiere  != '' OR ve_temperature != '' ".
97
								"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
97
								"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
98
								"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
98
								"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
99
								"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
99
								"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
100
								"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
100
								"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
101
						} else {
101
						} else {
102
							$e = "Valeur de paramètre inconnue pour 'categorie'.";
102
							$e = "Valeur de paramètre inconnue pour 'categorie'.";
103
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
103
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
104
						}
104
						}
105
						break;
105
						break;
106
					case 'retour.format'  :
106
					case 'retour.format'  :
107
						if ($valeur == 'min' || $valeur == 'max') {
107
						if ($valeur == 'min' || $valeur == 'max') {
108
							$this->retour_format = $valeur;
108
							$this->retour_format = $valeur;
109
							break;
109
							break;
110
						} else {
110
						} else {
111
							$e = "Valeur de paramètre inconnue pour 'retour.format'.";
111
							$e = "Valeur de paramètre inconnue pour 'retour.format'.";
112
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
112
							throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
113
						}
113
						}
114
					case 'version.projet' :
114
					case 'version.projet' :
115
						$this->traiterVersion($valeur);
115
						$this->traiterVersion($valeur);
116
						break;
116
						break;
117
					default :
117
					default :
118
						$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
118
						$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
119
							.$param.' " n\'existe pas.';
119
							.$param.' " n\'existe pas.';
120
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);	
120
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);	
121
						break;
121
						break;
122
				}
122
				}
123
			}
123
			}
124
		}
124
		}
125
	}
125
	}
126
	
126
	
127
	
127
	
128
 
128
 
129
	public function traiterRessources() {
129
	public function traiterRessources() {
130
			if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
130
			if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
131
				switch ($retour[1]) {
131
				switch ($retour[1]) {
132
					case 'bdtfx' :
132
					case 'bdtfx' :
133
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
133
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
134
						break;
134
						break;
135
					case  'bdafx' :
135
					case  'bdafx' :
136
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
136
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
137
						break;
137
						break;
138
					case  'bdbfx' :
138
					case  'bdbfx' :
139
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
139
						$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
140
						break;
140
						break;
141
					default :
141
					default :
142
						$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
142
						$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
143
							.$retour[1].' " n\'existe pas.';
143
							.$retour[1].' " n\'existe pas.';
144
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
144
						throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
145
						break;
145
						break;
146
				}
146
				}
147
 
147
 
148
			} else {
148
			} else {
149
				$e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.';
149
				$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);
150
				throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
151
				break;
151
				break;
152
			}
152
			}
153
	}
153
	}
154
	
154
	
155
	//+++------------------------------traitement des versions----------------------------------------++
155
	//+++------------------------------traitement des versions----------------------------------------++
156
	
156
	
157
	public function traiterVersion($valeur) {
157
	public function traiterVersion($valeur) {
158
		if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '*' || $valeur == '+') {
158
		if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '*' || $valeur == '+') {
159
			$this->version_projet = $valeur;
159
			$this->version_projet = $valeur;
160
		} else {
160
		} else {
161
			$e = "Erreur : La version est inconnue.";
161
			$e = "Erreur : La version est inconnue.";
162
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
162
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
163
		}
163
		}
164
		
164
		
165
	}
165
	}
166
	
166
	
167
	public function definirTables() {
167
	public function definirTables() {
168
		$table_num_version = $this->recupererVersionDisponible();
168
		$table_num_version = $this->recupererVersionDisponible();
169
		$prefixe_table = config::get('bdd_table');
169
		$prefixe_table = config::get('bdd_table');
170
		if ( in_array($this->version_projet,$table_num_version) ) {
170
		if ( in_array($this->version_projet,$table_num_version) ) {
171
			$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
171
			$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
172
		} elseif ($this->version_projet == '+') {
172
		} elseif ($this->version_projet == '+') {
173
					$derniere_version = $table_num_version[count($table_num_version) - 1];
173
					$derniere_version = $table_num_version[count($table_num_version) - 1];
174
					$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
174
					$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
175
		} elseif ($this->version_projet == '*') {
175
		} elseif ($this->version_projet == '*') {
176
			foreach ($table_num_version as $num_version) {
176
			foreach ($table_num_version as $num_version) {
177
				$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
177
				$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
178
			}
178
			}
179
		} else {
179
		} else {
180
			$e = "Erreur : La version est inconnue.";
180
			$e = "Erreur : La version est inconnue.";
181
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
181
			throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
182
		}
182
		}
183
	}
183
	}
184
	
184
	
185
//+--------------------------formatages de resultats  -------------------------------------------+
185
//+--------------------------formatages de resultats  -------------------------------------------+
186
	
186
	
187
	public function retournerResultatFormate($resultat) {
187
	public function retournerResultatFormate($resultat) {
188
		$resultat_json = $resultat[0];
188
		$resultat_json = $resultat[0];
189
		if ($this->retour_format == 'max'){
189
		if ($this->retour_format == 'max'){
190
			if (!isset($this->parametres['categorie']) ) {
190
			if (!isset($this->parametres['categorie']) ) {
191
				$this->formaterResultatsTousChamps($resultat_json);
191
				$this->formaterResultatsTousChamps($resultat_json);
192
			} elseif ($this->parametres['categorie'] == 'ecologie') {
192
			} elseif ($this->parametres['categorie'] == 'ecologie') {
193
				 $this->formaterResultatsChampsEcologie($resultat_json);
193
				 $this->formaterResultatsChampsEcologie($resultat_json);
194
			} elseif ($this->parametres['categorie'] == 'description') {
194
			} elseif ($this->parametres['categorie'] == 'description') {
195
				 $this->formaterResultatsChampsDescription($resultat_json);
195
				 $this->formaterResultatsChampsDescription($resultat_json);
196
			}
196
			}
197
		}
197
		}
198
		return $this->resultat_json;
198
		return $this->resultat_json;
199
	}
199
	}
200
 
200
 
201
	public function formaterResultatsTousChamps($resultat) {
201
	public function formaterResultatsTousChamps($resultat) {
202
		$this->resultat_json = $resultat;
202
		$this->resultat_json = $resultat;
203
		$this->traiterTypeBio();	
203
		$this->traiterTypeBio();	
204
		$graphique_presence = $this->traiterOntologieEcologie() ;
204
		$graphique_presence = $this->traiterOntologieEcologie() ;
205
		if ($graphique_presence) {
205
		if ($graphique_presence) {
206
			$graphique = $this->ajouterLiensGraphique();
206
			$graphique = $this->ajouterLiensGraphique();
207
					}
207
					}
208
	}
208
	}
209
	
209
	
210
	public function formaterResultatsChampsEcologie($resultat) {
210
	public function formaterResultatsChampsEcologie($resultat) {
211
		$this->resultat_json = $resultat;
211
		$this->resultat_json = $resultat;
212
		$graphique_presence = $this->traiterOntologieEcologie() ;
212
		$graphique_presence = $this->traiterOntologieEcologie() ;
213
		if ($graphique_presence) {
213
		if ($graphique_presence) {
214
			$graphique = $this->ajouterLiensGraphique();
214
			$graphique = $this->ajouterLiensGraphique();
215
		}
215
		}
216
	}
216
	}
217
	
217
	
218
	
218
	
219
	public function formaterResultatsChampsDescription($resultat) {
219
	public function formaterResultatsChampsDescription($resultat) {
220
	$this->resultat_json = $resultat;
220
	$this->resultat_json = $resultat;
221
	$this->traiterTypeBio();
221
	$this->traiterTypeBio();
222
	}
222
	}
223
	
223
	
224
	public function traiterOntologieEcologie() {
224
	public function traiterOntologieEcologie() {
225
		$donnees_presence =  false;
225
		$donnees_presence =  false;
226
		$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
226
		$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
227
		foreach ($this->champs_ontologiques as $cle => $valeur){
227
		foreach ($this->champs_ontologiques as $cle => $valeur){
228
			if ($this->resultat_json[$cle] != ""){
228
			if ($this->resultat_json[$cle] != ""){
229
				$donnees_presence =  true;
229
				$donnees_presence =  true;
230
				$this->recupererOntologies($this->resultat_json[$cle], $cle);
230
				$this->recupererOntologies($this->resultat_json[$cle], $cle);
231
				unset($this->resultat_json[$cle]);
231
				unset($this->resultat_json[$cle]);
232
			}
232
			}
233
		}
233
		}
234
		return $donnees_presence;
234
		return $donnees_presence;
235
	}
235
	}
236
	
236
	
237
	public function traiterTypeBio() {
237
	public function traiterTypeBio() {
238
		if ($this->resultat_json['type_bio'] != ""){
238
		if ($this->resultat_json['type_bio'] != ""){
239
			$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
239
			$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
240
			unset($this->resultat_json['type_bio']);
240
			unset($this->resultat_json['type_bio']);
241
			$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
241
			$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
242
		}
242
		}
243
	}
243
	}
244
 
244
 
245
	public function ajouterLiensGraphique() {
245
	public function ajouterLiensGraphique() {
246
		$this->resultat_json['graphique_climat']['libelle'] = 'climat';
246
		$this->resultat_json['graphique_climat']['libelle'] = 'climat';
247
		$this->resultat_json['graphique_climat']['href'] = 
247
		$this->resultat_json['graphique_climat']['href'] = 
248
			$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
248
			$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
249
		$this->resultat_json['graphique_sol']['libelle'] = 'sol';
249
		$this->resultat_json['graphique_sol']['libelle'] = 'sol';
250
		$this->resultat_json['graphique_sol']['href'] = 
250
		$this->resultat_json['graphique_sol']['href'] = 
251
			$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
251
			$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
252
	}
252
	}
253
	
253
	
254
	
254
	
255
//+--------------------------traitement ontologies -------------------------------------------+
255
//+--------------------------traitement ontologies -------------------------------------------+
256
 
256
 
257
	public function recupererOntologies($valeur, $champs){
257
	public function recupererOntologies($valeur, $champs){
258
		$url = Config::get('url_service_base').Config::get('nom_projet').
258
		$url = Config::get('url_service_base').Config::get('nom_projet').
259
			'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
259
			'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
260
		$val = $this->consulterHref($url);
260
		$val = $this->consulterHref($url);
261
		$this->resultat_json[$champs.'.libelle'] = $val->nom;
261
		$this->resultat_json[$champs.'.libelle'] = $val->nom;
262
		$this->resultat_json[$champs.'.code'] = $valeur;
262
		$this->resultat_json[$champs.'.code'] = $valeur;
263
		$this->resultat_json[$champs.'.href'] = $url;
263
		$this->resultat_json[$champs.'.href'] = $url;
264
	}
264
	}
265
	
265
	
266
	//+-------------ontologie pour le champs type biologique (lire le .txt)---+
266
	//+-------------ontologie pour le champs type biologique (lire le .txt)---+
267
 
267
 
268
	public function recupererOntologiePrTypeBio($type_a_traiter){
268
	public function recupererOntologiePrTypeBio($type_a_traiter){
269
		$resultat_typeBio = "";
269
		$resultat_typeBio = "";
270
		if ($type_a_traiter != "") {
270
		if ($type_a_traiter != "") {
271
			$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
271
			$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
272
			$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
272
			$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
273
			$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
273
			$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
274
		}
274
		}
275
		return $resultat_typeBio;
275
		return $resultat_typeBio;
276
	}
276
	}
277
	
277
	
278
	public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
278
	public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
279
		$types_sstypes = '';
279
		$types_sstypes = '';
280
		foreach ($types_prim_sec as $cle => $tb) {
280
		foreach ($types_prim_sec as $cle => $tb) {
281
			$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
281
			$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
282
		}
282
		}
283
		switch (count($types_sstypes)) {
283
		switch (count($types_sstypes)) {
284
			case 1 : 
284
			case 1 : 
285
				$types_sstypes = $types_sstypes['principal'];
285
				$types_sstypes = $types_sstypes['principal'];
286
				break;
286
				break;
287
			case 2 : 
287
			case 2 : 
288
				$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
288
				$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
289
				break;
289
				break;
290
		}
290
		}
291
		return $types_sstypes;
291
		return $types_sstypes;
292
	}
292
	}
293
	
293
	
294
 
294
 
295
	public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
295
	public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
296
		$resultat_typeBio['type_bio.code'] = $type_a_traiter;
296
		$resultat_typeBio['type_bio.code'] = $type_a_traiter;
297
		foreach ($types_sstypes as $cle => $tb) {
297
		foreach ($types_sstypes as $cle => $tb) {
298
			if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
298
			if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
299
				$i = 0;
299
				$i = 0;
300
				foreach ($tb as $types) {
300
				foreach ($tb as $types) {
301
					$url = Config::get('url_service_base').Config::get('nom_projet').
301
					$url = Config::get('url_service_base').Config::get('nom_projet').
302
						'/ontologies/TB:'.urlencode(urlencode($types));
302
						'/ontologies/TB:'.urlencode(urlencode($types));
303
					$val = $this->consulterHref($url);
303
					$val = $this->consulterHref($url);
304
					$libelle[$cle]= $val->nom;
304
					$libelle[$cle]= $val->nom;
305
					$detail[$cle]['libelle'] = $val->nom;
305
					$detail[$cle][$i]['libelle'] = $val->nom;
306
					$detail[$cle]['code'] = $val->code;
306
					$detail[$cle][$i]['code'] = $val->code;
307
					$detail[$cle]['href'] = $url;
307
					$detail[$cle][$i]['href'] = $url;
-
 
308
					$i++;
308
				}
309
				}
309
			}
310
			}
310
			if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
311
			if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
311
				$i = 0;
312
				$i = 0;
312
				foreach ($tb as $sstypes) {
313
				foreach ($tb as $sstypes) {
313
					$url = Config::get('url_service_base').Config::get('nom_projet').
314
					$url = Config::get('url_service_base').Config::get('nom_projet').
314
								'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
315
								'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
315
					$val = $this->consulterHref($url);
316
					$val = $this->consulterHref($url);
316
					$libelle[$cle]=$val->nom;
317
					$libelle[$cle]=$val->nom;
317
					$detail[$cle][$i]['libelle'] = $val->nom;
318
					$detail[$cle][$i]['libelle'] = $val->nom;
318
					$detail[$cle][$i]['code'] = $val->code;
319
					$detail[$cle][$i]['code'] = $val->code;
319
					$detail[$cle][$i]['href'] = $url;
320
					$detail[$cle][$i]['href'] = $url;
320
					$i++;
321
					$i++;
321
				}
322
				}
322
			}
323
			}
323
		}
324
		}
324
		$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
325
		$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
325
		$resultat_typeBio['type_bio.detail'] = $detail;
326
		$resultat_typeBio['type_bio.detail'] = $detail;
326
		return $resultat_typeBio;
327
		return $resultat_typeBio;
327
	}
328
	}
328
	
329
	
-
 
330
	
329
	
331
	
330
	public function formaterTypeBioPrLibelle($info) {
332
	public function formaterTypeBioPrLibelle($info) {
331
		$libelle = $info['type.principal']." ";
333
		$libelle = $info['type.principal']." ";
332
		$libelle .= isset($info['sous_type.principal']) ? " (".$info['sous_type.principal'].") " : "";
334
		$libelle .= isset($info['sous_type.principal']) ? " (".$info['sous_type.principal'].") " : "";
333
		$libelle .= isset($info['type.secondaire']) ? ", ".$info['type.secondaire']." " : "";
335
		$libelle .= isset($info['type.secondaire']) ? ", ".$info['type.secondaire']." " : "";
334
		$libelle .= isset($info['sous_type.secondaire']) ? "(".$info['sous_type.secondaire'].") " : "";
336
		$libelle .= isset($info['sous_type.secondaire']) ? "(".$info['sous_type.secondaire'].") " : "";
335
		return $libelle;
337
		return $libelle;
336
	}
338
	}
337
 
339
 
338
	//séparation des principaux et des secondaires
340
	//séparation des principaux et des secondaires
339
	public function separerTypesPrimairesSecondaires($type) {
341
	public function separerTypesPrimairesSecondaires($type) {
340
		$types = array();	
342
		$types = array();	
341
		if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
343
		if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
342
			$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
344
			$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
343
			$types['secondaire'] = $retour[2];
345
			$types['secondaire'] = $retour[2];
344
		} else {
346
		} else {
345
			$types['principal'] = $type;
347
			$types['principal'] = $type;
346
		}
348
		}
347
		return $types;
349
		return $types;
348
	}
350
	}
349
 
351
 
350
	
352
	
351
	public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
353
	public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
352
		$types = array();
354
		$types = array();
353
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
355
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
354
			//type
356
			//type
355
			$type = array();
357
			$type = array();
356
			$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
358
			$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
357
			if (preg_match("/,/", $type[0])) {
-
 
358
				$type = preg_split("/,/", $type[0]);
359
			$type = explode(",", $type[0]);
359
			}
-
 
360
			for ($i = 0 ; $i < count($type); $i++) {
360
			for ($i = 0 ; $i < count($type); $i++) {
361
				$types['type.'.$typePrimOuSec][$i] = $type[$i];
361
				$types['type.'.$typePrimOuSec][$i] = $type[$i];
362
			}
362
			}
363
			//sous types
363
			//sous types
364
			$ss_types = array();
364
			$ss_types = array();
365
			if (isset($retour[2]) && $retour[2] != '') {
365
			if (isset($retour[2]) && $retour[2] != '') {
366
 				$ss_types[0] =  $retour[2] ;
366
 				$ss_types[0] =  $retour[2] ;
367
 				if (preg_match("/\-/", $ss_types[0])) {
-
 
368
 					$ss_types = preg_split("/\-/", $ss_types[0]);
367
 				$ss_types = explode("-", $ss_types[0]);
369
 				}
-
 
370
				for ($i = 0 ; $i < count($ss_types); $i++) {
368
				for ($i = 0 ; $i < count($ss_types); $i++) {
371
					$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
369
					$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
372
				}
370
				}
373
			}
371
			}
374
    	}
372
    	}
375
 		return $types;
373
 		return $types;
376
 	}
374
 	}
377
 	
375
 	
378
 
376
 
379
 	
377
 	
380
 	
378
 	
381
	
379
	
382
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
380
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
383
	
381
	
384
	public function assemblerLaRequete() {
382
	public function assemblerLaRequete() {
385
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
383
		$requete = 	' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
386
		.$this->retournerRequeteCondition();
384
		.$this->retournerRequeteCondition();
387
		return $requete;
385
		return $requete;
388
	}
386
	}
389
	
387
	
390
	
388
	
391
	
389
	
392
	public  function retournerRequeteCondition() {
390
	public  function retournerRequeteCondition() {
393
		$condition = '';
391
		$condition = '';
394
		if (empty($this->requete_condition) == false) {
392
		if (empty($this->requete_condition) == false) {
395
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
393
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
396
		}
394
		}
397
		return $condition;
395
		return $condition;
398
	}
396
	}
399
 
397
 
400
 
398
 
401
	
399
	
402
}
400
}
403
?>
401
?>