Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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