Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 152 Rev 160
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
class NomsVernaculaires extends Commun {
24
class NomsVernaculaires extends Commun {
25
	protected $champ_infos = array(
25
	protected $champ_infos = array(
26
			'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtfx', 'nom' => 'nom_sci'),
26
			'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtfx', 'nom' => 'nom_sci'),
27
			'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom'),
27
			'conseil_emploi' => array('service' => 'ontologies', 'ressource' => 'numStatut:', 'projet' => 'nvjfl', 'nom' => 'nom'),
28
			'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom'));
28
			'genre' => array('service' => 'ontologies', 'ressource' => 'genreNombre:', 'projet' => 'nvjfl', 'nom' => 'nom'));
29
 
29
 
30
	protected $service = 'noms-vernaculaires';
30
	protected $service = 'noms-vernaculaires';
31
 
31
 
32
	/**
32
	/**
33
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
33
	 * Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
34
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
34
	 *  /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
35
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
35
	 * Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
36
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
36
	 * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
37
	protected $format_reponse = 'noms-vernaculaires';
37
	protected $format_reponse = 'noms-vernaculaires';
38
 
38
 
39
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
39
	/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
40
	 * selon ressources et paramètres */
40
	 * selon ressources et paramètres */
41
	protected $requete_champ = array(' * ');
41
	protected $requete_champ = array(' * ');
42
	protected $requete_condition = '';
42
	protected $requete_condition = '';
43
	protected $limite_requete = array(
43
	protected $limite_requete = array(
44
		'depart' => 0,
44
		'depart' => 0,
45
		'limite' => 100
45
		'limite' => 100
46
	);
46
	);
47
 
47
 
48
	/**
48
	/**
49
	 * Precise la contenance plus ou moins précise du tableau à retourner :
49
	 * Precise la contenance plus ou moins précise du tableau à retourner :
50
	 *  - min = les données présentes dans la table
50
	 *  - min = les données présentes dans la table
51
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
51
	 *  - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
52
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
52
	 *  - oss = la liste des nom_sci (uniquement pour noms et taxons) */
53
	protected $retour_format = 'max';
53
	protected $retour_format = 'max';
54
	/** Valeur du paramètre de requete recherche :
54
	/** Valeur du paramètre de requete recherche :
55
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
55
	 *  - stricte : le masque est passé tel quel à l'opérateur LIKE.
56
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
56
	 *  - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
57
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
57
	 *  - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
58
	protected $recherche;
58
	protected $recherche;
59
 
59
 
60
	/** Permet de stocker le tableau de résultat (non encodé en json) */
60
	/** Permet de stocker le tableau de résultat (non encodé en json) */
61
	protected $table_retour = array();
61
	protected $table_retour = array();
62
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
62
	/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
63
	protected $total_resultat;
63
	protected $total_resultat;
64
 
64
 
65
	//+------------------------------------------------------------------------------------------------------+
65
	//+------------------------------------------------------------------------------------------------------+
66
	// créer une condition en fonction du paramétre
66
	// créer une condition en fonction du paramétre
67
	public function traiterParametres() {
67
	public function traiterParametres() {
68
		if (isset($this->parametres) && !empty($this->parametres)) {
68
		if (isset($this->parametres) && !empty($this->parametres)) {
69
 
69
 
70
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
70
			if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
71
				$this->recherche = $this->parametres['recherche'];
71
				$this->recherche = $this->parametres['recherche'];
72
			}
72
			}
73
			foreach ($this->parametres as $param => $valeur) {
73
			foreach ($this->parametres as $param => $valeur) {
74
				switch ($param) {
74
				switch ($param) {
75
					case 'masque' :
75
					case 'masque' :
76
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
76
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
77
						break;
77
						break;
78
					case 'masque.nt' :
78
					case 'masque.nt' :
79
						$this->ajouterLeFiltreMasque('num_taxon', $valeur);
79
						$this->ajouterLeFiltreMasque('num_taxon', $valeur);
80
						break;
80
						break;
81
					case 'masque.nv' :
81
					case 'masque.nv' :
82
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
82
						$this->ajouterLeFiltreMasque('nom_vernaculaire', $valeur);
83
						break;
83
						break;
84
					case 'masque.lg' :
84
					case 'masque.lg' :
85
						$this->ajouterLeFiltreMasque('code_langue', $valeur);
85
						$this->ajouterLeFiltreMasque('code_langue', $valeur);
86
						break;
86
						break;
87
					case 'masque.cce' :
87
					case 'masque.cce' :
88
						$this->ajouterLeFiltreMasque('num_statut', $valeur);
88
						$this->ajouterLeFiltreMasque('num_statut', $valeur);
89
						break;
89
						break;
90
					case 'retour.format' :
90
					case 'retour.format' :
91
						$this->retour_format = $valeur;
91
						$this->retour_format = $valeur;
92
						break;
92
						break;
93
					case 'navigation.depart' :
93
					case 'navigation.depart' :
94
						$this->limite_requete['depart'] = $valeur;
94
						$this->limite_requete['depart'] = $valeur;
95
						break;
95
						break;
96
					case 'navigation.limite' :
96
					case 'navigation.limite' :
97
						$this->limite_requete['limite'] = $valeur;
97
						$this->limite_requete['limite'] = $valeur;
98
						break;
98
						break;
99
					case 'recherche' :
99
					case 'recherche' :
100
						break;
100
						break;
101
					case 'version.projet' :
101
					case 'version.projet' :
102
						break;
102
						break;
103
					default :
103
					default :
104
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
104
						$p = 'Erreur dans les paramètres de recherche de votre requête : '.
105
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
105
							'</br> Le paramètre " '.$param.' " n\'existe pas.';
106
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
106
							$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
107
				}
107
				}
108
			}
108
			}
109
		}
109
		}
110
	}
110
	}
111
 
111
 
112
	public function ajouterLeFiltreMasque($nom_champ, $valeur) {
112
	public function ajouterLeFiltreMasque($nom_champ, $valeur) {
113
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
113
		if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
114
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
114
			$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
115
		} else {
115
		} else {
116
			if ($this->recherche == 'floue') {
116
			if ($this->recherche == 'floue') {
117
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
117
				$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
118
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
118
					.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
119
			} else {
119
			} else {
120
				if ($this->recherche == 'etendue') {
120
				if ($this->recherche == 'etendue') {
121
					$valeur = str_replace(' ','% ', $valeur);
121
					$valeur = str_replace(' ','% ', $valeur);
122
					$valeur .= '%';
122
					$valeur .= '%';
123
				}
123
				}
124
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
124
				$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
125
			}
125
			}
126
		}
126
		}
127
	}
127
	}
128
 
128
 
129
	//+------------------------------------------------------------------------------------------------------+
129
	//+------------------------------------------------------------------------------------------------------+
130
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
130
	// en fonction de la présence des ressources modifie requete_champ et requete_condition
131
	public function traiterRessources() {
131
	public function traiterRessources() {
132
		if (isset($this->ressources) && !empty($this->ressources)) {
132
		if (isset($this->ressources) && !empty($this->ressources)) {
133
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
133
			if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
134
				$this->traiterRessourceId(); // ajoute condition id=#valeur
134
				$this->traiterRessourceId(); // ajoute condition id=#valeur
135
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
135
				if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
136
					$this->traiterRessourceChampOuRelations(); //modifie requete_champ ou requete_condition
136
					$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
137
				}
137
				}
138
			}
138
			}
139
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
139
		} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
140
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
140
			$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
141
		}
141
		}
142
	}
142
	}
143
 
143
 
144
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
144
	//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
145
	public function traiterRessourceId() {
145
	public function traiterRessourceId() {
146
		if (is_numeric($this->ressources[0])) {
146
		if (is_numeric($this->ressources[0])) {
147
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
147
			$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
148
			$this->format_reponse .= '/id';
148
			$this->format_reponse .= '/id';
-
 
149
		} elseif ($this->ressources[0] == 'attributions') {
-
 
150
			$this->format_reponse .= '/attributions';
149
		} else {
151
		} else {
150
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
152
			$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
151
				' " n\'existe pas.';
153
				' " n\'existe pas.';
152
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
154
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
153
		}
155
		}
154
	}
156
	}
155
 
157
 
156
 
158
 
157
	public function traiterRessourceChampOuRelations() {
-
 
158
		//requete = /noms-vernaculaires/#id/relations :
-
 
159
		if ($this->ressources[1] == 'relations') {
-
 
160
			$this->format_reponse .= '/relations';
-
 
161
			$this->requete_condition[] = 'num_taxon = (SELECT region FROM '.$this->table.' WHERE '
-
 
162
										.implode(' AND ', $this->requete_condition).')';
-
 
163
		//requete = /noms-vernaculaires/#id/#champ :
-
 
164
		} else {
159
	public function traiterRessourceChamp() {
165
			$this->format_reponse .= '/champ';
160
		$this->format_reponse .= '/champ';
166
			$this->analyserChamp();
-
 
167
		}
161
		$this->analyserChamp();
168
	}
162
	}
169
 
163
 
170
	public function analyserChamp() {
164
	public function analyserChamp() {
171
		$this->requete_champ = array();
165
		$this->requete_champ = array();
172
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
166
		$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
173
		$champs = explode(' ', $this->ressources[1]);
167
		$champs = explode(' ', $this->ressources[1]);
174
		foreach ($champs as $champ) {
168
		foreach ($champs as $champ) {
175
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
169
			preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
176
			if (isset($this->champs_possibles[$match[1]])) {
170
			if (isset($this->champs_possibles[$match[1]])) {
177
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
171
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
178
			} elseif (isset($this->champs_possibles[$match[0]])) {
172
			} elseif (isset($this->champs_possibles[$match[0]])) {
179
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
173
				$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
180
			} else {
174
			} else {
181
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
175
				$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
182
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
176
				$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
183
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
177
					'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
184
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
178
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
185
			}
179
			}
186
		}
180
		}
187
	}
181
	}
188
 
182
 
189
	//+------------------------------------------------------------------------------------------------------+
183
	//+------------------------------------------------------------------------------------------------------+
190
	public function assemblerLaRequete() {
184
	public function assemblerLaRequete() {
191
		$requete = ' SELECT '.$this->formerRequeteChamp().
185
		$requete = ' SELECT '.$this->formerRequeteChamp().
192
					' FROM '.$this->table
186
					' FROM '.$this->table
193
					.$this->formerRequeteCondition()
187
					.$this->formerRequeteCondition()
194
					.$this->formerRequeteLimite();
188
					.$this->formerRequeteLimite();
195
		return $requete;
189
		return $requete;
196
	}
190
	}
197
 
191
 
198
	public  function formerRequeteChamp() {
192
	public  function formerRequeteChamp() {
199
		if (in_array('*', $this->requete_champ)) {
193
		if (in_array('*', $this->requete_champ)) {
200
			$champ = ' * ';
194
			$champ = ' * ';
201
		} else {
195
		} else {
202
			$champ = implode(', ', $this->requete_champ);
196
			$champ = implode(', ', $this->requete_champ);
203
		}
197
		}
204
		return $champ;
198
		return $champ;
205
	}
199
	}
206
 
200
 
207
	public  function formerRequeteCondition() {
201
	public  function formerRequeteCondition() {
208
		$condition = '';
202
		$condition = '';
209
		if ($this->requete_condition != null) {
203
		if ($this->requete_condition != null) {
210
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
204
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
211
		}
205
		}
212
		return $condition;
206
		return $condition;
213
	}
207
	}
214
 
208
 
215
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
209
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
216
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
210
	// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
217
	public function formerRequeteLimite() {
211
	public function formerRequeteLimite() {
218
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
212
		if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
219
			$this->requete_limite = '';
213
			$this->requete_limite = '';
220
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
214
		} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
221
			$this->limite_requete['depart'] =
215
			$this->limite_requete['depart'] =
222
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
216
				(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
223
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
217
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
224
		} else {
218
		} else {
225
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
219
			$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
226
		}
220
		}
227
		return $this->requete_limite;
221
		return $this->requete_limite;
228
	}
222
	}
229
 
223
 
230
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
224
	//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
231
	public function recupererTotalResultat() {
225
	public function recupererTotalResultat() {
-
 
226
		$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
232
		$requete = 'SELECT count(distinct(id)) as nombre FROM '
227
		$requete = 'SELECT count('.$distinct.') as nombre FROM '
233
			.$this->table
228
			.$this->table
234
			.$this->formerRequeteCondition();
229
			.$this->formerRequeteCondition();
235
		$res = $this->getBdd()->recuperer($requete);
230
		$res = $this->getBdd()->recuperer($requete);
236
 
231
 
237
		if ($res) {
232
		if ($res) {
238
			$total = $res['nombre'];
233
			$total = $res['nombre'];
239
		} else {
234
		} else {
240
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base';
235
			$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
241
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
236
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
242
		}
237
		}
243
		return $total;
238
		return $total;
244
	}
239
	}
245
 
240
 
246
	//+------------------------------------------------------------------------------------------------------+
241
	//+------------------------------------------------------------------------------------------------------+
247
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
242
	// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
248
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
243
	// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
249
	public function retournerResultatFormate($resultat) {
244
	public function retournerResultatFormate($resultat) {
250
		$this->recupererTableConfig('correspondance_champs');
245
		$this->recupererTableConfig('correspondance_champs');
251
		switch ($this->format_reponse) {
246
		switch ($this->format_reponse) {
252
			case 'noms-vernaculaires'				: 
247
			case 'noms-vernaculaires'				: 
253
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
248
				$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat);			break;
-
 
249
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
254
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
250
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
255
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
251
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
256
			default									:																	break;
252
			default									:																	break;
257
		}
253
		}
258
		return $reponse;
254
		return $reponse;
259
	}
255
	}
260
 
256
 
261
	public function formaterNomsVernaculaires($resultat) {
257
	public function formaterNomsVernaculaires($resultat) {
262
		//on remplit la table $table_retour_json['entete']
258
		//on remplit la table $table_retour_json['entete']
263
		$table_retour_json['entete']['masque'] = implode('&', $this->parametres);
259
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
264
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
260
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
265
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
261
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
266
		$table_retour_json['entete']['total']  = $this->total_resultat;
262
		$table_retour_json['entete']['total']  = $this->total_resultat;
267
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
263
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
268
		if (isset($url['precedent']) && $url['precedent'] != '') { $table_retour_json['entete']['href.precedent'] = $url['precedent']; }
264
		if (isset($url['precedent']) && $url['precedent'] != '') { $table_retour_json['entete']['href.precedent'] = $url['precedent']; }
269
		if (isset($url['suivant']) && $url['suivant']   != '') { $table_retour_json['entete']['href.suivant']   = $url['suivant']; }
265
		if (isset($url['suivant']) && $url['suivant']   != '') { $table_retour_json['entete']['href.suivant']   = $url['suivant']; }
270
 
266
		
271
		//on remplit la table $table_retour_json['resultat']
267
		//on remplit la table $table_retour_json['resultat']
272
		if (isset($this->parametres['masque.nv'])) {
268
		if (isset($this->parametres['masque.nv'])) {
273
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
269
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
274
		}
270
		}
275
		if (isset($this->parametres['masque'])) {
271
		if (isset($this->parametres['masque'])) {
276
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
272
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
277
		}
273
		}
278
		foreach ($resultat as $tab) {
274
		foreach ($resultat as $tab) {
279
			foreach ($tab as $key => $valeur) {
275
			foreach ($tab as $key => $valeur) {
280
				if ($valeur != '') {
276
				if ($valeur != '') {
281
					switch ($key) {
277
					switch ($key) {
282
						case 'id'				: $num = $valeur;								break;
278
						case 'id'				: $num = $valeur;								break;
283
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
279
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
284
						default					:												break;
280
						default					:												break;
285
					}
281
					}
286
				}
282
				}
287
			}
283
			}
288
			if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
284
			if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
289
			$resultat_json[$num] = $this->table_retour;
285
			$resultat_json[$num] = $this->table_retour;
290
			$this->table_retour = array();
286
			$this->table_retour = array();
291
		}
287
		}
292
 
288
 
293
		$table_retour_json['resultat'] = $resultat_json;
289
		$table_retour_json['resultat'] = $resultat_json;
294
		return $table_retour_json;
290
		return $table_retour_json;
295
	}
291
	}
-
 
292
	
-
 
293
	public function recupererMasque() {
-
 
294
		$tab_masque = array();
-
 
295
		foreach ($this->parametres as $param=>$valeur) {
-
 
296
			if (strstr($param, 'masque') != false) {
-
 
297
				$tab_masque[] = $param.'='.$valeur;
-
 
298
			}
-
 
299
		}
-
 
300
		$masque = implode('&', $tab_masque);
-
 
301
		return $masque;
-
 
302
	}
296
	
303
	
297
	public function formaterEnOss($resultat) {
304
	public function formaterEnOss($resultat) {
298
		$table_nom = array();
305
		$table_nom = array();
299
		$oss = '';
306
		$oss = '';
300
		foreach ($resultat as $tab) {
307
		foreach ($resultat as $tab) {
301
			if (isset($tab['nom_vernaculaire']) ) {
308
			if (isset($tab['nom_vernaculaire']) ) {
302
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
309
				if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
303
					$table_nom[] = $tab['nom_vernaculaire'];
310
					$table_nom[] = $tab['nom_vernaculaire'];
304
					$oss [] = $tab['nom_vernaculaire'];
311
					$oss [] = $tab['nom_vernaculaire'];
305
				}
312
				}
306
			}
313
			}
307
		}
314
		}
308
		if (isset($this->masque)) $masque = implode('&', $this->masque);
315
		if (isset($this->masque)) $masque = implode('&', $this->masque);
309
		else $masque = 'Pas de masque';
316
		else $masque = 'Pas de masque';
310
		$table_retour_oss = array($masque, $oss);
317
		$table_retour_oss = array($masque, $oss);
311
		return $table_retour_oss;
318
		return $table_retour_oss;
312
	}
319
	}
-
 
320
	
-
 
321
	public function formaterNomsVernaculairesAttributions($resultat) {
-
 
322
		//on remplie la table $table_retour_json['entete']
-
 
323
		$table_retour_json['entete']['masque'] = $this->recupererMasque();
-
 
324
		$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
-
 
325
		$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
-
 
326
		$table_retour_json['entete']['total']  = $this->total_resultat;
-
 
327
		$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
-
 
328
		if (isset($url['precedent']) && $url['precedent'] != '') {
-
 
329
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
-
 
330
		}
-
 
331
		if (isset($url['suivant']) && $url['suivant']   != '') {
-
 
332
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
-
 
333
		}
-
 
334
	
-
 
335
		//on remplie la table $table_retour_json['resultat']
-
 
336
		if (isset($this->parametres['masque.nv'])) {
-
 
337
			$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
-
 
338
		}
-
 
339
		if (isset($this->parametres['masque'])) {
-
 
340
			$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
-
 
341
		}
-
 
342
		foreach ($resultat as $tab) {
-
 
343
			$resultat_json[$tab['num_nom_vernaculaire']]['id'] = $tab['id'];
-
 
344
			$resultat_json[$tab['num_nom_vernaculaire']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
-
 
345
			$resultat_json[$tab['num_nom_vernaculaire']]['langue.code'] = $tab['code_langue'];
-
 
346
			$resultat_json[$tab['num_nom_vernaculaire']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
-
 
347
			if ($this->retour_format == 'max') {
-
 
348
				$resultat_json[$tab['num_nom_vernaculaire']]['taxon'] = $tab['num_taxon'];
-
 
349
				$this->taxons[] = $tab['num_taxon']; // utiliser pour chercher les noms latins
-
 
350
				$resultat_json[$tab['num_nom_vernaculaire']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
-
 
351
			}
-
 
352
		}
-
 
353
		
-
 
354
		if ($this->retour_format == 'max') {
-
 
355
			$resultat_json = $this->afficherTaxonsAttributions($resultat_json);
-
 
356
		}
-
 
357
		
-
 
358
		$table_retour_json['resultat'] = $resultat_json;
-
 
359
		return $table_retour_json;
-
 
360
	}
-
 
361
	
-
 
362
	public function afficherTaxonsAttributions($resultat) {
-
 
363
		$nom_sci = $this->recupererNomTaxons();
-
 
364
		foreach ($resultat as $num=>$tab) {
-
 
365
			if (isset($nom_sci[$tab['taxon']])) {
-
 
366
				$resultat[$num]['taxon'] = $nom_sci[$tab['taxon']];
-
 
367
			}
-
 
368
		}
-
 
369
		return $resultat;
-
 
370
	}
313
 
371
	
314
	// formatage de la reponse /id ss la forme
372
	// formatage de la reponse /id ss la forme
315
	// id, nom_vernaculaire, attributions
373
	// id, nom_vernaculaire, attributions
316
	// langue
374
	// langue
317
	// num_nom (correspond à un taxon bdtfx)
375
	// num_nom (correspond à un taxon bdtfx)
318
	public function formaterNomsVernaculairesId($resultat) {
376
	public function formaterNomsVernaculairesId($resultat) {
319
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
377
		foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
320
			// on crée les variables qui serviront de clés et on les enléves du tableau
378
			// on crée les variables qui serviront de clés et on les enléves du tableau
321
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
379
			$num_nom = $taxon['num_nom_vernaculaire']; // unique pour un trinôme id, langue, taxon
322
			unset($taxon['num_nom_vernaculaire']);
380
			unset($taxon['num_nom_vernaculaire']);
323
			$langue = $taxon['code_langue'];
381
			$langue = $taxon['code_langue'];
324
			unset($taxon['code_langue']);
382
			unset($taxon['code_langue']);
325
 
383
 
326
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
384
			foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
327
				if (isset($taxon[$key]) && $taxon[$key] != "") {
385
				if (isset($taxon[$key]) && $taxon[$key] != "") {
328
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
386
					$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
329
				}
387
				}
330
			}
388
			}
331
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
389
			foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
332
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
390
				if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
333
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
391
					$this->afficherDonnees($key, $valeur, $langue, $num_nom);
334
				}
392
				}
335
			}
393
			}
336
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
394
			if ($this->retour_format == 'max') $this->chargerBiblio($num_nom, $langue);
337
		}
395
		}
338
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
396
		if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
339
		unset($this->table_retour['href']);
397
		unset($this->table_retour['href']);
340
		return $this->table_retour;
398
		return $this->table_retour;
341
	}
399
	}
342
 
400
 
343
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
401
	public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
344
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
402
		if ($champ == 'id' || $champ == 'nom_vernaculaire') {
345
			$this->table_retour[$champ] = $valeur;
403
			$this->table_retour[$champ] = $valeur;
346
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
404
		} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
347
				switch ($match[1]) {
405
				switch ($match[1]) {
348
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
406
					case 'taxon'	: if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
349
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
407
						$this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
350
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
408
					case 'langue'	: //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
351
						break;
409
						break;
352
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
410
					case 'genre'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
353
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
411
					case 'conseil_emploi'	: $this->afficherPointCode($match[1], $langue, $num_nom, $valeur);	break;
354
					default : break;
412
					default : break;
355
				}
413
				}
356
 
414
 
357
		} elseif ($langue != '') {
415
		} elseif ($langue != '') {
358
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
416
			$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
359
		} else {
417
		} else {
360
			$this->table_retour[$champ] = $valeur;
418
			$this->table_retour[$champ] = $valeur;
361
		}
419
		}
362
	}
420
	}
363
 
421
 
364
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
422
	public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
365
		if (isset($this->champ_infos[$nomChamp])) {
423
		if (isset($this->champ_infos[$nomChamp])) {
366
			extract($this->champ_infos[$nomChamp]);
424
			extract($this->champ_infos[$nomChamp]);
367
		}
425
		}
368
 
426
 
369
		if ($this->retour_format == 'max') {
427
		if ($this->retour_format == 'max') {
370
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
428
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
371
			if ($service == 'taxons') {
429
			if ($service == 'taxons') {
372
				$code_valeur = '';
430
				$code_valeur = '';
373
			} else {
431
			} else {
374
				$code_valeur = $this->chercherSignificationCode($url, $nom);
432
				$code_valeur = $this->chercherSignificationCode($url, $nom);
375
			}
433
			}
376
			if ($projet != '') $projet .= '.';
434
			if ($projet != '') $projet .= '.';
377
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
435
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
378
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
436
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
379
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
437
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
380
		} else {
438
		} else {
381
			if ($projet != '') $projet .= '.';
439
			if ($projet != '') $projet .= '.';
382
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
440
			$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
383
		}
441
		}
384
	}
442
	}
385
 
443
 
386
	public function chercherSignificationCode($url, $nom) {
444
	public function chercherSignificationCode($url, $nom) {
387
		if (isset($this->signification_code[$url])) {
445
		if (isset($this->signification_code[$url])) {
388
			$valeur = $this->signification_code[$url];
446
			$valeur = $this->signification_code[$url];
389
		} else {
447
		} else {
390
			$res = $this->consulterHref($url);
448
			$res = $this->consulterHref($url);
391
			$valeur = $res->$nom;
449
			$valeur = $res->$nom;
392
			$this->signification_code[$url] = $valeur;
450
			$this->signification_code[$url] = $valeur;
393
		}
451
		}
394
		return $valeur;
452
		return $valeur;
395
	}
453
	}
396
 
454
 
397
	public function afficherTaxons() {
455
	public function afficherTaxons() {
398
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.$this->getBdd()->proteger(implode(',', $this->taxons));
-
 
399
		$res = $this->consulterHref($url);
456
		$resultat = $this->recupererNomTaxons();
400
		foreach ($res->resultat as $id=>$taxon) {
-
 
401
			$resultat[$id] = $taxon->nom_sci;
-
 
402
		}
-
 
403
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
457
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
404
			foreach ($langue as $num_nom=>$taxon) {
458
			foreach ($langue as $num_nom=>$taxon) {
405
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
459
				$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
406
				if (isset($resultat[$num_tax])) {
460
				if (isset($resultat[$num_tax])) {
407
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax];
461
					$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax];
408
				}
462
				}
409
			}
463
			}
410
		}
464
		}
411
	}
465
	}
-
 
466
	
-
 
467
	public function recupererNomTaxons() {
-
 
468
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&masque.nt='.
-
 
469
			$this->getBdd()->proteger(implode(',', $this->taxons));
-
 
470
		$res = $this->consulterHref($url);
-
 
471
		foreach ($res->resultat as $id=>$taxon) {
-
 
472
			$resultat[$taxon->num_taxonomique] = $taxon->nom_sci;
-
 
473
		}
-
 
474
		return $resultat;
-
 
475
	}
412
 
476
 
413
	public function formaterNomsVernaculairesIdChamp($resultat) {
477
	public function formaterNomsVernaculairesIdChamp($resultat) {
414
		$this->table_retour['id'] = $this->ressources[0];
478
		$this->table_retour['id'] = $this->ressources[0];
415
		$champs = explode(' ', $this->ressources[1]);
479
		$champs = explode(' ', $this->ressources[1]);
416
		if (in_array('attributions', $champs) != false) {
480
		if (in_array('attributions', $champs) != false) {
417
			$this->formaterNomsVernaculairesId($resultat);
481
			$this->formaterNomsVernaculairesId($resultat);
418
			unset($this->table_retour['nom_vernaculaire']);
482
			unset($this->table_retour['nom_vernaculaire']);
419
		} else {//print_r($resultat);
483
		} else {
420
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
484
			$champ_attributions = array('num_taxon', 'zone_usage', 'num_statut', 'num_genre', 'notes');
421
			foreach ($resultat as $taxon) {
485
			foreach ($resultat as $taxon) {
422
				foreach ($taxon as $key=>$valeur) {
486
				foreach ($taxon as $key=>$valeur) {
423
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
487
					if ($key == 'code_langue' && in_array('langue', $champs) != false) {
424
						$this->table_retour['attributions']['langue'][] = $valeur;
488
						$this->table_retour['attributions']['langue'][] = $valeur;
425
					} elseif (in_array($key, $champ_attributions) != false) {
489
					} elseif (in_array($key, $champ_attributions) != false) {
426
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
490
						$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['num_nom_vernaculaire']);
427
					} elseif (in_array($key, $champs) != false) {
491
					} elseif (in_array($key, $champs) != false) {
428
						$this->table_retour[$key] = $valeur;
492
						$this->table_retour[$key] = $valeur;
429
					}
493
					}
430
				}
494
				}
431
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
495
				if (in_array('biblio', $champs) != false) $this->chargerBiblio($taxon['num_nom_vernaculaire'], $taxon['code_langue']);
432
			}
496
			}
433
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
497
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
434
		}
498
		}
435
		return $this->table_retour;
499
		return $this->table_retour;
436
	}
500
	}
437
 
501
 
438
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
502
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
439
		preg_match('/^(.*)\.code$/', $champ, $match);
503
		preg_match('/^(.*)\.code$/', $champ, $match);
440
		$champ = $match[1];
504
		$champ = $match[1];
441
		if (isset($this->champ_infos[$champ])) {
505
		if (isset($this->champ_infos[$champ])) {
442
			extract($this->champ_infos[$champ]);
506
			extract($this->champ_infos[$champ]);
443
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
507
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
444
			$projet .= '.';
508
			$projet .= '.';
445
		}
509
		}
446
 
510
 
447
		$champs = explode(' ', $this->ressources[1]);
511
		$champs = explode(' ', $this->ressources[1]);
448
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
512
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
449
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
513
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
450
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
514
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
451
		}
515
		}
452
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
516
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
453
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
517
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
454
		}
518
		}
455
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
519
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
456
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
520
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
457
		}
521
		}
458
		if (in_array($champ, $champs) !== false) {
522
		if (in_array($champ, $champs) !== false) {
459
			if (isset($url)) {
523
			if (isset($url)) {
460
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
524
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
461
			} else {
525
			} else {
462
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
526
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
463
			}
527
			}
464
		}
528
		}
465
	}
529
	}
466
 
530
 
467
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
531
	public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
468
		if ($this->retour_format == 'max') {
532
		if ($this->retour_format == 'max') {
469
				$this->table_retour['attributions'][$nomChamp] = $nom;
533
				$this->table_retour['attributions'][$nomChamp] = $nom;
470
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
534
				$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
471
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
535
				$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
472
		} else {
536
		} else {
473
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
537
			$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
474
		}
538
		}
475
	}
539
	}
476
 
540
 
477
	public function chargerBiblio($num_nom, $langue) {
541
	public function chargerBiblio($num_nom, $langue) {
478
		list($table, $version) = explode('_v',$this->table);
542
		list($table, $version) = explode('_v',$this->table);
479
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
543
		$requete = "SELECT b.*, lb.notes FROM nvjfl_lien_biblio_v$version lb, nvjfl_biblio_v$version b ".
480
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
544
					"WHERE b.num_ref = lb.num_ref AND lb.num_nom = '$num_nom' ;";
481
		$resultat = $this->getBdd()->recupererTous($requete); //Debug::printr($resultat);
545
		$resultat = $this->getBdd()->recupererTous($requete); //Debug::printr($resultat);
482
 
546
 
483
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
547
		 if ($resultat == '') { //cas ou la requete comporte des erreurs
484
		 	$r = 'La requête SQL formée comporte une erreur !!';
548
		 	$r = 'La requête SQL formée comporte une erreur !!';
485
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
549
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $r);
486
			Debug::printr($requete);
550
			Debug::printr($requete);
487
		 } elseif ($resultat) {
551
		 } elseif ($resultat) {
488
			foreach ($resultat as $res) {
552
			foreach ($resultat as $res) {
489
			   	foreach ($res as $cle => $valeur) {
553
			   	foreach ($res as $cle => $valeur) {
490
			   		if ($valeur !== "") {
554
			   		if ($valeur !== "") {
491
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
555
			   			$this->table_retour['attributions'][$langue][$num_nom]['biblio.'.$cle] = $valeur;
492
			   		}
556
			   		}
493
			    }
557
			    }
494
			}
558
			}
495
		}
559
		}
496
	}
560
	}
497
 
561
 
498
}
562
}
499
?>
563
?>