Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 731 Rev 734
1
<?php
1
<?php
2
/**
2
/**
3
* Description :
3
* Description :
4
* Classe NomsVernaculaires.php fournit une liste de noms vernaculaires et leur liaison à la bdtfx
4
* Classe NomsVernaculaires.php fournit une liste de noms vernaculaires et leur liaison à la bdtfx
5
* Le but étant de fournir un ensemble minimal d'information comprenant :
5
* Le but étant de fournir un ensemble minimal d'information comprenant :
6
* un identifiant (numérique ou alphanumérique sous forme de ChatMot si possible), un nom, une langue et
6
* un identifiant (numérique ou alphanumérique sous forme de ChatMot si possible), un nom, une langue et
7
* une relation avec un taxon de la bdtfx.
7
* une relation avec un taxon de la bdtfx.
8
* Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
8
* Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
9
* L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
9
* L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
10
*
10
*
11
* Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
11
* Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
12
* distinct, retour.format, navigation.depart et navigation.limite.
12
* distinct, retour.format, navigation.depart et navigation.limite.
13
*
13
*
14
* Encodage en entrée : utf8
14
* Encodage en entrée : utf8
15
* Encodage en sortie : utf8
15
* Encodage en sortie : utf8
16
* @package framework-v3
16
* @package framework-v3
17
* @author Delphine Cauquil <delphine@tela-botanica.org>
17
* @author Delphine Cauquil <delphine@tela-botanica.org>
18
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
18
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
19
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
* @version 1.0
21
* @version 1.0
22
* @copyright 1999-${year} Tela Botanica (accueil@tela-botanica.org)
22
* @copyright 1999-${year} Tela Botanica (accueil@tela-botanica.org)
23
*/
23
*/
-
 
24
 
-
 
25
// Un caractère de concaténation entre le projet et le service.
-
 
26
// Ce caractère ne doit pas faire partie d'aucun des noms de service ou projet
-
 
27
define('RES_VAL_SEP', '@');
-
 
28
 
24
class NomsVernaculaires extends Commun {
29
class NomsVernaculaires extends Commun {
25
	protected $champ_infos = array(
30
	protected $champ_infos = array(
26
		'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtfx', 'nom' => 'nom_sci',
31
		'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtfx', 'nom' => 'nom_sci',
27
						 // utilisés par ajouterChampsOntologieLigneResultat()
32
						 // utilisés par ajouterChampsOntologieLigneResultat()
28
						 'intitule' => 'taxon.code', // intitulé du champ tel qu'il sera renvoyé en JSON
33
						 'intitule' => 'taxon.code', // intitulé du champ tel qu'il sera renvoyé en JSON
29
						 'bdd_champ' => 'num_taxon'), // intitulé du champ tel qu'il est présent dans l'enregistrement MySQL
34
						 'bdd_champ' => 'num_taxon'), // intitulé du champ tel qu'il est présent dans l'enregistrement MySQL
30
		'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom',
35
		'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom',
31
								  'intitule' => 'conseil_emploi', 'bdd_champ' => 'num_statut'),
36
								  'intitule' => 'conseil_emploi', 'bdd_champ' => 'num_statut'),
32
		'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom',
37
		'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom',
33
						 'intitule' => 'genre', 'bdd_champ' => 'num_genre'));
38
						 'intitule' => 'genre', 'bdd_champ' => 'num_genre'));
34
 
39
 
35
	protected $service = 'noms-vernaculaires';
40
	protected $service = 'noms-vernaculaires';
36
 
41
 
37
	/**
42
	/**
38
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
43
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
39
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
44
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
40
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
45
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
41
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
46
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
42
	protected $format_reponse = 'noms-vernaculaires';
47
	protected $format_reponse = 'noms-vernaculaires';
43
 
48
 
44
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
49
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
45
	 * selon ressources et paramètres */
50
	 * selon ressources et paramètres */
46
	protected $requete_champ = array(' * ');
51
	protected $requete_champ = array(' * ');
47
	protected $requete_condition = '';
52
	protected $requete_condition = '';
48
	protected $limite_requete = array(
53
	protected $limite_requete = array(
49
		'depart' => 0,
54
		'depart' => 0,
50
		'limite' => 100
55
		'limite' => 100
51
	);
56
	);
52
	
57
	
53
	protected $champ_tri = 'code_langue';
58
	protected $champ_tri = 'code_langue';
54
	protected $direction_tri = 'asc';
59
	protected $direction_tri = 'asc';
55
	
60
	
56
	/**
61
	/**
57
	 * Indique les champs supplémentaires à retourner
62
	 * Indique les champs supplémentaires à retourner
58
	 *  - conseil_emploi = conseil d'emploi du nom vernaculaire
63
	 *  - conseil_emploi = conseil d'emploi du nom vernaculaire
59
	 *  - genre = genre et nombre du nom
64
	 *  - genre = genre et nombre du nom
60
	 *  - taxon = nom retenu associé à ce nom
65
	 *  - taxon = nom retenu associé à ce nom
61
	 */
66
	 */
62
	protected $champs_supp = array();
67
	protected $champs_supp = array();
63
 
68
 
64
	/**
69
	/**
65
	 * Precise la contenance plus ou moins précise du tableau à retourner :
70
	 * Precise la contenance plus ou moins précise du tableau à retourner :
66
	 *  - min = les données présentes dans la table
71
	 *  - min = les données présentes dans la table
67
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
72
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
68
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
73
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
69
	protected $retour_format = 'max';
74
	protected $retour_format = 'max';
70
	/** Valeur du paramètre de requete recherche :
75
	/** Valeur du paramètre de requete recherche :
71
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
76
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
72
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
77
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
73
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
78
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
74
	protected $recherche;
79
	protected $recherche;
75
	
80
	
76
	/** Permet de stocker le tableau de résultat (non encodé en json) */
81
	/** Permet de stocker le tableau de résultat (non encodé en json) */
77
	protected $table_retour = array();
82
	protected $table_retour = array();
78
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
83
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
79
	protected $total_resultat;
84
	protected $total_resultat;
80
	
85
	
81
	private $config;
86
	private $config;
82
	
87
	
83
	public function __construct($config) {
88
	public function __construct($config) {
84
		$this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
89
		$this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
85
	}
90
	}
86
 
91
 
87
	//+------------------------------------------------------------------------------------------------------+
92
	//+------------------------------------------------------------------------------------------------------+
88
	// créer une condition en fonction du paramétre
93
	// créer une condition en fonction du paramétre
89
	public function traiterParametres() {
94
	public function traiterParametres() {
90
		if (isset($this->parametres) && !empty($this->parametres)) {
95
		if (isset($this->parametres) && !empty($this->parametres)) {
91
 
96
 
92
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
97
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
93
				$this->recherche = $this->parametres['recherche'];
98
				$this->recherche = $this->parametres['recherche'];
94
			}
99
			}
95
			foreach ($this->parametres as $param => $valeur) {
100
			foreach ($this->parametres as $param => $valeur) {
96
				switch ($param) {
101
				switch ($param) {
97
					case 'masque' :
102
					case 'masque' :
98
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
103
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
99
						break;
104
						break;
100
					case 'masque.nt' :
105
					case 'masque.nt' :
101
						$this->ajouterFiltreMasque('num_taxon', $valeur);
106
						$this->ajouterFiltreMasque('num_taxon', $valeur);
102
						break;
107
						break;
103
					case 'masque.nv' :
108
					case 'masque.nv' :
104
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
109
						$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
105
						break;
110
						break;
106
					case 'masque.lg' :
111
					case 'masque.lg' :
107
						$this->ajouterFiltreMasque('code_langue', $valeur);
112
						$this->ajouterFiltreMasque('code_langue', $valeur);
108
						break;
113
						break;
109
					case 'masque.cce' :
114
					case 'masque.cce' :
110
						$this->ajouterFiltreMasque('num_statut', $valeur);
115
						$this->ajouterFiltreMasque('num_statut', $valeur);
111
						break;
116
						break;
112
					case 'retour.format' :
117
					case 'retour.format' :
113
						$this->retour_format = $valeur;
118
						$this->retour_format = $valeur;
114
						break;
119
						break;
115
					case 'navigation.depart' :
120
					case 'navigation.depart' :
116
						$this->limite_requete['depart'] = $valeur;
121
						$this->limite_requete['depart'] = $valeur;
117
						break;
122
						break;
118
					case 'navigation.limite' :
123
					case 'navigation.limite' :
119
						$this->limite_requete['limite'] = $valeur;
124
						$this->limite_requete['limite'] = $valeur;
120
						break;
125
						break;
121
					case 'retour.champs' :
126
					case 'retour.champs' :
122
						$this->champs_supp = explode(',',$valeur);
127
						$this->champs_supp = explode(',',$valeur);
123
					break;
128
					break;
124
					case 'recherche' :
129
					case 'recherche' :
125
						break;
130
						break;
126
					case 'version.projet' :
131
					case 'version.projet' :
127
						break;
132
						break;
128
					default :
133
					default :
129
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
134
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
130
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
135
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
131
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
136
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
132
				}
137
				}
133
			}
138
			}
134
		}
139
		}
135
	}
140
	}
136
 
141
 
137
	public function ajouterFiltreMasque($nom_champ, $valeur) {
142
	public function ajouterFiltreMasque($nom_champ, $valeur) {
138
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
143
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
139
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
144
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
140
		} else {
145
		} else {
141
			if ($this->recherche == 'floue') {
146
			if ($this->recherche == 'floue') {
142
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
147
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
143
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
148
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
144
			} else {
149
			} else {
145
				if ($this->recherche == 'etendue') {
150
				if ($this->recherche == 'etendue') {
146
					$valeur = '%'.str_replace(' ','% ', $valeur);
151
					$valeur = '%'.str_replace(' ','% ', $valeur);
147
					$valeur .= '%';
152
					$valeur .= '%';
148
				}
153
				}
149
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
154
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
150
			}
155
			}
151
		}
156
		}
152
	}
157
	}
153
 
158
 
154
	//+------------------------------------------------------------------------------------------------------+
159
	//+------------------------------------------------------------------------------------------------------+
155
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
160
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
156
	public function traiterRessources() {
161
	public function traiterRessources() {
157
		if (isset($this->ressources) && !empty($this->ressources)) {
162
		if (isset($this->ressources) && !empty($this->ressources)) {
158
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
163
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
159
				$this->traiterRessourceId(); // ajoute condition id=#valeur
164
				$this->traiterRessourceId(); // ajoute condition id=#valeur
160
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
165
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
161
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
166
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
162
				}
167
				}
163
			}
168
			}
164
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
169
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
165
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
170
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
166
		}
171
		}
167
	}
172
	}
168
 
173
 
169
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
174
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
170
	public function traiterRessourceId() {
175
	public function traiterRessourceId() {
171
		if (is_numeric($this->ressources[0])) {
176
		if (is_numeric($this->ressources[0])) {
172
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
177
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
173
			$this->format_reponse .= '/id';
178
			$this->format_reponse .= '/id';
174
		} elseif ($this->ressources[0] == 'attributions') {
179
		} elseif ($this->ressources[0] == 'attributions') {
175
			$this->format_reponse .= '/attributions';
180
			$this->format_reponse .= '/attributions';
176
		} else {
181
		} else {
177
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
182
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
178
				' " n\'existe pas.';
183
				' " n\'existe pas.';
179
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
184
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
180
		}
185
		}
181
	}
186
	}
182
 
187
 
183
 
188
 
184
	public function traiterRessourceChamp() {
189
	public function traiterRessourceChamp() {
185
		$this->format_reponse .= '/champ';
190
		$this->format_reponse .= '/champ';
186
		$this->analyserChamp();
191
		$this->analyserChamp();
187
	}
192
	}
188
 
193
 
189
	public function analyserChamp() {
194
	public function analyserChamp() {
190
		$this->requete_champ = array();
195
		$this->requete_champ = array();
191
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
196
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
192
		$champs = explode(' ', $this->ressources[1]);
197
		$champs = explode(' ', $this->ressources[1]);
193
		foreach ($champs as $champ) {
198
		foreach ($champs as $champ) {
194
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
199
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
195
			if (isset($this->champs_possibles[$match[1]])) {
200
			if (isset($this->champs_possibles[$match[1]])) {
196
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
201
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
197
			} elseif (isset($this->champs_possibles[$match[0]])) {
202
			} elseif (isset($this->champs_possibles[$match[0]])) {
198
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
203
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
199
			} else {
204
			} else {
200
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
205
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
201
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
206
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
202
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
207
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
203
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
208
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
204
			}
209
			}
205
		}
210
		}
206
	}
211
	}
207
 
212
 
208
	//+------------------------------------------------------------------------------------------------------+
213
	//+------------------------------------------------------------------------------------------------------+
209
	public function assemblerLaRequete() {
214
	public function assemblerLaRequete() {
210
		$requete = ' SELECT '.$this->formerRequeteChamp().
215
		$requete = ' SELECT '.$this->formerRequeteChamp().
211
					', CASE num_statut WHEN "" THEN 1 ELSE 0 END AS is_null '.
216
					', CASE num_statut WHEN "" THEN 1 ELSE 0 END AS is_null '.
212
					' FROM '.$this->table
217
					' FROM '.$this->table
213
					.$this->formerRequeteCondition().
218
					.$this->formerRequeteCondition().
214
					' ORDER BY is_null ASC, num_statut ASC '
219
					' ORDER BY is_null ASC, num_statut ASC '
215
					.$this->formerRequeteLimite();
220
					.$this->formerRequeteLimite();
216
		return $requete;
221
		return $requete;
217
	}
222
	}
218
 
223
 
219
	public  function formerRequeteChamp() {
224
	public  function formerRequeteChamp() {
220
		if (in_array('*', $this->requete_champ)) {
225
		if (in_array('*', $this->requete_champ)) {
221
			$champ = ' * ';
226
			$champ = ' * ';
222
		} else {
227
		} else {
223
			$champ = implode(', ', $this->requete_champ);
228
			$champ = implode(', ', $this->requete_champ);
224
		}
229
		}
225
		return $champ;
230
		return $champ;
226
	}
231
	}
227
 
232
 
228
	public  function formerRequeteCondition() {
233
	public  function formerRequeteCondition() {
229
		$condition = '';
234
		$condition = '';
230
		if ($this->requete_condition != null) {
235
		if ($this->requete_condition != null) {
231
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
236
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
232
		}
237
		}
233
		return $condition;
238
		return $condition;
234
	}
239
	}
235
 
240
 
236
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
241
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
237
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
242
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
238
	public function formerRequeteLimite() {
243
	public function formerRequeteLimite() {
239
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
244
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
240
			$this->requete_limite = '';
245
			$this->requete_limite = '';
241
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
246
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
242
			$this->limite_requete['depart'] =
247
			$this->limite_requete['depart'] =
243
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
248
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
244
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
249
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
245
		} else {
250
		} else {
246
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
251
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
247
		}
252
		}
248
		return $this->requete_limite;
253
		return $this->requete_limite;
249
	}
254
	}
250
 
255
 
251
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
256
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
252
	public function recupererTotalResultat() {
257
	public function recupererTotalResultat() {
253
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
258
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
254
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
259
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
255
			.$this->table
260
			.$this->table
256
			.$this->formerRequeteCondition();
261
			.$this->formerRequeteCondition();
257
		$res = $this->getBdd()->recuperer($requete);
262
		$res = $this->getBdd()->recuperer($requete);
258
 
263
 
259
		if ($res) {
264
		if ($res) {
260
			$total = $res['nombre'];
265
			$total = $res['nombre'];
261
		} else {
266
		} else {
262
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
267
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
263
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
268
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
264
		}
269
		}
265
		return $total;
270
		return $total;
266
	}
271
	}
267
 
272
 
268
	//+------------------------------------------------------------------------------------------------------+
273
	//+------------------------------------------------------------------------------------------------------+
269
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
274
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
270
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
275
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
271
	public function retournerResultatFormate($resultat) {
276
	public function retournerResultatFormate($resultat) {
272
		$this->recupererTableConfig('correspondance_champs');
277
		$this->recupererTableConfig('correspondance_champs');
273
		switch ($this->format_reponse) {
278
		switch ($this->format_reponse) {
274
			case 'noms-vernaculaires'				: 
279
			case 'noms-vernaculaires'				: 
275
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
280
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
276
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
281
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
277
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
282
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
278
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
283
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
279
			default									:																	break;
284
			default									:																	break;
280
		}
285
		}
281
		return $reponse;
286
		return $reponse;
282
	}
287
	}
283
	
288
	
284
	public function ajouterJsonEnTeteNV() {
289
	public function ajouterJsonEnTeteNV() {
285
		$table_retour_json['masque'] = $this->recupererMasque();
290
		$table_retour_json['masque'] = $this->recupererMasque();
286
		$table_retour_json['depart'] = $this->limite_requete['depart'];
291
		$table_retour_json['depart'] = $this->limite_requete['depart'];
287
		$table_retour_json['limite'] = $this->limite_requete['limite'];
292
		$table_retour_json['limite'] = $this->limite_requete['limite'];
288
		$table_retour_json['total']  = $this->total_resultat;
293
		$table_retour_json['total']  = $this->total_resultat;
289
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
294
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
290
		if (isset($url['precedent']) && $url['precedent'] != '') {
295
		if (isset($url['precedent']) && $url['precedent'] != '') {
291
			$table_retour_json['href.precedent'] = $url['precedent'];
296
			$table_retour_json['href.precedent'] = $url['precedent'];
292
		}
297
		}
293
		if (isset($url['suivant']) && $url['suivant']   != '') {
298
		if (isset($url['suivant']) && $url['suivant']   != '') {
294
			$table_retour_json['href.suivant']   = $url['suivant'];
299
			$table_retour_json['href.suivant']   = $url['suivant'];
295
		}
300
		}
296
		return $table_retour_json;
301
		return $table_retour_json;
297
	}
302
	}
298
	
303
	
299
	public function ajouterJsonResultatNV($resultat) {
304
	public function ajouterJsonResultatNV($resultat) {
300
		foreach ($resultat as $tab) {
305
		foreach ($resultat as $tab) {
301
			foreach ($tab as $key => $valeur) {
306
			foreach ($tab as $key => $valeur) {
302
				if ($valeur != '') {
307
				if ($valeur != '') {
303
					switch ($key) {
308
					switch ($key) {
304
						case 'id'				: $num = $valeur;								break;
309
						case 'id'				: $num = $valeur;								break;
305
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
310
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
306
						default					:												break;
311
						default					:												break;
307
					}
312
					}
308
				}
313
				}
309
			}
314
			}
310
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
315
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
311
			$resultat_json[$num] = $this->table_retour;
316
			$resultat_json[$num] = $this->table_retour;
312
			$this->table_retour = array();
317
			$this->table_retour = array();
313
		}
318
		}
314
		return  $resultat_json;
319
		return  $resultat_json;
315
	}
320
	}
316
 
321
 
317
	
322
	
318
	public function formaterNomsVernaculaires($resultat) {
323
	public function formaterNomsVernaculaires($resultat) {
319
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
324
		$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
320
		$resultat = $this->hierarchiserResultat($resultat);
325
		$resultat = $this->hierarchiserResultat($resultat);
321
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
326
		$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
322
		return $table_retour_json;
327
		return $table_retour_json;
323
	}
328
	}
324
	
329
	
325
	public function hierarchiserResultat($resultat) {
330
	public function hierarchiserResultat($resultat) {
326
		//tri recherche floue
331
		//tri recherche floue
327
		if (isset($this->parametres['masque.nv'])) {
332
		if (isset($this->parametres['masque.nv'])) {
328
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
333
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
329
		}
334
		}
330
		if (isset($this->parametres['masque'])) {
335
		if (isset($this->parametres['masque'])) {
331
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
336
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
332
		}
337
		}
333
		return $resultat;
338
		return $resultat;
334
	}
339
	}
335
	
340
	
336
	public function recupererMasque() {
341
	public function recupererMasque() {
337
		$tab_masque = array();
342
		$tab_masque = array();
338
		foreach ($this->parametres as $param=>$valeur) {
343
		foreach ($this->parametres as $param=>$valeur) {
339
			if (strstr($param, 'masque') != false) {
344
			if (strstr($param, 'masque') != false) {
340
				$tab_masque[] = $param.'='.$valeur;
345
				$tab_masque[] = $param.'='.$valeur;
341
			}
346
			}
342
		}
347
		}
343
		$masque = implode('&', $tab_masque);
348
		$masque = implode('&', $tab_masque);
344
		return $masque;
349
		return $masque;
345
	}
350
	}
346
	
351
	
347
	public function formaterEnOss($resultat) {
352
	public function formaterEnOss($resultat) {
348
		$table_nom = array();
353
		$table_nom = array();
349
		$oss = '';
354
		$oss = '';
350
		foreach ($resultat as $tab) {
355
		foreach ($resultat as $tab) {
351
			if (isset($tab['nom_vernaculaire']) ) {
356
			if (isset($tab['nom_vernaculaire']) ) {
352
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
357
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
353
					$table_nom[] = $tab['nom_vernaculaire'];
358
					$table_nom[] = $tab['nom_vernaculaire'];
354
					$oss [] = $tab['nom_vernaculaire'];
359
					$oss [] = $tab['nom_vernaculaire'];
355
				}
360
				}
356
			}
361
			}
357
		}
362
		}
358
		if (isset($this->masque)) $masque = implode('&', $this->masque);
363
		if (isset($this->masque)) $masque = implode('&', $this->masque);
359
		else $masque = 'Pas de masque';
364
		else $masque = 'Pas de masque';
360
		$table_retour_oss = array($masque, $oss);
365
		$table_retour_oss = array($masque, $oss);
361
		return $table_retour_oss;
366
		return $table_retour_oss;
362
	}
367
	}
363
	
368
	
364
	public function formaterNomsVernaculairesAttributions($resultat) {
369
	public function formaterNomsVernaculairesAttributions($resultat) {
365
		//on remplie la table $table_retour_json['entete']
370
		//on remplie la table $table_retour_json['entete']
366
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
371
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
367
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
372
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
368
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
373
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
369
		$table_retour_json['entete']['total']  = $this->total_resultat;
374
		$table_retour_json['entete']['total']  = $this->total_resultat;
370
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
375
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
371
		if (!empty($url['precedent'])) {
376
		if (!empty($url['precedent'])) {
372
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
377
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
373
		}
378
		}
374
		if (!empty($url['suivant'])) {
379
		if (!empty($url['suivant'])) {
375
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
380
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
376
		}
381
		}
377
		foreach ($resultat as &$tab) {			
382
		foreach ($resultat as &$tab) {			
378
			$nnv = $tab['num_nom_vernaculaire'];
383
			$nnv = $tab['num_nom_vernaculaire'];
379
			$resultat_json[$nnv]['id'] = $tab['id'];
384
			$resultat_json[$nnv]['id'] = $tab['id'];
380
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
385
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
381
			$resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
386
			$resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
382
			$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
387
			$resultat_json[$nnv]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
383
			if ($this->retour_format == 'max') {
388
			if ($this->retour_format == 'max') {
384
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
389
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
385
				if($this->champs_supp) {
390
				if($this->champs_supp) {
386
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
391
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
387
					// simple initialisation par copie de la référence de l'original
392
					// simple initialisation par copie de la référence de l'original
388
					$resultat_json[$nnv] = &$tab;
393
					$resultat_json[$nnv] = &$tab;
389
				}
394
				}
390
				else {
395
				else {
391
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
396
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
392
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
397
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
393
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
398
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
394
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
399
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
395
				}
400
				}
396
			}
401
			}
397
		}
402
		}
398
 
403
 
399
		// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
404
		// dans ce cas (particulier?) nous n'avons pour l'heure initialisé qu'une référence
400
		// vers le tableau de valeurs original
405
		// vers le tableau de valeurs original
401
		if ($this->retour_format == 'max' && $this->champs_supp) {
406
		if ($this->retour_format == 'max' && $this->champs_supp) {
402
			// récupérons désormais les ontologies
407
			// récupérons désormais les ontologies
403
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
408
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
404
		}
409
		}
405
 
410
 
406
		if ($this->retour_format == 'max') {
411
		if ($this->retour_format == 'max') {
407
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une 
412
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une 
408
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
413
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
409
			$noms_sci = $this->recupererNomTaxons();
414
			$noms_sci = $this->recupererNomTaxons();
410
			foreach ($resultat_json as $num_nom => &$tab) {
415
			foreach ($resultat_json as $num_nom => &$tab) {
411
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
416
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
412
				if($tab == null) {
417
				if($tab == null) {
413
					unset($resultat_json[$num_nom]);
418
					unset($resultat_json[$num_nom]);
414
				}
419
				}
415
			}
420
			}
416
		}
421
		}
417
		
422
		
418
		$table_retour_json['resultat'] = $resultat_json;
423
		$table_retour_json['resultat'] = $resultat_json;
419
		return $table_retour_json;
424
		return $table_retour_json;
420
	}
425
	}
421
	
426
	
422
	/**
427
	/**
423
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
428
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
424
	 * en faisant appels aux web services associés
429
	 * en faisant appels aux web services associés
425
	 * @param array in/out $resultats: tous les résultats
430
	 * @param array in/out $resultats: tous les résultats
426
	 */
431
	 */
427
	public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
432
	public function ajouterChampsOntologieLigneTousResultats(&$resultats) {
428
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
433
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
429
			if(!in_array($cle, $this->champs_supp)) continue;
434
			if(!in_array($cle, $this->champs_supp)) continue;
430
 
435
 
431
			// TODO: n'activer QUE lorsque le webservice ontologie Nvjfl supportera le multi-critère
436
			// TODO: n'activer QUE lorsque le webservice ontologie Nvjfl supportera le multi-critère
432
			// cf: services/modules/0.1/commun/Ontologies.php
437
			// cf: services/modules/0.1/commun/Ontologies.php
433
			if(FALSE && $cle == 'conseil_emploi') {
438
			if($cle == 'conseil_emploi') {
434
				// la factorisation des toutes les valeurs recherchées (pour tous les
439
				// la factorisation des toutes les valeurs recherchées (pour tous les
435
				// résultats, peut [potentiellement] être effectuée ci-dessous)
440
				// résultats, peut [potentiellement] être effectuée ci-dessous)
436
				$ontologieParamPending = static::NvjflOntologieIndex($resultats, $champs_supplementaires);
441
				$ontologieParamPending = static::NvjflOntologieIndex($resultats, $champs_supplementaires);
437
				$this->NvjflOntologieExpand($ontologieParamPending);
442
				$this->NvjflOntologieExpand($ontologieParamPending);
438
				self::NvjflOntologieCombine($resultats, $champs_supplementaires);
443
				self::NvjflOntologieCombine($resultats, $champs_supplementaires);
439
				continue;
444
				continue;
440
			}
445
			}
441
 
446
 
442
			// extrait, depuis un élément de $champ_infos:
447
			// extrait, depuis un élément de $champ_infos:
443
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
448
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
444
			extract($champs_supplementaires);
449
			extract($champs_supplementaires);
445
 
450
 
446
			foreach ($resultats as &$tab) {
451
			foreach ($resultats as &$tab) {
447
				$valeur_recherche = $tab[$bdd_champ];
452
				$valeur_recherche = $tab[$bdd_champ];
448
				if(!trim($valeur_recherche)) continue;
453
				if(!trim($valeur_recherche)) continue;
449
 
454
 
450
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
455
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
451
				$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
456
				$tab[$intitule] = $this->chercherSignificationCode($url, $nom);
452
			}
457
			}
453
		}
458
		}
454
	}
459
	}
455
 
460
 
456
	/* Récupère les valeurs recherchées pour une liste de résultats, (plus ou moins)
461
	/* Récupère les valeurs recherchées pour une liste de résultats, (plus ou moins)
457
	   spécifiquement au service d'Ontologies de NVJFL.
462
	   spécifiquement au service d'Ontologies de NVJFL.
458
	   Aggrège les valeurs dans le tableau retourné.
463
	   Aggrège les valeurs dans le tableau retourné.
459
	   Une référence vers l'index du tableau (NULL pour l'instant) est laissée dans
464
	   Une référence vers l'index du tableau (NULL pour l'instant) est laissée dans
460
	   un élément du résultat. */
465
	   un élément du résultat. */
461
	static function NvjflOntologieIndex(&$resultats, $champs_infos) {
466
	static function NvjflOntologieIndex(&$resultats, $champs_infos) {
462
		$ontologieParamPending = Array();
467
		$ontologieParamPending = Array();
463
		extract($champs_infos);
468
		extract($champs_infos);
464
		foreach($resultats as &$resultat) {
469
		foreach($resultats as &$resultat) {
465
			$valeur_recherche = $resultat[$bdd_champ];
470
			$valeur_recherche = $resultat[$bdd_champ];
466
			if(!trim($valeur_recherche)) continue;
471
			if(!trim($valeur_recherche)) continue;
467
			$ontologieParamPending[$ressource . $valeur_recherche] = NULL;
472
			$ontologieParamPending[$ressource . $valeur_recherche] = NULL;
468
			// placeholder pour le résultat
473
			// placeholder pour le résultat
469
			$resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl'] =
474
			$resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl'] =
470
				&$ontologieParamPending[$ressource . $valeur_recherche];
475
				&$ontologieParamPending[$ressource . $valeur_recherche];
471
		}
476
		}
472
		return $ontologieParamPending;
477
		return $ontologieParamPending;
473
	}
478
	}
474
 
479
 
475
	// TODO: switch to static si il peut en être de même pour ajouterHrefAutreProjet()
480
	// TODO: switch to static si il peut en être de même pour ajouterHrefAutreProjet()
476
	/* À partir d'un aggrégat des critère de requêtes d'ontologies, spécifiques à NVJFL,
481
	/* À partir d'un aggrégat des critère de requêtes d'ontologies, spécifiques à NVJFL,
477
	   créé une URL multi-critère.
482
	   créé une URL multi-critère.
478
	   Celle-ci, dans ce cas précis, n'est que la concaténation, par des virgules,
483
	   Celle-ci, dans ce cas précis, n'est que la concaténation, par des virgules,
479
	   des couples <ressource - valeur recherchée>.
484
	   des couples <ressource - valeur recherchée>.
480
	   L'URL est appelée et la valeur correspondante, dans $criteres_requete, remplacée.
485
	   L'URL est appelée et la valeur correspondante, dans $criteres_requete, remplacée.
481
 
486
 
482
	   Note: dans le cadre du tryptique index/expand/combine pour lequel cette fonction existe,
487
	   Note: dans le cadre du tryptique index/expand/combine pour lequel cette fonction existe,
483
	   la valeur est référencée par une élément d'une ou plusieurs lignes de $resultat correspondantes.
488
	   la valeur est référencée par une élément d'une ou plusieurs lignes de $resultat correspondantes.
484
	   Celle(s)-ci sera[ont] donc changée(s) dans la foulée. */
489
	   Celle(s)-ci sera[ont] donc changée(s) dans la foulée. */
485
	public function NvjflOntologieExpand(&$criteres_requete) {
490
	public function NvjflOntologieExpand(&$criteres_requete) {
486
		// équivalent spécifique de ajouterHrefAutreProjet()
491
		// équivalent spécifique de ajouterHrefAutreProjet()
487
		$valeurs_requises = implode(',', array_keys($criteres_requete));
492
		$valeurs_requises = implode(',', array_keys($criteres_requete));
488
		$url = Config::get('url_service_base').'nvjfl/ontologies/'.$valeurs_requises;
493
		$url = Config::get('url_service_base').'nvjfl/ontologies/'.$valeurs_requises;
489
		$val = $this->consulterHref($url);
494
		$val = $this->consulterHref($url);
490
		// modifie par conséquent $resultats[X]['_result_ontologies' . RES_VAL_SEP . 'nvjfl']
495
		// modifie par conséquent $resultats[X]['_result_ontologies' . RES_VAL_SEP . 'nvjfl']
491
		// dont la référence pointe toujours sur $v
496
		// dont la référence pointe toujours sur $v
492
		foreach($val as $k => $v) $criteres_requete[$k] = $val->$k;
497
		foreach($val as $k => $v) $criteres_requete[$k] = $val->$k;
493
	}
498
	}
494
 
499
 
495
	/* Fonction finale du tryptique: réordonne les valeurs obtenues auprès du web-service
500
	/* Fonction finale du tryptique: réordonne les valeurs obtenues auprès du web-service
496
	   NVJFL en adéquation avec les champs attendus en sortie. Pour ce faire, $champs_infos
501
	   NVJFL en adéquation avec les champs attendus en sortie. Pour ce faire, $champs_infos
497
	   est nécessaire. D'autre part, l'index spécifique '_result_ontologies' . RES_VAL_SEP . 'nvjfl'
502
	   est nécessaire. D'autre part, l'index spécifique '_result_ontologies' . RES_VAL_SEP . 'nvjfl'
498
	   est supprimé après avoir été correctement copié. */
503
	   est supprimé après avoir été correctement copié. */
499
	static function NvjflOntologieCombine(&$resultats, $champs_infos) {
504
	static function NvjflOntologieCombine(&$resultats, $champs_infos) {
500
		extract($champs_infos);
505
		extract($champs_infos);
501
		foreach($resultats as &$resultat) {
506
		foreach($resultats as &$resultat) {
502
			if(!isset($resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl'])) continue;
507
			if(!isset($resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl'])) continue;
503
			// equivalent de chercher signification
508
			// equivalent de chercher signification
504
			$resultat[$intitule] = $resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl']->$nom;
509
			$resultat[$intitule] = $resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl']->$nom;
505
			unset($resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl']);
510
			unset($resultat['_result_ontologies' . RES_VAL_SEP . 'nvjfl']);
506
		}
511
		}
507
	}
512
	}
508
 
513
 
509
	/**
514
	/**
510
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
515
	 * Ajoute les champs d'ontologie supplémentaires si necéssaire
511
	 * en faisant appels aux web services associés
516
	 * en faisant appels aux web services associés
512
	 * @param array $ligne_resultat
517
	 * @param array $ligne_resultat
513
	 * 
518
	 * 
514
	 * @return array la ligne modifiée
519
	 * @return array la ligne modifiée
515
	 */
520
	 */
516
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
521
	public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
517
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
522
		foreach($this->champ_infos as $cle => $champs_supplementaires) {
518
			if(!in_array($cle, $this->champs_supp)) continue;
523
			if(!in_array($cle, $this->champs_supp)) continue;
519
			// extrait, depuis un élément de $champ_infos:
524
			// extrait, depuis un élément de $champ_infos:
520
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
525
			// $service, $ressource, $projet, $nom, $intitule, $bdd_champ
521
			extract($champs_supplementaires);
526
			extract($champs_supplementaires);
522
			$valeur_recherche = $ligne_resultat[$bdd_champ];
527
			$valeur_recherche = $ligne_resultat[$bdd_champ];
523
			if(!trim($valeur_recherche)) continue;
528
			if(!trim($valeur_recherche)) continue;
524
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
529
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
525
			$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
530
			$ligne_resultat[$intitule] = $this->chercherSignificationCode($url, $nom);
526
		}
531
		}
527
		return $ligne_resultat;
532
		return $ligne_resultat;
528
	}
533
	}
529
	
534
	
530
	/**
535
	/**
531
	 * Fonction qui ajoute les attributions à une ligne de résultats
536
	 * Fonction qui ajoute les attributions à une ligne de résultats
532
	 *
537
	 *
533
	 * @param array $ligne_tableau_resultat
538
	 * @param array $ligne_tableau_resultat
534
	 * @param array $nom_sci
539
	 * @param array $nom_sci
535
	 */
540
	 */
536
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
541
	public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
537
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
542
		if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
538
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
543
			$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
539
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
544
			$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
540
		} else {
545
		} else {
541
			$ligne_tableau_resultat = null;
546
			$ligne_tableau_resultat = null;
542
		}
547
		}
543
		return $ligne_tableau_resultat;
548
		return $ligne_tableau_resultat;
544
	}
549
	}
545
	
550
	
546
	private function trierLigneTableau($a, $b) {
551
	private function trierLigneTableau($a, $b) {
547
		$retour = 0;
552
		$retour = 0;
548
		
553
		
549
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
554
		if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
550
			$retour = 0;
555
			$retour = 0;
551
		}
556
		}
552
				
557
				
553
		if($this->champ_tri == 'code_langue') {
558
		if($this->champ_tri == 'code_langue') {
554
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
559
			if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
555
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
560
				$retour = ($this->direction_tri == 'asc') ? -1 : 1;
556
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
561
			} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
557
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
562
				$retour = ($this->direction_tri == 'asc') ? 1 : -1;
558
			} else {
563
			} else {
559
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
564
				$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
560
			}
565
			}
561
		} else {
566
		} else {
562
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
567
			$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
563
		}
568
		}
564
		return $retour;
569
		return $retour;
565
	}
570
	}
566
	
571
	
567
	private function comparerChaineSelonDirectionTri($a, $b) {
572
	private function comparerChaineSelonDirectionTri($a, $b) {
568
		if($this->direction_tri == 'asc') {
573
		if($this->direction_tri == 'asc') {
569
			return ($a < $b) ? -1 : 1;
574
			return ($a < $b) ? -1 : 1;
570
		} else {
575
		} else {
571
			return ($a > $b) ? -1 : 1;
576
			return ($a > $b) ? -1 : 1;
572
		}
577
		}
573
	}
578
	}
574
	
579
	
575
	// formatage de la reponse /id ss la forme
580
	// formatage de la reponse /id ss la forme
576
	// id, nom_vernaculaire, attributions
581
	// id, nom_vernaculaire, attributions
577
	// langue
582
	// langue
578
	// num_nom (correspond à un taxon bdtfx)
583
	// num_nom (correspond à un taxon bdtfx)
579
	public function formaterNomsVernaculairesId($resultat) {
584
	public function formaterNomsVernaculairesId($resultat) {
580
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
585
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
581
			// on crée les variables qui serviront de clés et on les enléves du tableau
586
			// on crée les variables qui serviront de clés et on les enléves du tableau
582
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
587
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
583
			unset($taxon['num_nom_vernaculaire']);
588
			unset($taxon['num_nom_vernaculaire']);
584
			$langue = $taxon['code_langue'];
589
			$langue = $taxon['code_langue'];
585
			unset($taxon['code_langue']);
590
			unset($taxon['code_langue']);
586
 
591
 
587
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
592
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
588
				if (isset($taxon[$key]) && $taxon[$key] != "") {
593
				if (isset($taxon[$key]) && $taxon[$key] != "") {
589
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
594
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
590
				}
595
				}
591
			}
596
			}
592
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
597
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
593
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
598
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
594
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
599
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
595
				}
600
				}
596
			}
601
			}
597
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
602
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
598
		}
603
		}
599
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
604
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
600
		unset($this->table_retour['href']);
605
		unset($this->table_retour['href']);
601
		return $this->table_retour;
606
		return $this->table_retour;
602
	}
607
	}
603
 
608
 
604
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
609
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
605
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
610
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
606
			$this->table_retour[$champ] = $valeur;
611
			$this->table_retour[$champ] = $valeur;
607
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
612
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
608
				switch ($match[1]) {
613
				switch ($match[1]) {
609
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
614
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
610
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
615
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
611
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
616
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
612
						break;
617
						break;
613
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
618
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
614
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
619
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
615
					default : break;
620
					default : break;
616
				}
621
				}
617
 
622
 
618
		} elseif ($langue != '') {
623
		} elseif ($langue != '') {
619
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
624
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
620
		} else {
625
		} else {
621
			$this->table_retour[$champ] = $valeur;
626
			$this->table_retour[$champ] = $valeur;
622
		}
627
		}
623
	}
628
	}
624
 
629
 
625
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
630
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
626
		if (isset($this->champ_infos[$nomChamp])) {
631
		if (isset($this->champ_infos[$nomChamp])) {
627
			extract($this->champ_infos[$nomChamp]);
632
			extract($this->champ_infos[$nomChamp]);
628
		}
633
		}
629
 
634
 
630
		if ($this->retour_format == 'max') {
635
		if ($this->retour_format == 'max') {
631
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
636
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
632
			if ($service == 'taxons') {
637
			if ($service == 'taxons') {
633
				$code_valeur = '';
638
				$code_valeur = '';
634
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
639
				$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
635
			} else {
640
			} else {
636
				$code_valeur = $this->chercherSignificationCode($url, $nom);
641
				$code_valeur = $this->chercherSignificationCode($url, $nom);
637
			}
642
			}
638
			if ($projet != '') $projet .= '.';
643
			if ($projet != '') $projet .= '.';
639
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
644
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
640
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
645
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
641
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
646
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
642
		} else {
647
		} else {
643
			if ($projet != '') $projet .= '.';
648
			if ($projet != '') $projet .= '.';
644
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
649
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
645
		}
650
		}
646
	}
651
	}
647
 
652
 
648
	public function chercherSignificationCode($url, $nom) {
653
	public function chercherSignificationCode($url, $nom) {
649
		if (isset($this->signification_code[$url])) {
654
		if (isset($this->signification_code[$url])) {
650
			$valeur = $this->signification_code[$url];
655
			$valeur = $this->signification_code[$url];
651
		} else {
656
		} else {
652
			$res = $this->consulterHref($url);
657
			$res = $this->consulterHref($url);
653
			$valeur = $res->$nom;
658
			$valeur = $res->$nom;
654
			$this->signification_code[$url] = $valeur;
659
			$this->signification_code[$url] = $valeur;
655
		}
660
		}
656
		return $valeur;
661
		return $valeur;
657
	}
662
	}
658
 
663
 
659
	public function afficherTaxons() {
664
	public function afficherTaxons() {
660
		$resultat = $this->recupererNomTaxons();
665
		$resultat = $this->recupererNomTaxons();
661
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
666
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
662
			foreach ($langue as $num_nom=>$taxon) {
667
			foreach ($langue as $num_nom=>$taxon) {
663
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
668
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
664
				if (isset($resultat[$num_tax])) {
669
				if (isset($resultat[$num_tax])) {
665
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
670
					$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
666
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
671
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
667
				}
672
				}
668
			}
673
			}
669
		}
674
		}
670
	}
675
	}
671
	
676
	
672
	public function recupererNomTaxons() {
677
	public function recupererNomTaxons() {
673
		$taxons = array_unique($this->taxons);
678
		$taxons = array_unique($this->taxons);
674
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
679
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
675
		$res = $this->consulterHref($url);
680
		$res = $this->consulterHref($url);
676
		foreach ($res->resultat as $id=>$taxon) {
681
		foreach ($res->resultat as $id=>$taxon) {
677
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
682
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
678
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
683
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
679
		}
684
		}
680
		return $resultat;
685
		return $resultat;
681
	}
686
	}
682
 
687
 
683
	public function formaterNomsVernaculairesIdChamp($resultat) {
688
	public function formaterNomsVernaculairesIdChamp($resultat) {
684
		$this->table_retour['id'] = $this->ressources[0];
689
		$this->table_retour['id'] = $this->ressources[0];
685
		$champs = explode(' ', $this->ressources[1]);
690
		$champs = explode(' ', $this->ressources[1]);
686
		if (in_array('attributions', $champs) != false) {
691
		if (in_array('attributions', $champs) != false) {
687
			$this->formaterNomsVernaculairesId($resultat);
692
			$this->formaterNomsVernaculairesId($resultat);
688
			unset($this->table_retour['nom_vernaculaire']);
693
			unset($this->table_retour['nom_vernaculaire']);
689
		} else {
694
		} else {
690
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
695
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
691
			foreach ($resultat as $taxon) {
696
			foreach ($resultat as $taxon) {
692
				foreach ($taxon as $key=>$valeur) {
697
				foreach ($taxon as $key=>$valeur) {
693
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
698
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
694
						$this->table_retour['attributions']['langue'][] = $valeur;
699
						$this->table_retour['attributions']['langue'][] = $valeur;
695
					} elseif (in_array($key, $champ_attributions) != false) {
700
					} elseif (in_array($key, $champ_attributions) != false) {
696
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
701
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
697
					} elseif (in_array($key, $champs) != false) {
702
					} elseif (in_array($key, $champs) != false) {
698
						$this->table_retour[$key] = $valeur;
703
						$this->table_retour[$key] = $valeur;
699
					}
704
					}
700
				}
705
				}
701
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
706
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
702
			}
707
			}
703
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
708
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
704
		}
709
		}
705
		return $this->table_retour;
710
		return $this->table_retour;
706
	}
711
	}
707
 
712
 
708
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
713
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
709
		preg_match('/^(.*)\.code$/', $champ, $match);
714
		preg_match('/^(.*)\.code$/', $champ, $match);
710
		$champ = $match[1];
715
		$champ = $match[1];
711
		if (isset($this->champ_infos[$champ])) {
716
		if (isset($this->champ_infos[$champ])) {
712
			extract($this->champ_infos[$champ]);
717
			extract($this->champ_infos[$champ]);
713
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
718
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
714
			$projet .= '.';
719
			$projet .= '.';
715
		}
720
		}
716
 
721
 
717
		$champs = explode(' ', $this->ressources[1]);
722
		$champs = explode(' ', $this->ressources[1]);
718
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
723
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
719
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
724
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
720
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
725
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
721
		}
726
		}
722
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
727
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
723
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
728
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
724
		}
729
		}
725
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
730
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
726
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
731
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
727
		}
732
		}
728
		if (in_array($champ, $champs) !== false) {
733
		if (in_array($champ, $champs) !== false) {
729
			if (isset($url)) {
734
			if (isset($url)) {
730
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
735
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
731
			} else {
736
			} else {
732
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
737
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
733
			}
738
			}
734
		}
739
		}
735
	}
740
	}
736
 
741
 
737
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
742
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
738
		if ($this->retour_format == 'max') {
743
		if ($this->retour_format == 'max') {
739
				$this->table_retour['attributions'][$nomChamp] = $nom;
744
				$this->table_retour['attributions'][$nomChamp] = $nom;
740
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
745
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
741
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
746
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
742
		} else {
747
		} else {
743
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
748
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
744
		}
749
		}
745
	}
750
	}
746
 
751
 
747
	public function chargerBiblio($num_nom, $langue) {
752
	public function chargerBiblio($num_nom, $langue) {
748
		list($table, $version) = explode('_v',$this->table);
753
		list($table, $version) = explode('_v',$this->table);
749
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
754
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
750
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
755
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
751
		$resultat = $this->getBdd()->recupererTous($requete);
756
		$resultat = $this->getBdd()->recupererTous($requete);
752
 
757
 
753
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
758
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
754
		 	$r = 'La requête SQL formée comporte une erreur !!';
759
		 	$r = 'La requête SQL formée comporte une erreur !!';
755
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
760
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
756
			Debug::printr($requete);
761
			Debug::printr($requete);
757
		 } elseif ($resultat) {
762
		 } elseif ($resultat) {
758
			foreach ($resultat as $res) {
763
			foreach ($resultat as $res) {
759
			   	foreach ($res as $cle => $valeur) {
764
			   	foreach ($res as $cle => $valeur) {
760
			   		if ($valeur !== "") {
765
			   		if ($valeur !== "") {
761
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
766
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
762
			   		}
767
			   		}
763
			    }
768
			    }
764
			}
769
			}
765
		}
770
		}
766
	}
771
	}
767
 
772
 
768
}
773
}
769
?>
774
?>