Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 562 Rev 568
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
* Description :
4
* Description :
5
* Classe CommunNomsTaxons.php
5
* Classe CommunNomsTaxons.php
6
* Encodage en entrée : utf8
6
* Encodage en entrée : utf8
7
* Encodage en sortie : utf8
7
* Encodage en sortie : utf8
8
* @package framework-v3
8
* @package framework-v3
9
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
9
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
10
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
10
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
11
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
* @version 1.0
12
* @version 1.0
13
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
13
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
14
*/
14
*/
15
 
15
 
16
 
16
 
17
abstract class CommunNomsTaxons extends Commun {
17
abstract class CommunNomsTaxons extends Commun {
18
 
18
 
19
	/** Tableau de correspondance entre les noms des champs et les codes de l'ontologie.*/
19
	/** Tableau de correspondance entre les noms des champs et les codes de l'ontologie.*/
20
	private $relationsChampsCodesOntologie = null;
20
	private $relationsChampsCodesOntologie = null;
21
	protected $table_retour; //Permet de stocker le tableau de résultat (non encodé en json)
21
	protected $table_retour; //Permet de stocker le tableau de résultat (non encodé en json)
22
	protected $resultat_req; // Permet de stocker le résultat de la requete principale.
22
	protected $resultat_req; // Permet de stocker le résultat de la requete principale.
23
	protected $compo_nom = null; //Stocke sous forme de tableau les composant du nom à ajouter au nom scientifique
23
	protected $compo_nom = null; //Stocke sous forme de tableau les composant du nom à ajouter au nom scientifique
24
	protected $table;// Nom de la table dans laquelle on récupèrera les données dans les requetes SQL
24
	protected $table;// Nom de la table dans laquelle on récupèrera les données dans les requetes SQL
25
	protected $total_resultat = null;
25
	protected $total_resultat = null;
26
	 /** Stocke le service appelé correspondant. Est utilisé principalement lors de l'affichage du href d'un synonyme
26
	 /** Stocke le service appelé correspondant. Est utilisé principalement lors de l'affichage du href d'un synonyme
27
	  (ex id=12, basionyme num 25 est un synonyme) dans le service taxon */
27
	  (ex id=12, basionyme num 25 est un synonyme) dans le service taxon */
28
	protected $service_href = null;
28
	protected $service_href = null;
29
	protected $erreursParametres = null;
29
	protected $erreursParametres = null;
-
 
30
	protected $sans_nom_sci = array('gen','sp','ssp','fam','au_ss','bib_ss');
-
 
31
	private $bib_traitees = array();
30
 
32
 
31
//+------------------------------- PARAMÈTRES ---------------------------------------------------------------+
33
//+------------------------------- PARAMÈTRES ---------------------------------------------------------------+
32
 
34
 
33
	public function traiterParametres() {
35
	public function traiterParametres() {
34
		$this->definirParametresParDefaut();
36
		$this->definirParametresParDefaut();
35
		$this->verifierParametres();
37
		$this->verifierParametres();
36
 
38
 
37
		if (isset($this->parametres) && count($this->parametres) > 0) {
39
		if (isset($this->parametres) && count($this->parametres) > 0) {
38
			foreach ($this->parametres as $param => $val) {
40
			foreach ($this->parametres as $param => $val) {
39
				switch ($param) {
41
				switch ($param) {
40
					case 'ns.structure' :
42
					case 'ns.structure' :
41
						$this->remplirTableCompositionNom($val);
43
						$this->remplirTableCompositionNom($val);
-
 
44
						if (in_array($val,$this->sans_nom_sci)){
-
 
45
							$this->requete_champ = implode(', ',$this->compo_nom);
-
 
46
						}else {						
42
						$this->requete_champ .= ' ,'.implode(', ',$this->compo_nom);
47
							$this->requete_champ .= ' ,'.implode(', ',$this->compo_nom);
-
 
48
						}
43
						break;
49
						break;
44
					case 'navigation.depart' :
50
					case 'navigation.depart' :
45
							$this->limite_requete['depart'] = $val;
51
							$this->limite_requete['depart'] = $val;
46
						break;
52
						break;
47
					case 'navigation.limite' :
53
					case 'navigation.limite' :
48
							$this->limite_requete['limite'] = $val;
54
							$this->limite_requete['limite'] = $val;
49
						break;
55
						break;
50
				}
56
				}
51
			}
57
			}
52
			$this->traiterParametresSpecifiques();
58
			$this->traiterParametresSpecifiques();
53
		}
59
		}
54
	}
60
	}
55
 
61
 
56
	protected function definirParametresParDefaut() {
62
	protected function definirParametresParDefaut() {
57
		if (empty($this->parametres['recherche'])) {
63
		if (empty($this->parametres['recherche'])) {
58
			$this->parametres['recherche'] = 'stricte';
64
			$this->parametres['recherche'] = 'stricte';
59
		}
65
		}
60
		if (empty($this->parametres['ns.format'])) {
66
		if (empty($this->parametres['ns.format'])) {
61
			$this->parametres['ns.format'] =  'txt';
67
			$this->parametres['ns.format'] =  'txt';
62
		}
68
		}
63
		if (empty($this->parametres['retour.format'])) {
69
		if (empty($this->parametres['retour.format'])) {
64
			$this->parametres['retour.format'] = 'max';
70
			$this->parametres['retour.format'] = 'max';
65
		}
71
		}
66
		if (empty($this->parametres['ns.structure'])) {
72
		if (empty($this->parametres['ns.structure']) &&
-
 
73
			$this->parametres['retour.format'] != 'oss') {
67
			$this->parametres['ns.structure'] = 'au,an,bib';
74
			$this->parametres['ns.structure'] = 'au,an,bib';
68
		}
75
		}
69
	}
76
	}
-
 
77
	
70
 
78
	
71
	public function verifierParametres() {
79
	public function verifierParametres() {
72
		$this->verifierParametresAPI();
80
		$this->verifierParametresAPI();
73
 
81
 
74
		$this->verifierParametre('recherche', 'stricte|floue|etendue');
82
		$this->verifierParametre('recherche', 'stricte|floue|etendue');
75
		$this->verifierParametre('ns.format', 'htm|txt');
83
		$this->verifierParametre('ns.format', 'htm|txt');
76
		$this->verifierParametre('retour.format', 'min|max|oss|perso');
84
		$this->verifierParametre('retour.format', 'min|max|oss|perso');
77
		$this->verifierParametreAvecValeurMultipe('ns.structure', 'an|au|bib|ad');
85
		$this->verifierParametreAvecValeurMultipe('ns.structure', 'an|au|bib|ad|gen|sp|ssp|fam|au_ss|bib_ss');
78
 
86
 
79
		if (count($this->erreursParametres) > 0) {
87
		if (count($this->erreursParametres) > 0) {
80
			$m = 'Erreur dans votre requête : '.implode('<br/>', $this->erreursParametres);
88
			$m = 'Erreur dans votre requête : '.implode('<br/>', $this->erreursParametres);
81
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $m);
89
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $m);
82
		}
90
		}
83
	}
91
	}
84
 
92
 
85
	public function verifierParametresAPI() {
93
	public function verifierParametresAPI() {
86
		$parametresApi = $this->recupererTableauConfig('parametresAPI');
94
		$parametresApi = $this->recupererTableauConfig('parametresAPI');
87
		while (!is_null($parametre = key($this->parametres))) {
95
		while (!is_null($parametre = key($this->parametres))) {
88
			if (!in_array($parametre, $parametresApi)) {
96
			if (!in_array($parametre, $parametresApi)) {
89
				$this->erreursParametres[] = "Le paramètre '$parametre' n'est pas pris en compte par cette version de l'API.";
97
				$this->erreursParametres[] = "Le paramètre '$parametre' n'est pas pris en compte par cette version de l'API.";
90
			}
98
			}
91
			next($this->parametres);
99
			next($this->parametres);
92
		}
100
		}
93
	}
101
	}
94
 
102
 
95
	public function verifierParametre($parametre, $valeursPermises) {
103
	public function verifierParametre($parametre, $valeursPermises) {
96
		if (isset($this->parametres[$parametre]) && !empty($this->parametres[$parametre])) {
104
		if (isset($this->parametres[$parametre]) && !empty($this->parametres[$parametre])) {
97
			$valeur = $this->parametres[$parametre];
105
			$valeur = $this->parametres[$parametre];
98
			$this->verifierValeursPermises($parametre, $valeur, $valeursPermises);
106
			$this->verifierValeursPermises($parametre, $valeur, $valeursPermises);
99
		}
107
		}
100
	}
108
	}
101
 
109
 
102
	public function verifierParametreAvecValeurMultipe($parametre, $valeursPermises) {
110
	public function verifierParametreAvecValeurMultipe($parametre, $valeursPermises) {
103
		if (isset($this->parametres[$parametre]) && !empty($this->parametres[$parametre])) {
111
		if (isset($this->parametres[$parametre]) && !empty($this->parametres[$parametre])) {
104
			$valeursConcatenees = $this->parametres[$parametre];
112
			$valeursConcatenees = $this->parametres[$parametre];
105
			$valeurs = explode(',', $valeursConcatenees);
113
			$valeurs = explode(',', $valeursConcatenees);
106
			foreach ($valeurs as $valeur) {
114
			foreach ($valeurs as $valeur) {
107
				$this->verifierValeursPermises($parametre, $valeur, $valeursPermises);
115
				$this->verifierValeursPermises($parametre, $valeur, $valeursPermises);
108
			}
116
			}
109
		}
117
		}
110
	}
118
	}
111
 
119
 
112
	private function verifierValeursPermises($parametre, $valeur, $valeursPermises) {
120
	private function verifierValeursPermises($parametre, $valeur, $valeursPermises) {
113
		if (!in_array($valeur, explode('|', $valeursPermises))) {
121
		if (!in_array($valeur, explode('|', $valeursPermises))) {
114
			$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $valeursPermises";
122
			$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $valeursPermises";
115
		}
123
		}
116
	}
124
	}
117
 
125
 
118
	public function traiterParametresCommuns() {
126
	public function traiterParametresCommuns() {
119
 
127
 
120
	}
128
	}
121
 
129
 
122
	public function ajouterFiltreMasque($nom_champ, $valeur) {
130
	public function ajouterFiltreMasque($nom_champ, $valeur) {
-
 
131
		$valeur = explode(',',$valeur);
-
 
132
		$conditions = array();
123
		if ($nom_champ == 'annee' || $nom_champ == 'rang') {
133
		if ($nom_champ == 'annee' || $nom_champ == 'rang') {
-
 
134
			foreach ($valeur as $val) {
124
			$this->requete_condition []= "$nom_champ = ".$this->getBdd()->proteger($valeur);
135
				 $conditions[] = "$nom_champ = ".$this->getBdd()->proteger($val);
-
 
136
			}
125
		} else {
137
		} else {
126
			if ($this->parametres['recherche'] == 'etendue') {
138
			if ($this->parametres['recherche'] == 'etendue') {
-
 
139
				foreach ($valeur as $val) {
127
				$valeur = $this->modifierValeur($valeur);
140
					$val = $this->modifierValeur($val);
128
				$this->requete_condition[] = "$nom_champ LIKE ".$this->getBdd()->proteger($valeur);
141
					$conditions[] = "$nom_champ LIKE ".$this->getBdd()->proteger($val);
-
 
142
				}
-
 
143
				
129
			} elseif ($this->parametres['recherche'] == 'floue') {
144
			} elseif ($this->parametres['recherche'] == 'floue') {
-
 
145
				foreach ($valeur as $val) {
130
				$valeur = $this->getBdd()->proteger($valeur);
146
					$val = $this->getBdd()->proteger($val);
131
				$this->requete_condition[] = "( SOUNDEX($nom_champ) = SOUNDEX($valeur))".
147
					$conditions[] = "( SOUNDEX($nom_champ) = SOUNDEX($val))".
132
						" OR ( SOUNDEX(REVERSE($nom_champ)) = SOUNDEX(REVERSE($valeur)))";
148
											" OR ( SOUNDEX(REVERSE($nom_champ)) = SOUNDEX(REVERSE($val)))";
-
 
149
				}
133
			} else {
150
			} else {
-
 
151
				foreach ($valeur as $val) {
134
				$this->requete_condition[] = "$nom_champ LIKE ".$this->getBdd()->proteger($valeur);
152
					$conditions[] = "$nom_champ LIKE ".$this->getBdd()->proteger($val);
-
 
153
				}
135
			}
154
			}
136
		}
155
		}
-
 
156
		$this->requete_condition[]= '('.implode(' OR ', $conditions ).')';
137
		$this->masque[$nom_champ] = "$nom_champ=$valeur";
157
		$this->masque[$nom_champ] = "$nom_champ=$valeur";
138
	}
158
	}
139
 
159
 
140
	private function modifierValeur($valeur) {
160
	private function modifierValeur($valeur) {
141
		$valeur = $this->remplacerCaractereHybrideEtChimere($valeur);
161
		$valeur = $this->remplacerCaractereHybrideEtChimere($valeur);
142
		$valeur = $this->preparerChainePourRechercheEtendue($valeur);
162
		$valeur = $this->preparerChainePourRechercheEtendue($valeur);
143
		return $valeur;
163
		return $valeur;
144
	}
164
	}
145
 
165
 
146
	private function remplacerCaractereHybrideEtChimere($valeur) {
166
	private function remplacerCaractereHybrideEtChimere($valeur) {
147
		$caracteres = array('×', '%D7', '+', '%2B');
167
		$caracteres = array('×', '%D7', '+', '%2B');
148
		$remplacements = array('x ','x ', '+', '+');
168
		$remplacements = array('x ','x ', '+', '+');
149
		$valeur = str_replace($caracteres, $remplacements, $valeur);
169
		$valeur = str_replace($caracteres, $remplacements, $valeur);
150
		return $valeur;
170
		return $valeur;
151
	}
171
	}
152
 
172
 
153
	private function preparerChainePourRechercheEtendue($valeur) {
173
	private function preparerChainePourRechercheEtendue($valeur) {
154
		$valeur = str_replace(' ', '% ', trim($valeur));
174
		$valeur = str_replace(' ', '% ', trim($valeur));
155
		$valeur = $valeur.'%';
175
		$valeur = $valeur.'%';
156
		return $valeur;
176
		return $valeur;
157
	}
177
	}
158
 
178
 
159
	//+-------------------------------Fonctions d'analyse des ressources-------------------------------------+
179
	//+-------------------------------Fonctions d'analyse des ressources-------------------------------------+
160
 
180
 
161
	private function etreRessourceId() {
181
	private function etreRessourceId() {
162
		$ok = false;
182
		$ok = false;
163
		if ($this->estUnIdentifiant() && count($this->ressources) == 1) {
183
		if ($this->estUnIdentifiant() && count($this->ressources) == 1) {
164
			$ok = true;
184
			$ok = true;
165
		}
185
		}
166
		return $ok;
186
		return $ok;
167
	}
187
	}
168
 
188
 
169
	public function traiterRessources() {
189
	public function traiterRessources() {
170
		if (isset($this->ressources) && count($this->ressources) > 0) {
190
		if (isset($this->ressources) && count($this->ressources) > 0) {
171
			if ($this->ressources[0] == 'relations') {
191
			if ($this->ressources[0] == 'relations') {
172
				$this->traiterRessourceRelations();
192
				$this->traiterRessourceRelations();
173
			} elseif ($this->estUnIdentifiant()) { //l'identifiant peut etre de type /#id ou /nt:#id
193
			} elseif ($this->estUnIdentifiant()) { //l'identifiant peut etre de type /#id ou /nt:#id
174
				$this->traiterRessourcesIdentifiant(); // dans le service noms ou taxons
194
				$this->traiterRessourcesIdentifiant(); // dans le service noms ou taxons
175
			} elseif ($this->ressources[0] == 'stats') { //ressource = noms/stats
195
			} elseif ($this->ressources[0] == 'stats') { //ressource = noms/stats
176
				$this->traiterRessourcesStats();
196
				$this->traiterRessourcesStats();
177
			} else {
197
			} else {
178
				$e = 'Erreur dans votre requete </br> Ressources disponibles : <br/>
198
				$e = 'Erreur dans votre requete </br> Ressources disponibles : <br/>
179
					 <li> /'.$this->service.'/#id (id : L\'identifiant du nom rechercher)</li>
199
					 <li> /'.$this->service.'/#id (id : L\'identifiant du nom rechercher)</li>
180
					 <li> /'.$this->service.'/nt:#id (id : Numero du taxon recherche)</li>
200
					 <li> /'.$this->service.'/nt:#id (id : Numero du taxon recherche)</li>
181
					 <li> /'.$this->service.'/stats </li>';
201
					 <li> /'.$this->service.'/stats </li>';
182
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
202
				$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
183
			}
203
			}
184
		}
204
		}
185
	}
205
	}
186
 
206
 
187
	public function traiterRessourcesStats() {
207
	public function traiterRessourcesStats() {
188
		$this->format_reponse = $this->service.'/stats';
208
		$this->format_reponse = $this->service.'/stats';
189
 
209
 
190
		$e = "Erreur dans votre requête </br> Ressources disponibles : $this->service/stats/[annees|rangs|initiales]";
210
		$e = "Erreur dans votre requête </br> Ressources disponibles : $this->service/stats/[annees|rangs|initiales]";
191
		if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
211
		if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
192
			switch ($this->ressources[1]) {
212
			switch ($this->ressources[1]) {
193
				case 'annees' :
213
				case 'annees' :
194
					$this->traiterRessourceStatsAnnees();
214
					$this->traiterRessourceStatsAnnees();
195
					break;
215
					break;
196
				case 'rangs' :
216
				case 'rangs' :
197
					$this->traiterRessourceStatsRangs();
217
					$this->traiterRessourceStatsRangs();
198
					break;
218
					break;
199
				case 'initiales' :
219
				case 'initiales' :
200
					$this->traiterRessourceStatsInitiales();
220
					$this->traiterRessourceStatsInitiales();
201
					break;
221
					break;
202
				default :
222
				default :
203
					$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
223
					$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
204
					break;
224
					break;
205
			}
225
			}
206
		} else {
226
		} else {
207
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
227
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
208
		}
228
		}
209
	}
229
	}
210
 
230
 
211
	/** Vérifie si la première valeur de la table de ressource est un identifiant :
231
	/** Vérifie si la première valeur de la table de ressource est un identifiant :
212
	 * un numerique ou un numéro taxonomique sous la forme nt:xx */
232
	 * un numerique ou un numéro taxonomique sous la forme nt:xx */
213
	public function estUnIdentifiant() {
233
	public function estUnIdentifiant() {
214
		return (is_numeric($this->ressources[0]) || (strrpos($this->ressources[0],'nt:') !== false
234
		return (is_numeric($this->ressources[0]) || (strrpos($this->ressources[0],'nt:') !== false
215
				&& is_numeric(str_replace('nt:','',$this->ressources[0]))));
235
				&& is_numeric(str_replace('nt:','',$this->ressources[0]))));
216
	}
236
	}
217
 
237
 
218
	//+------------------------------------------------------------------------------------------------------+
238
	//+------------------------------------------------------------------------------------------------------+
219
	// Fonction d'analyse des parametres
239
	// Fonction d'analyse des parametres
220
 
240
 
221
	/** Permet de remplir le tableau compo_nom. Il comprendra en fct du paramètre ns.structure les éléments à rajouter
241
	/** Permet de remplir le tableau compo_nom. Il comprendra en fct du paramètre ns.structure les éléments à rajouter
222
	 * au nom_sci (annee, auteur, biblio ou addendum). */
242
	 * au nom_sci (annee, auteur, biblio ou addendum). */
223
	public function remplirTableCompositionNom($valeur) {
243
	public function remplirTableCompositionNom($valeur) {
224
		$structure_nom = explode(',', $valeur);
244
		$structure_nom = explode(',', $valeur);
225
		foreach ($structure_nom as $structure) {
245
		foreach ($structure_nom as $structure) {
-
 
246
			//avec str_replace() 'sp' est inclu dans 'ssp', et la conversion pour 'ssp' est mauvaise
-
 
247
			$this->compo_nom[$structure] = 
226
			$this->compo_nom[$structure] = str_replace(array('an', 'au', 'bib', 'ad'),
248
				preg_replace(array('/^an$/', '/^au$/', '/^bib$/', '/^ad$/',
-
 
249
				 '/^sp$/', '/^gen$/', '/^ssp$/','/^fam$/','/^au_ss$/','/^bib_ss$/'),
227
				array('annee', 'auteur', 'biblio_origine', 'nom_addendum'), $structure);
250
				array('annee', 'auteur', 'biblio_origine', 'nom_addendum', 
-
 
251
				'epithete_sp', 'genre', 'epithete_infra_sp','famille','auteur', 'biblio_origine'), 
-
 
252
				$structure);
228
		}
253
		} 
229
	}
254
	}
230
 
255
 
231
	public function mettreAuFormat() {
256
	public function mettreAuFormat() {
232
		if ($this->parametres['ns.format'] == 'htm') {
257
		if ($this->parametres['ns.format'] == 'htm') {
233
			if (strrpos($this->requete_champ, 'nom_sci_html as nom_sci') === false) {
258
			if (strrpos($this->requete_champ, 'nom_sci_html as nom_sci') === false) {
234
				$this->requete_champ = str_replace('nom_sci', 'nom_sci_html as nom_sci', $this->requete_champ);
259
				$this->requete_champ = str_replace('nom_sci', 'nom_sci_html as nom_sci', $this->requete_champ);
235
			}
260
			}
236
		}
261
		}
237
	}
262
	}
238
 
263
 
239
	//+------------------------------------------------------------------------------------------------------+
264
	//+------------------------------------------------------------------------------------------------------+
240
	// Fonctions de formatage
265
	// Fonctions de formatage
241
 
266
 
242
	/** Fonction permettant de creer la table dont le nom est passé en paramètre (champs_api, champs_bdtfx,
267
	/** Fonction permettant de creer la table dont le nom est passé en paramètre (champs_api, champs_bdtfx,
243
	 * correspondance_champs...). Les données de chaque table sont présentes dans le fichier de configuration config.ini
268
	 * correspondance_champs...). Les données de chaque table sont présentes dans le fichier de configuration config.ini
244
	 * @param String $table : Peut contenir plusieurs nom de table dont on souhaite récupérer les données : table,table,table. */
269
	 * @param String $table : Peut contenir plusieurs nom de table dont on souhaite récupérer les données : table,table,table. */
245
	public function recupererTableSignification($table) {
270
	public function recupererTableSignification($table) {
246
		$tables = explode(',', $table);
271
		$tables = explode(',', $table);
247
		foreach ($tables as $tab) {
272
		foreach ($tables as $tab) {
248
			if ($tab == 'champs_comp') {
273
			if ($tab == 'champs_comp') {
249
				$champ_bdnff_api = array_keys($this->champs_api); //on recupère le nom des champ ds la bdd
274
				$champ_bdnff_api = array_keys($this->champs_api); //on recupère le nom des champ ds la bdd
250
				$this->champs_comp = array_diff($this->champs_table, $champ_bdnff_api);
275
				$this->champs_comp = array_diff($this->champs_table, $champ_bdnff_api);
251
			} elseif ($tab == 'champs_api') {
276
			} elseif ($tab == 'champs_api') {
252
				foreach ($this->correspondance_champs as $key => $val) {
277
				foreach ($this->correspondance_champs as $key => $val) {
253
					preg_match('/(hybride[.]parent_0[12](?:[.]notes)?|nom_sci[.][^.]+|[^.]+)(?:[.](id|code))?/', $val, $match);
278
					preg_match('/(hybride[.]parent_0[12](?:[.]notes)?|nom_sci[.][^.]+|[^.]+)(?:[.](id|code))?/', $val, $match);
254
					$val = $match[1];
279
					$val = $match[1];
255
					$this->champs_api[$key] = $val;
280
					$this->champs_api[$key] = $val;
256
				}
281
				}
257
			} else {
282
			} else {
258
				$this->$tab = $this->recupererTableauConfig($tab);
283
				$this->$tab = $this->recupererTableauConfig($tab);
259
			}
284
			}
260
		}
285
		}
261
	}
286
	}
262
 
287
 
263
	public function formaterEnOss($resultat) {
288
	public function formaterEnOss($resultat) {
264
		$table_nom = array();
289
		$table_nom = array();
265
		$oss = '';
290
		$oss = '';
266
		foreach ($resultat as $tab) {
291
		foreach ($resultat as $tab) {
267
			if (isset($tab['nom_sci']) ) {
292
			if (isset($tab['nom_sci']) ) {
268
				if (!in_array($tab['nom_sci'], $table_nom)) {
293
				if (!in_array($tab['nom_sci'], $table_nom)) {
269
					$table_nom[] = $tab['nom_sci'];
294
					$table_nom[] = $tab['nom_sci'];
270
					$oss [] = $tab['nom_sci'].$this->ajouterCompositionNom($tab);
295
					$oss[] = $tab['nom_sci'].' '.$this->ajouterCompositionNom($tab);
-
 
296
				}
-
 
297
			}else {
-
 
298
				$res = $this->ajouterCompositionNom($tab);
-
 
299
				if($res) {
-
 
300
					$oss[] = $res;
271
				}
301
				}
272
			}
302
			}
-
 
303
			
273
		}
304
		}
-
 
305
	
274
		if (isset($this->masque)) $masque = implode('&', $this->masque);
306
		if (isset($this->masque)) $masque = implode('&', $this->masque);
275
		else $masque = 'Pas de masque';
307
		else $masque = 'Pas de masque';
276
		$table_retour_oss = array($masque, $oss);
308
		$table_retour_oss = array($masque, $oss);
277
		return $table_retour_oss;
309
		return $table_retour_oss;
278
	}
310
	}
279
 
311
 
280
	public function afficherEnteteResultat($url_service) {
312
	public function afficherEnteteResultat($url_service) {
281
		$this->table_retour['depart'] = $this->limite_requete['depart'];
313
		$this->table_retour['depart'] = $this->limite_requete['depart'];
282
		$this->table_retour['limite'] = $this->limite_requete['limite'];
314
		$this->table_retour['limite'] = $this->limite_requete['limite'];
283
		$this->table_retour['total']  = $this->total_resultat;
315
		$this->table_retour['total']  = $this->total_resultat;
284
		$url = $this->formulerUrl($this->total_resultat, $url_service);
316
		$url = $this->formulerUrl($this->total_resultat, $url_service);
285
		if (isset($url['precedent']) && $url['precedent'] != '') {
317
		if (isset($url['precedent']) && $url['precedent'] != '') {
286
			$this->table_retour['href.precedent'] = $url['precedent'];
318
			$this->table_retour['href.precedent'] = $url['precedent'];
287
		}
319
		}
288
		if (isset($url['suivant']) && $url['suivant']   != '') {
320
		if (isset($url['suivant']) && $url['suivant']   != '') {
289
			$this->table_retour['href.suivant']   = $url['suivant'];
321
			$this->table_retour['href.suivant']   = $url['suivant'];
290
		}
322
		}
291
	}
323
	}
292
 
324
 
293
	public function afficherNomHrefRetenu($tab, $num) {
325
	public function afficherNomHrefRetenu($tab, $num) {
294
		$this->resultat_req = $tab;
326
		$this->resultat_req = $tab;
295
		$this->afficherDonnees('num_nom', $num);
327
		$this->afficherDonnees('num_nom', $num);
296
		if ($this->parametres['retour.format'] == 'min') { // sinon est affiché ds afficherDonnees(num_nom, $val) ci-dessus
328
		if ($this->parametres['retour.format'] == 'min') { // sinon est affiché ds afficherDonnees(num_nom, $val) ci-dessus
297
			 $this->table_retour['nom_sci'] = $tab['nom_sci'];
329
			 $this->table_retour['nom_sci'] = $tab['nom_sci'];
298
			 $this->table_retour['nom_sci_complet'] = $tab['nom_sci'].$this->ajouterCompositionNom($tab);
330
			 $this->table_retour['nom_sci_complet'] = $tab['nom_sci'].$this->ajouterCompositionNom($tab);
299
		}
331
		}
300
		if ($tab['num_nom_retenu'] != '') {
332
		if ($tab['num_nom_retenu'] != '') {
301
			$retenu = ($tab['num_nom_retenu'] == $num) ? 'true' : 'false';
333
			$retenu = ($tab['num_nom_retenu'] == $num) ? 'true' : 'false';
302
		} else {
334
		} else {
303
			$retenu = 'absent';
335
			$retenu = 'absent';
304
		}
336
		}
305
		$this->table_retour['retenu'] = $retenu;
337
		$this->table_retour['retenu'] = $retenu;
306
		unset($this->table_retour['id']);
338
		unset($this->table_retour['id']);
307
	}
339
	}
308
 
340
 
309
 
341
 
310
	//+------------------------------------------------------------------------------------------------------+
342
	//+------------------------------------------------------------------------------------------------------+
311
	// Fonction de formatage pour les services /#id/
343
	// Fonction de formatage pour les services /#id/
312
 
344
 
313
	public function formaterId($resultat) {
345
	public function formaterId($resultat) {
314
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
346
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
315
		$this->resultat_req = $resultat;
347
		$this->resultat_req = $resultat;
316
 
348
 
317
		foreach ($resultat as $cle => $valeur) {
349
		foreach ($resultat as $cle => $valeur) {
318
			if ($valeur != '') {
350
			if ($valeur != '') {
319
				$this->afficherDonnees($cle, $valeur);
351
				$this->afficherDonnees($cle, $valeur);
320
			}
352
			}
321
		}
353
		}
322
		if (isset($this->parametres['retour.champs']) && $this->format_reponse == 'noms/id') {
354
		if (isset($this->parametres['retour.champs']) && $this->format_reponse == 'noms/id') {
323
			$retour = $this->table_retour;
355
			$retour = $this->table_retour;
324
			$this->table_retour = array();
356
			$this->table_retour = array();
325
			$champs = explode(',', $this->parametres['retour.champs']);
357
			$champs = explode(',', $this->parametres['retour.champs']);
326
			$this->ajouterChampsPersonnalises($champs, $retour);
358
			$this->ajouterChampsPersonnalises($champs, $retour);
327
		}
359
		}
328
		unset($this->table_retour['href']);
360
		unset($this->table_retour['href']);
329
		return $this->table_retour;
361
		return $this->table_retour;
330
	}
362
	}
331
 
363
 
332
	public function formaterIdChamp($resultat) {
364
	public function formaterIdChamp($resultat) {
333
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
365
		$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
334
		$reponse_id = $this->formaterId($resultat);
366
		$reponse_id = $this->formaterId($resultat);
335
		$this->table_retour = array();
367
		$this->table_retour = array();
336
		$champs = explode(' ', $this->ressources[1]);
368
		$champs = explode(' ', $this->ressources[1]);
337
		$this->ajouterChampsPersonnalises($champs, $reponse_id);
369
		$this->ajouterChampsPersonnalises($champs, $reponse_id);
338
		return $this->table_retour;
370
		return $this->table_retour;
339
	}
371
	}
340
 
372
 
341
	protected function ajouterChampsPersonnalises($champs, $reponse_id) {
373
	protected function ajouterChampsPersonnalises($champs, $reponse_id) {
342
		$champs_a_libeller = array('nom_retenu', 'rang', 'basionyme', 'hybride', 'hybride.parent_01',
374
		$champs_a_libeller = array('nom_retenu', 'rang', 'basionyme', 'hybride', 'hybride.parent_01',
343
			 'hybride.parent_02', 'presence', 'tax_sup', 'statut_origine', 'statut_culture', 'statut_introduction');
375
			 'hybride.parent_02', 'presence', 'tax_sup', 'statut_origine', 'statut_culture', 'statut_introduction');
344
		if (! is_null($champs) && is_array($champs) && count($champs) > 0) {
376
		if (! is_null($champs) && is_array($champs) && count($champs) > 0) {
345
			foreach ($champs as $champ) {
377
			foreach ($champs as $champ) {
346
				if ($this->verifierValiditeChamp($champ)) {
378
				if ($this->verifierValiditeChamp($champ)) {
347
					if (strrpos($champ, '.*') !== false) {
379
					if (strrpos($champ, '.*') !== false) {
348
						$this->afficherPointEtoile($champ, $reponse_id);
380
						$this->afficherPointEtoile($champ, $reponse_id);
349
					} elseif (in_array($champ, $champs_a_libeller)) {
381
					} elseif (in_array($champ, $champs_a_libeller)) {
350
						$this->table_retour[$champ.'.libelle'] = 
382
						$this->table_retour[$champ.'.libelle'] = 
351
							(isset($reponse_id[$champ.'.libelle'])) ? $reponse_id[$champ.'.libelle'] : null;
383
							(isset($reponse_id[$champ.'.libelle'])) ? $reponse_id[$champ.'.libelle'] : null;
352
					} else {
384
					} else {
353
						$champ = $this->trouverChampBddCorrespondant($champ);
385
						$champ = $this->trouverChampBddCorrespondant($champ);
354
						$this->table_retour[$champ] = (isset($reponse_id[$champ])) ? $reponse_id[$champ] : null;
386
						$this->table_retour[$champ] = (isset($reponse_id[$champ])) ? $reponse_id[$champ] : null;
355
					}
387
					}
356
				}
388
				}
357
			}
389
			}
358
		}
390
		}
359
	}
391
	}
360
 
392
 
361
	public function afficherPointEtoile($champ, $reponse) {
393
	public function afficherPointEtoile($champ, $reponse) {
362
		preg_match('/^([^.]+\.)\*$/', $champ, $match);
394
		preg_match('/^([^.]+\.)\*$/', $champ, $match);
363
		if ($match[1] == 'nom_sci') {
395
		if ($match[1] == 'nom_sci') {
364
			$this->afficherNomSciPointEpithete($this->resultat_req);
396
			$this->afficherNomSciPointEpithete($this->resultat_req);
365
		} else {
397
		} else {
366
			foreach ($reponse as $chp => $valeur) {
398
			foreach ($reponse as $chp => $valeur) {
367
				if (strrpos($chp, $match[1]) !== false) {
399
				if (strrpos($chp, $match[1]) !== false) {
368
					if ($valeur != '') {
400
					if ($valeur != '') {
369
						$this->table_retour[$chp] = $valeur;
401
						$this->table_retour[$chp] = $valeur;
370
					} else {
402
					} else {
371
						$this->table_retour[$chp] = null;
403
						$this->table_retour[$chp] = null;
372
					}
404
					}
373
				}
405
				}
374
			}
406
			}
375
		}
407
		}
376
	}
408
	}
377
 
409
 
378
	public function decomposerNomChamp($champ) {
410
	public function decomposerNomChamp($champ) {
379
		$decomposition = false;
411
		$decomposition = false;
380
		if (preg_match('/^(?:([^.]+\.parent_0[12]|[^.]+))(?:\.(.+))?$/', $champ, $match)) {
412
		if (preg_match('/^(?:([^.]+\.parent_0[12]|[^.]+))(?:\.(.+))?$/', $champ, $match)) {
381
			$radical_champ = $match[1];
413
			$radical_champ = $match[1];
382
			$suffixe = (isset($match[2])) ? $match[2] : "";
414
			$suffixe = (isset($match[2])) ? $match[2] : "";
383
			$decomposition = array($radical_champ, $suffixe);
415
			$decomposition = array($radical_champ, $suffixe);
384
		}
416
		}
385
		return $decomposition;
417
		return $decomposition;
386
	}
418
	}
387
 
419
 
388
	public function verifierValiditeChamp($champ) {
420
	public function verifierValiditeChamp($champ) {
389
		$decomposition = $this->decomposerNomChamp($champ);
421
		$decomposition = $this->decomposerNomChamp($champ);
390
		$validite_ressource = true;
422
		$validite_ressource = true;
391
		if ($decomposition) {
423
		if ($decomposition) {
392
			list($radical, $suffixe) = $decomposition;
424
			list($radical, $suffixe) = $decomposition;
393
			$champs_complementaire = array('nom_retenu_complet', 'basionyme_complet');
425
			$champs_complementaire = array('nom_retenu_complet', 'basionyme_complet');
394
			// on verifie si le nom du champ existe bien
426
			// on verifie si le nom du champ existe bien
395
			if (!$this->estChampApi($radical) && !$this->estChampComplementaire($radical)) {
427
			if (!$this->estChampApi($radical) && !$this->estChampComplementaire($radical)) {
396
				if (!in_array($radical, $champs_complementaire)) {
428
				if (!in_array($radical, $champs_complementaire)) {
397
					$validite_ressource = false;
429
					$validite_ressource = false;
398
					$e = 'Le champ "'.$radical.'" n\'existe pas dans la base. <br/><br/>';
430
					$e = 'Le champ "'.$radical.'" n\'existe pas dans la base. <br/><br/>';
399
					$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
431
					$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
400
				}
432
				}
401
			} elseif ($this->estUnPoint($champ)) {
433
			} elseif ($this->estUnPoint($champ)) {
402
				$validite_ressource = $this->verifierValiditeSuffixe($suffixe, $radical);
434
				$validite_ressource = $this->verifierValiditeSuffixe($suffixe, $radical);
403
			}
435
			}
404
		}
436
		}
405
		return $validite_ressource;
437
		return $validite_ressource;
406
	}
438
	}
407
 
439
 
408
	public function estChampApi($radical_champ) {
440
	public function estChampApi($radical_champ) {
409
		$champ_api_ok = false;
441
		$champ_api_ok = false;
410
		if (in_array($radical_champ, $this->champs_api) || in_array($radical_champ, $this->correspondance_champs)) {
442
		if (in_array($radical_champ, $this->champs_api) || in_array($radical_champ, $this->correspondance_champs)) {
411
			$champ_api_ok = true;
443
			$champ_api_ok = true;
412
		}
444
		}
413
		return $champ_api_ok;
445
		return $champ_api_ok;
414
	}
446
	}
415
 
447
 
416
	public function estChampComplementaire($radical_champ) {
448
	public function estChampComplementaire($radical_champ) {
417
		$champ_complementaire_ok = in_array($radical_champ, $this->champs_comp) ? true : false;
449
		$champ_complementaire_ok = in_array($radical_champ, $this->champs_comp) ? true : false;
418
		return	$champ_complementaire_ok;
450
		return	$champ_complementaire_ok;
419
	}
451
	}
420
 
452
 
421
	public function verifierValiditeSuffixe($suffixe, $radical_champ) {
453
	public function verifierValiditeSuffixe($suffixe, $radical_champ) {
422
		$validite_ressource = true;
454
		$validite_ressource = true;
423
		if ($this->correspondAUnId($radical_champ) || $radical_champ == 'id') {
455
		if ($this->correspondAUnId($radical_champ) || $radical_champ == 'id') {
424
			$this->verificationSuffixesIdentifiant($suffixe, $radical_champ, $validite_ressource);
456
			$this->verificationSuffixesIdentifiant($suffixe, $radical_champ, $validite_ressource);
425
		} elseif ($this->correspondAUnCode($radical_champ)) {
457
		} elseif ($this->correspondAUnCode($radical_champ)) {
426
			$this->verificationSuffixesCodes($suffixe, $radical_champ, $validite_ressource);
458
			$this->verificationSuffixesCodes($suffixe, $radical_champ, $validite_ressource);
427
		} elseif ($radical_champ == 'nom_sci') {
459
		} elseif ($radical_champ == 'nom_sci') {
428
			if ($suffixe != '*') {
460
			if ($suffixe != '*') {
429
				$validite_ressource = false;
461
				$validite_ressource = false;
430
				$m = 'Erreur : Le suffixe demandé n\'existe pas pour le champ "'.$radical_champ.'".<br/>
462
				$m = 'Erreur : Le suffixe demandé n\'existe pas pour le champ "'.$radical_champ.'".<br/>
431
					Les suffixes possibles sont les suivants : <li> * </li>';
463
					Les suffixes possibles sont les suivants : <li> * </li>';
432
				$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $m);
464
				$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $m);
433
			}
465
			}
434
		} else {
466
		} else {
435
			$validite_ressource = false;
467
			$validite_ressource = false;
436
			$m = 'Erreur : Le paramètre "'.$radical_champ.'" ne peut pas présenter de suffixe. <br/><br/>';
468
			$m = 'Erreur : Le paramètre "'.$radical_champ.'" ne peut pas présenter de suffixe. <br/><br/>';
437
			$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $m);
469
			$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $m);
438
		}
470
		}
439
		return $validite_ressource;
471
		return $validite_ressource;
440
	}
472
	}
441
 
473
 
442
	public function verificationSuffixesCodes(&$suffixe, &$radical_champ, &$validite_ressource ) {
474
	public function verificationSuffixesCodes(&$suffixe, &$radical_champ, &$validite_ressource ) {
443
		if (!in_array($suffixe, array('*', 'code', 'href', 'details'))) {
475
		if (!in_array($suffixe, array('*', 'code', 'href', 'details'))) {
444
			$validite_ressource = false;
476
			$validite_ressource = false;
445
			$e = 'Erreur : Le suffixe demandé n\'existe pas pour le champ "'.$radical_champ.'.<br/> Les suffixes '
477
			$e = 'Erreur : Le suffixe demandé n\'existe pas pour le champ "'.$radical_champ.'.<br/> Les suffixes '
446
				.'possibles sont les suivants : <li> .* </li><li> .code </li><li> .href </li><li> .details </li>';
478
				.'possibles sont les suivants : <li> .* </li><li> .code </li><li> .href </li><li> .details </li>';
447
			$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
479
			$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
448
		}
480
		}
449
	}
481
	}
450
 
482
 
451
	public function verificationSuffixesIdentifiant(&$suffixe, &$radical_champ, &$validite_ressource) {
483
	public function verificationSuffixesIdentifiant(&$suffixe, &$radical_champ, &$validite_ressource) {
452
		if ((strrpos($radical_champ, 'parent') !== false && !in_array($suffixe, array('*', 'id', 'href', 'details', 'notes')))
484
		if ((strrpos($radical_champ, 'parent') !== false && !in_array($suffixe, array('*', 'id', 'href', 'details', 'notes')))
453
			|| !in_array($suffixe, array('*', 'id', 'href', 'details')) && strrpos($radical_champ, 'parent') === false) {
485
			|| !in_array($suffixe, array('*', 'id', 'href', 'details')) && strrpos($radical_champ, 'parent') === false) {
454
			$validite_ressource = false;
486
			$validite_ressource = false;
455
			$e = 'Erreur : Le suffixe demandé n\'existe pas pour le champ "'.$radical_champ.'".<br/> Les suffixes '
487
			$e = 'Erreur : Le suffixe demandé n\'existe pas pour le champ "'.$radical_champ.'".<br/> Les suffixes '
456
				.'possibles sont les suivants : <li> .* </li><li> .id </li><li> .href </li><li> .details </li>'
488
				.'possibles sont les suivants : <li> .* </li><li> .id </li><li> .href </li><li> .details </li>'
457
				.'<li> .notes (seulement pour les hybride.parent)';
489
				.'<li> .notes (seulement pour les hybride.parent)';
458
			$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
490
			$this->renvoyerErreur( RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
459
		}
491
		}
460
	}
492
	}
461
 
493
 
462
 
494
 
463
//------------------------------fonction de formatage pour les services /stats/-----------------------------------------
495
//------------------------------fonction de formatage pour les services /stats/-----------------------------------------
464
 
496
 
465
	public function formaterStatsAnnee($resultat) {
497
	public function formaterStatsAnnee($resultat) {
466
		foreach ($resultat as $cle_annee) {
498
		foreach ($resultat as $cle_annee) {
467
			$annee = ($cle_annee['annee'] != '') ? $cle_annee['annee'] : 'ND';
499
			$annee = ($cle_annee['annee'] != '') ? $cle_annee['annee'] : 'ND';
468
			$nb = $cle_annee['nombre'];
500
			$nb = $cle_annee['nombre'];
469
			$retour_stats_annee[$annee] = $nb;
501
			$retour_stats_annee[$annee] = $nb;
470
		}
502
		}
471
		return $retour_stats_annee;
503
		return $retour_stats_annee;
472
	}
504
	}
473
 
505
 
474
	public function formaterStatsRang($resultat) {
506
	public function formaterStatsRang($resultat) {
475
		foreach ($resultat as $rangs) {
507
		foreach ($resultat as $rangs) {
476
			if ($rangs['rang'] != 0) {
508
			if ($rangs['rang'] != 0) {
477
				$rang = $rangs['rang'];
509
				$rang = $rangs['rang'];
478
				if ($this->parametres['retour.format'] == 'max') {
510
				if ($this->parametres['retour.format'] == 'max') {
479
					$retour_rang[$rang]['rang'] = $this->ajouterSignificationCode('rang',$rang);
511
					$retour_rang[$rang]['rang'] = $this->ajouterSignificationCode('rang',$rang);
480
				}
512
				}
481
				$nombre = $rangs['nombre'];
513
				$nombre = $rangs['nombre'];
482
				$retour_rang[$rang]['nombre'] = $nombre;
514
				$retour_rang[$rang]['nombre'] = $nombre;
483
			}
515
			}
484
		}
516
		}
485
		return $retour_rang;
517
		return $retour_rang;
486
	}
518
	}
487
 
519
 
488
	public function formaterStatsInitiales($resultat) {
520
	public function formaterStatsInitiales($resultat) {
489
		$rang = null;
521
		$rang = null;
490
		$table_rang = array();
522
		$table_rang = array();
491
		foreach ($resultat as $tuple) {
523
		foreach ($resultat as $tuple) {
492
			if ($tuple['rang'] != 0) {
524
			if ($tuple['rang'] != 0) {
493
				$this->memoriserRang($table_rang, $tuple, $rang);
525
				$this->memoriserRang($table_rang, $tuple, $rang);
494
				if ($tuple['lettre'] == 'x ') {
526
				if ($tuple['lettre'] == 'x ') {
495
					$this->ajouterHybrideChimere('hybride', $rang, $tuple);
527
					$this->ajouterHybrideChimere('hybride', $rang, $tuple);
496
				} elseif ($tuple['lettre'] == '+ ') {
528
				} elseif ($tuple['lettre'] == '+ ') {
497
					$this->ajouterHybrideChimere('chimere', $rang, $tuple);
529
					$this->ajouterHybrideChimere('chimere', $rang, $tuple);
498
				} else {
530
				} else {
499
					$l = substr($tuple['lettre'], 0, 1);
531
					$l = substr($tuple['lettre'], 0, 1);
500
					if (isset($this->table_retour[$rang][$l])) {
532
					if (isset($this->table_retour[$rang][$l])) {
501
						$this->table_retour[$rang][substr($tuple['lettre'], 0, 1)] += floatval($tuple['nb']);
533
						$this->table_retour[$rang][substr($tuple['lettre'], 0, 1)] += floatval($tuple['nb']);
502
					} else {
534
					} else {
503
						$this->table_retour[$rang][substr($tuple['lettre'], 0, 1)] = floatval($tuple['nb']);
535
						$this->table_retour[$rang][substr($tuple['lettre'], 0, 1)] = floatval($tuple['nb']);
504
					}
536
					}
505
				}
537
				}
506
			}
538
			}
507
		}
539
		}
508
		return $this->table_retour;
540
		return $this->table_retour;
509
	}
541
	}
510
 
542
 
511
	public function memoriserRang(&$table_rang, $tuple, &$rang) {
543
	public function memoriserRang(&$table_rang, $tuple, &$rang) {
512
		if (is_array($table_rang)) {
544
		if (is_array($table_rang)) {
513
			if (!in_array($tuple['rang'], $table_rang)) {
545
			if (!in_array($tuple['rang'], $table_rang)) {
514
				$rang = $tuple['rang'];
546
				$rang = $tuple['rang'];
515
				$table_rang[] = $rang;
547
				$table_rang[] = $rang;
516
				if ($this->parametres['retour.format'] == 'max') {
548
				if ($this->parametres['retour.format'] == 'max') {
517
					$rang = $this->ajouterSignificationCode('rang', $rang);
549
					$rang = $this->ajouterSignificationCode('rang', $rang);
518
				}
550
				}
519
			}
551
			}
520
		}
552
		}
521
	}
553
	}
522
 
554
 
523
	public function ajouterHybrideChimere($groupe, &$rang, &$tuple) {
555
	public function ajouterHybrideChimere($groupe, &$rang, &$tuple) {
524
		if (isset($this->table_retour[$rang][str_replace('hybride', 'hyb', $groupe)])) {
556
		if (isset($this->table_retour[$rang][str_replace('hybride', 'hyb', $groupe)])) {
525
			$this->table_retour[$rang][$groupe] += floatval($tuple['nb']);
557
			$this->table_retour[$rang][$groupe] += floatval($tuple['nb']);
526
		} else {
558
		} else {
527
			$this->table_retour[$rang][$groupe] = floatval($tuple['nb']);
559
			$this->table_retour[$rang][$groupe] = floatval($tuple['nb']);
528
		}
560
		}
529
	}
561
	}
530
 
562
 
531
	//-----------------------------Fonctions d'affichage utiliser dans les fonctions de formatage---------------------------
563
	//-----------------------------Fonctions d'affichage utiliser dans les fonctions de formatage---------------------------
532
 
564
 
533
	public function afficherDonnees($champApi, $valeur) {
565
	public function afficherDonnees($champApi, $valeur) {
534
		$champBdd = $this->trouverChampBddCorrespondant($champApi);
566
		$champBdd = $this->trouverChampBddCorrespondant($champApi);
535
		if ($this->parametres['retour.format'] == 'min') {
567
		if ($this->parametres['retour.format'] == 'min') {
536
			if ($champApi == 'nom_sci') {
568
			if ($champApi == 'nom_sci') {
537
				$valeur = $valeur.$this->ajouterCompositionNom($this->resultat_req);
569
				$valeur = $valeur.' '.$this->ajouterCompositionNom($this->resultat_req);
538
			}
570
			}
539
			if ($champApi == 'nom_sci_html') {
571
			if ($champApi == 'nom_sci_html') {
540
				$valeur = $valeur.$this->ajouterCompositionNom($this->resultat_req, 'htm');
572
				$valeur = $valeur.' '.$this->ajouterCompositionNom($this->resultat_req, 'htm');
541
			}
573
			}
542
			$this->table_retour[$champBdd] = $valeur;
574
			$this->table_retour[$champBdd] = $valeur;
543
		} else {
575
		} else {
544
			$this->afficherToutesLesInfos($champBdd, $valeur);
576
			$this->afficherToutesLesInfos($champBdd, $valeur);
545
		}
577
		}
546
	}
578
	}
547
 
579
 
548
	public function trouverChampBddCorrespondant($champApi) {
580
	public function trouverChampBddCorrespondant($champApi) {
549
		if (array_key_exists($champApi, $this->champs_api)) {
581
		if (array_key_exists($champApi, $this->champs_api)) {
550
			$champBdd = $this->correspondance_champs[$champApi];
582
			$champBdd = $this->correspondance_champs[$champApi];
551
		} else {
583
		} else {
552
			$champBdd = $champApi;
584
			$champBdd = $champApi;
553
		}
585
		}
554
		return $champBdd;
586
		return $champBdd;
555
	}
587
	}
556
 
588
 
557
	public function afficherToutesLesInfos($nom_champ_api, $valeur) {
589
	public function afficherToutesLesInfos($nom_champ_api, $valeur) {
558
		if ($this->presentePlusieursId($nom_champ_api, $valeur)) {
590
		if ($this->presentePlusieursId($nom_champ_api, $valeur)) {
559
			preg_match('/^([^.]+\.parent_0[12]|[^.]+)(?:\.id)?$/', $nom_champ_api, $match);
591
			preg_match('/^([^.]+\.parent_0[12]|[^.]+)(?:\.id)?$/', $nom_champ_api, $match);
560
			$this->afficherInfosPrecises($match[1], 'details', $valeur);
592
			$this->afficherInfosPrecises($match[1], 'details', $valeur);
561
			$this->table_retour[$nom_champ_api] = $valeur;
593
			$this->table_retour[$nom_champ_api] = $valeur;
562
 
594
 
563
		} elseif (strrpos($nom_champ_api, 'parent') !== false && strrpos($nom_champ_api, 'notes') !== false) {
595
		} elseif (strrpos($nom_champ_api, 'parent') !== false && strrpos($nom_champ_api, 'notes') !== false) {
564
			$this->table_retour[$nom_champ_api] = $valeur;
596
			$this->table_retour[$nom_champ_api] = $valeur;
565
 
597
 
566
		} elseif (($this->correspondAUnId($nom_champ_api) || $nom_champ_api == 'id' && $valeur != '0')) {
598
		} elseif (($this->correspondAUnId($nom_champ_api) || $nom_champ_api == 'id' && $valeur != '0')) {
567
			preg_match('/^([^.]+\.parent_0[12]|[^.]+)(?:\.id)?$/', $nom_champ_api, $match);
599
			preg_match('/^([^.]+\.parent_0[12]|[^.]+)(?:\.id)?$/', $nom_champ_api, $match);
568
			$this->afficherInfosPrecises($match[1], 'id,signification,href', $valeur);
600
			$this->afficherInfosPrecises($match[1], 'id,signification,href', $valeur);
569
 
601
 
570
		} elseif ($this->correspondAUnCode($nom_champ_api)) {
602
		} elseif ($this->correspondAUnCode($nom_champ_api)) {
571
			preg_match('/^([^.]+)(?:\.code)?$/', $nom_champ_api, $match);
603
			preg_match('/^([^.]+)(?:\.code)?$/', $nom_champ_api, $match);
572
			$this->afficherInfosPrecises($match[1], 'code,signification,href', $valeur);
604
			$this->afficherInfosPrecises($match[1], 'code,signification,href', $valeur);
573
 
605
 
574
		} elseif ($nom_champ_api == 'nom_sci_html') {
606
		} elseif ($nom_champ_api == 'nom_sci_html') {
575
			$this->table_retour['nom_sci_html'] = $valeur;
607
			$this->table_retour['nom_sci_html'] = $valeur;
576
			$this->table_retour['nom_sci_html_complet'] = $valeur.$this->ajouterCompositionNom($this->resultat_req, 'htm');
608
			$this->table_retour['nom_sci_html_complet'] = $valeur.' '.$this->ajouterCompositionNom($this->resultat_req, 'htm');
577
		}elseif ($nom_champ_api != 'nom_sci') {
609
		}elseif ($nom_champ_api != 'nom_sci') {
578
			$this->table_retour[$nom_champ_api] = $valeur;
610
			$this->table_retour[$nom_champ_api] = $valeur;
579
		}
611
		}
580
	}
612
	}
581
 
613
 
582
	public function presentePlusieursId($ressource, $valeur = null) {
614
	public function presentePlusieursId($ressource, $valeur = null) {
583
		if ($valeur) {
615
		if ($valeur) {
584
			$presente = strrpos($ressource, 'proparte') !== false && strrpos($valeur, ',') !== false;
616
			$presente = strrpos($ressource, 'proparte') !== false && strrpos($valeur, ',') !== false;
585
		} else { //pour la vérification du champ, on ignore alors la valeur de la ressource
617
		} else { //pour la vérification du champ, on ignore alors la valeur de la ressource
586
			$presente = strrpos($ressource, 'proparte') !== false;
618
			$presente = strrpos($ressource, 'proparte') !== false;
587
		}
619
		}
588
		return $presente;
620
		return $presente;
589
	}
621
	}
590
 
622
 
591
	public function afficherInfosPrecises($champ, $suffixe, $valeur) {
623
	public function afficherInfosPrecises($champ, $suffixe, $valeur) {
592
		$suffixes = explode(',', $suffixe);
624
		$suffixes = explode(',', $suffixe);
593
		//on initialise au service appelé. Sera potentiellement modifié dans la fonction afficherSignification()
625
		//on initialise au service appelé. Sera potentiellement modifié dans la fonction afficherSignification()
594
		$this->service_href = $this->service;
626
		$this->service_href = $this->service;
595
		foreach ($suffixes  as $suffixe) {
627
		foreach ($suffixes  as $suffixe) {
596
			switch ($suffixe) {
628
			switch ($suffixe) {
597
				case 'id' 			 :
629
				case 'id' 			 :
598
					$this->table_retour[str_replace('id.id', 'id', $champ.'.id')] = $valeur;
630
					$this->table_retour[str_replace('id.id', 'id', $champ.'.id')] = $valeur;
599
					break;
631
					break;
600
				case 'details' 		 :
632
				case 'details' 		 :
601
					$this->afficherTableDetails($champ, $valeur);
633
					$this->afficherTableDetails($champ, $valeur);
602
					break;
634
					break;
603
				case 'signification' :
635
				case 'signification' :
604
					$this->afficherSignification($champ, $valeur);
636
					$this->afficherSignification($champ, $valeur);
605
					break;
637
					break;
606
				case 'href' 		 :
638
				case 'href' 		 :
607
					$url = $this->creerUrl($champ, $valeur);
639
					$url = $this->creerUrl($champ, $valeur);
608
					$this->table_retour[str_replace('id.href', 'href', $champ.'.href')] = $url;
640
					$this->table_retour[str_replace('id.href', 'href', $champ.'.href')] = $url;
609
					break;
641
					break;
610
				case 'code' 		 :
642
				case 'code' 		 :
611
					$this->table_retour[$champ.'.code'] = $this->obtenirCode($champ, $valeur);
643
					$this->table_retour[$champ.'.code'] = $this->obtenirCode($champ, $valeur);
612
					break;
644
					break;
613
				case 'notes' 		 :
645
				case 'notes' 		 :
614
					$this->table_retour[$champ.'.notes'] = $this->resultat_req[str_replace('.', '_', $champ).'_notes'];
646
					$this->table_retour[$champ.'.notes'] = $this->resultat_req[str_replace('.', '_', $champ).'_notes'];
615
					break;
647
					break;
616
				default : break;
648
				default : break;
617
			}
649
			}
618
		}
650
		}
619
	}
651
	}
620
 
652
 
621
	public function afficherTableDetails($nom_champ_api, $valeur) {
653
	public function afficherTableDetails($nom_champ_api, $valeur) {
622
		$tab_id = explode(',', $valeur);
654
		$tab_id = explode(',', $valeur);
623
		$tab_res = $this->table_retour;
655
		$tab_res = $this->table_retour;
624
		$this->table_retour = array();
656
		$this->table_retour = array();
625
		foreach ($tab_id as $id) {
657
		foreach ($tab_id as $id) {
626
			$this->afficherInfosPrecises($nom_champ_api, 'id,signification,href', $id);
658
			$this->afficherInfosPrecises($nom_champ_api, 'id,signification,href', $id);
627
			$tab_res[$nom_champ_api.'.details'][] = $this->table_retour;
659
			$tab_res[$nom_champ_api.'.details'][] = $this->table_retour;
628
			$this->table_retour = array();
660
			$this->table_retour = array();
629
		}
661
		}
630
		$this->table_retour = $tab_res;
662
		$this->table_retour = $tab_res;
631
	}
663
	}
632
 
664
 
633
	private function obtenirCode($champ, $valeur) {
665
	private function obtenirCode($champ, $valeur) {
634
		$code = $this->transformerChampEnCode($champ);
666
		$code = $this->transformerChampEnCode($champ);
635
		return "bdnt.$code:$valeur";
667
		return "bdnt.$code:$valeur";
636
	}
668
	}
637
 
669
 
638
	private function transformerChampEnCode($champ) {
670
	private function transformerChampEnCode($champ) {
639
		if (is_null($this->relationsChampsCodesOntologie)) {
671
		if (is_null($this->relationsChampsCodesOntologie)) {
640
			$this->relationsChampsCodesOntologie = Outils::recupererTableauConfig('ChampsCodesOntologie');
672
			$this->relationsChampsCodesOntologie = Outils::recupererTableauConfig('ChampsCodesOntologie');
641
		}
673
		}
642
 
674
 
643
		$code = $champ;
675
		$code = $champ;
644
		if (array_key_exists($champ, $this->relationsChampsCodesOntologie)) {
676
		if (array_key_exists($champ, $this->relationsChampsCodesOntologie)) {
645
			$code = $this->relationsChampsCodesOntologie[$champ];
677
			$code = $this->relationsChampsCodesOntologie[$champ];
646
		}
678
		}
647
		return $code;
679
		return $code;
648
	}
680
	}
649
 
681
 
650
	public function creerUrl($champ, $valeur) {
682
	public function creerUrl($champ, $valeur) {
651
		if ($this->correspondAUnId($champ) || $champ == 'id') {
683
		if ($this->correspondAUnId($champ) || $champ == 'id') {
652
			$service = $this->service_href;
684
			$service = $this->service_href;
653
			$url = $this->ajouterHref($service, $valeur);
685
			$url = $this->ajouterHref($service, $valeur);
654
		} else {
686
		} else {
655
			$code = $this->transformerChampEnCode($champ);
687
			$code = $this->transformerChampEnCode($champ);
656
			$url = $this->ajouterHrefAutreProjet('ontologies', "$code:", $valeur, 'bdnt');
688
			$url = $this->ajouterHrefAutreProjet('ontologies', "$code:", $valeur, 'bdnt');
657
		}
689
		}
658
		return $url;
690
		return $url;
659
	}
691
	}
660
 
692
 
661
	public function afficherSignification($champ, $valeur) {
693
	public function afficherSignification($champ, $valeur) {
662
		if ($champ == 'id' && isset($this->resultat_req['nom_sci']) && $this->resultat_req['num_nom'] == $valeur) {
694
		if ($champ == 'id' && isset($this->resultat_req['nom_sci']) && $this->resultat_req['num_nom'] == $valeur) {
663
			//si le nom_sci du num_nom que l'on veut afficher est déjà dans la table de résultat :
695
			//si le nom_sci du num_nom que l'on veut afficher est déjà dans la table de résultat :
664
			$this->table_retour['nom_sci'] = $this->resultat_req['nom_sci'];
696
			$this->table_retour['nom_sci'] = $this->resultat_req['nom_sci'];
665
			$this->table_retour['nom_sci_complet'] = $this->resultat_req['nom_sci'].
697
			$this->table_retour['nom_sci_complet'] = $this->resultat_req['nom_sci'].
666
				$this->ajouterCompositionNom($this->resultat_req);
698
				$this->ajouterCompositionNom($this->resultat_req);
667
		} elseif ($this->correspondAUnId($champ) || $champ == 'id') {
699
		} elseif ($this->correspondAUnId($champ) || $champ == 'id') {
668
			$nom = $this->recupererNomSci($valeur);
700
			$nom = $this->recupererNomSci($valeur);
669
			if ($nom != array()) {
701
			if ($nom != array()) {
670
				$this->table_retour[$champ.'.libelle'] = $nom['nom_sci'];
702
				$this->table_retour[$champ.'.libelle'] = $nom['nom_sci'];
671
				$this->table_retour[$champ.'_html'] = $nom['nom_sci_html'];
703
				$this->table_retour[$champ.'_html'] = $nom['nom_sci_html'];
672
				$this->table_retour[$champ.'_complet'] = $nom['nom_sci_complet'];
704
				$this->table_retour[$champ.'_complet'] = $nom['nom_sci_complet'];
673
				$this->table_retour[$champ.'_html_complet'] = $nom['nom_sci_complet_html'];
705
				$this->table_retour[$champ.'_html_complet'] = $nom['nom_sci_complet_html'];
674
				$this->service_href = $nom['service'];
706
				$this->service_href = $nom['service'];
675
			}
707
			}
676
		} elseif ($this->correspondAUnCode($champ)) {
708
		} elseif ($this->correspondAUnCode($champ)) {
677
			$this->table_retour[$champ.'.libelle'] = $this->ajouterSignificationCode($champ, $valeur);
709
			$this->table_retour[$champ.'.libelle'] = $this->ajouterSignificationCode($champ, $valeur);
678
		}
710
		}
679
	}
711
	}
680
 
712
 
681
	/** Permet d'afficher les élements nomenclatural du nom_sci lors de l'appel dans le service noms/id/champ du champ^nom_sci.*/
713
	/** Permet d'afficher les élements nomenclatural du nom_sci lors de l'appel dans le service noms/id/champ du champ^nom_sci.*/
682
	public function afficherNomSciPointEpithete($resultat) {
714
	public function afficherNomSciPointEpithete($resultat) {
683
		$tab_nom_sci   = array('nom_supra_generique', 'genre', 'epithete_infra_generique', 'epithete_sp',
715
		$tab_nom_sci   = array('nom_supra_generique', 'genre', 'epithete_infra_generique', 'epithete_sp',
684
		'type_epithete', 'epithete_infra_sp', 'cultivar_groupe', 'cultivar', 'nom_commercial');
716
		'type_epithete', 'epithete_infra_sp', 'cultivar_groupe', 'cultivar', 'nom_commercial');
685
		foreach ($tab_nom_sci as $compo_nom) {
717
		foreach ($tab_nom_sci as $compo_nom) {
686
			if (isset($resultat[$compo_nom]) && !empty($resultat[$compo_nom])) {
718
			if (isset($resultat[$compo_nom]) && !empty($resultat[$compo_nom])) {
687
				$this->table_retour['nom_sci.'.$compo_nom] = $resultat[$compo_nom];
719
				$this->table_retour['nom_sci.'.$compo_nom] = $resultat[$compo_nom];
688
			}
720
			}
689
		}
721
		}
690
	}
722
	}
691
 
723
 
692
	public function ajouterSignificationCode($champ, $valeur) {
724
	public function ajouterSignificationCode($champ, $valeur) {
693
		$champ = ($champ == 'rang') ? 'rangTaxo' : rtrim($champ, '_Co,_Ga');
725
		$champ = ($champ == 'rang') ? 'rangTaxo' : rtrim($champ, '_Co,_Ga');
694
		if (preg_match('/^([^_-]+)(?:_|-)([^_-]+)$/', $champ, $match)) {
726
		if (preg_match('/^([^_-]+)(?:_|-)([^_-]+)$/', $champ, $match)) {
695
			$champ = $match[1].ucfirst($match[2]);
727
			$champ = $match[1].ucfirst($match[2]);
696
		}
728
		}
697
		$url = Config::get('url_ontologie').$champ.':'.$valeur.'/nom';
729
		$url = Config::get('url_ontologie').$champ.':'.$valeur.'/nom';
698
		$res = $this->consulterHref($url); //dans commun.php
730
		$res = $this->consulterHref($url); //dans commun.php
699
		$nom_code = $valeur;
731
		$nom_code = $valeur;
700
		if (is_object($res)) {
732
		if (is_object($res)) {
701
			$nom_code = $res->nom;
733
			$nom_code = $res->nom;
702
		}
734
		}
703
		return $nom_code;
735
		return $nom_code;
704
	}
736
	}
705
 
737
 
706
	public function recupererNomSci($id) {
738
	public function recupererNomSci($id) {
707
		$nom = array();
739
		$nom = array();
708
		if ($id != 0) {
740
		if ($id != 0) {
709
			if ($this->compo_nom == null) {
741
			if ($this->compo_nom == null) {
710
				$req = 'SELECT nom_sci, num_nom_retenu, nom_sci_html FROM '.$this->table.' WHERE num_nom = '.$id;
742
				$req = 'SELECT nom_sci, num_nom_retenu, nom_sci_html FROM '.$this->table.' WHERE num_nom = '.$id;
711
			} else { //on ajoute à la requete sql, les champs de ns.structure
743
			} else { //on ajoute à la requete sql, les champs de ns.structure
712
				//print_r($this->compo_nom);
744
				//print_r($this->compo_nom);
713
				$req = 'SELECT nom_sci, num_nom_retenu, nom_sci_html, '.implode(', ', $this->compo_nom)
745
				$req = 'SELECT nom_sci, num_nom_retenu, nom_sci_html, '.implode(', ', $this->compo_nom)
714
						.' FROM '.$this->table
746
						.' FROM '.$this->table
715
						.' WHERE num_nom = '.$id;
747
						.' WHERE num_nom = '.$id;
716
			}
748
			}
717
			if ($this->parametres['ns.format'] == 'htm') {
749
			if ($this->parametres['ns.format'] == 'htm') {
718
				$req = str_replace('nom_sci', 'nom_sci_html as nom_sci', $req);
750
				$req = str_replace('nom_sci', 'nom_sci_html as nom_sci', $req);
719
			}
751
			}
720
			$res = $this->getBdd()->recuperer($req);
752
			$res = $this->getBdd()->recuperer($req);
721
			if ($res) {
753
			if ($res) {
722
				$nom['nom_sci']	= $res['nom_sci'];
754
				$nom['nom_sci']	= $res['nom_sci'];
723
				$nom['nom_sci_html']	= $res['nom_sci_html'];
755
				$nom['nom_sci_html']	= $res['nom_sci_html'];
724
				$nom['nom_sci_complet']	= $res['nom_sci'].$this->ajouterCompositionNom($res);
756
				$nom['nom_sci_complet']	= $res['nom_sci'].' '.$this->ajouterCompositionNom($res);
725
				$nom['nom_sci_complet_html']	= $res['nom_sci_html'].$this->ajouterCompositionNom($res, 'htm');
757
				$nom['nom_sci_complet_html']	= $res['nom_sci_html'].' '.$this->ajouterCompositionNom($res, 'htm');
726
				$nom['service'] = ($res['num_nom_retenu'] == $id && $this->service == 'taxons') ? 'taxons' : 'noms';
758
				$nom['service'] = ($res['num_nom_retenu'] == $id && $this->service == 'taxons') ? 'taxons' : 'noms';
727
			}
759
			}
728
		}
760
		}
729
		return $nom;
761
		return $nom;
730
	}
762
	}
731
 
763
 
732
	/** Permet de retourner une chaine de caractère composée des parametres du nom (ns.structure : annnée, auteur,
764
	/** Permet de retourner une chaine de caractère composée des parametres du nom (ns.structure : annnée, auteur,
733
	 * bibilio et addendum). A ajouter au nom scientifique */
765
	 * bibilio et addendum). A ajouter au nom scientifique */
734
	public function ajouterCompositionNom($tab_res, $format = '') {
766
	public function ajouterCompositionNom($tab_res, $format = '') {
735
		$format = ($format == '') ? $this->parametres['ns.format'] : $format;
767
		$format = ($format == '') ? $this->parametres['ns.format'] : $format;
-
 
768
 
736
		$nom = '';
769
		$nom = '';
737
		if (isset($this->compo_nom)) {
770
		if (isset($this->compo_nom)) {
738
			if ($format == 'htm') {
771
			if ($format == 'htm') {
739
				$format = array(
772
				$format = array(
740
					'au' => '<span class="auteur">%s</span>',
773
					'au' => '<span class="auteur">%s</span>',
741
					'an' => '[<span class="annee">%s</span>]',
774
					'an' => '[<span class="annee">%s</span>]',
742
					'an_bib' => '[<span class="annee">%s</span>, <span class="biblio">%s</span>]',
775
					'an_bib' => '[<span class="annee">%s</span>, <span class="biblio">%s</span>]',
743
					'bib' => '[<span class="biblio">%s</span>]',
776
					'bib' => '[<span class="biblio">%s</span>]',
744
					'ad' => '[<span class="adendum">%s</span>]');
777
					'ad' => '[<span class="adendum">%s</span>]');
745
			} else {
778
			} else {
746
				$format = array(
779
				$format = array(
747
					'au' => '%s',
780
					'au' => '%s',
748
					'an' => '[%s]',
781
					'an' => '[%s]',
749
					'an_bib' => '[%s, %s]',
782
					'an_bib' => '[%s, %s]',
750
					'bib' => '[%s]',
783
					'bib' => '[%s]',
751
					'ad' => '[%s]');
784
					'ad' => '[%s]',
-
 
785
					'gen' => '%s',
-
 
786
					'sp' => '%s',
-
 
787
					'ssp' => '%s',
-
 
788
					'fam' => '%s',
-
 
789
					'au_ss' => '%s',
-
 
790
					'bib_ss' => '%s');
752
			}
791
			}
753
			$compo_nom = array();
792
			$compo_nom = array();
-
 
793
 
754
			foreach ($this->compo_nom as $key => $champ) {
794
			foreach ($this->compo_nom as $key => $champ) {
755
				if (isset($tab_res[$champ]) && !empty($tab_res[$champ])) {
795
				if (isset($tab_res[$champ]) && !empty($tab_res[$champ])) {
756
					$compo_nom[$key] = $tab_res[$champ];
796
					$compo_nom[$key] = $tab_res[$champ];
757
				}
797
				}
758
			}
798
			}
759
			$nom_complet = $this->formerNomComplet($compo_nom, $format);
799
			$nom_complet = $this->formerNomComplet($compo_nom, $format);
760
			$nom = ' '.implode(' ', $nom_complet);
800
			$nom = implode(' ', $nom_complet);
761
		}
801
		}
762
		return rtrim($nom, ' ');
802
		return rtrim($nom, ' ');
763
	}
803
	}
764
 
804
 
765
 
805
 
766
	public function formerNomComplet($compo_nom, $format) {
806
	public function formerNomComplet($compo_nom, $format) {
767
		$nom_complet = array();
807
		$nom_complet = array();
768
		extract($compo_nom);
808
		extract($compo_nom);
769
		if (isset($au)) $nom_complet[] = sprintf($format['au'], $au);
809
		if (isset($au)) $nom_complet[] = sprintf($format['au'], $au);
770
		if (isset($an)) {
810
		if (isset($an)) {
771
			if (isset($bib)) {
811
			if (isset($bib)) {
772
				$nom_complet[] = sprintf($format['an_bib'], $an, $bib);
812
				$nom_complet[] = sprintf($format['an_bib'], $an, $bib);
773
			} else {
813
			} else {
774
				$nom_complet[] = sprintf($format['an'], $an);
814
				$nom_complet[] = sprintf($format['an'], $an);
775
			}
815
			}
776
		} elseif (isset($bib)) {
816
		} elseif (isset($bib)) {
777
			$nom_complet[] = sprintf($format['bib'], $bib);
817
			$nom_complet[] = sprintf($format['bib'], $bib);
778
		}
818
		}
779
		if (isset($ad)) $nom_complet[] = sprintf($format['ad'], $ad);
819
		if (isset($ad)) $nom_complet[] = sprintf($format['ad'], $ad);
-
 
820
		if (isset($gen)) $nom_complet[] = sprintf($format['gen'], $gen);
-
 
821
		if (isset($ssp)) $nom_complet[] = sprintf($format['ssp'], $ssp);
-
 
822
		if (isset($sp)) $nom_complet[] = sprintf($format['sp'], $sp);
-
 
823
		if (isset($fam)) $nom_complet[] = sprintf($format['fam'], $fam);
-
 
824
		if (isset($au_ss)) $nom_complet[] = sprintf($format['au_ss'], $au_ss);
-
 
825
		if (isset($bib_ss)) {
-
 
826
			$bibl = $this->tronquerBiblio($bib_ss);
-
 
827
			//simule un 'select distinct' sur les biblio tronquées
-
 
828
			if (!isset($this->bib_traitees[$bibl])) { 
-
 
829
				$nom_complet[] = sprintf($format['bib_ss'],$bibl );
-
 
830
				$this->bib_traitees[$bibl] = 1;
-
 
831
			}
-
 
832
		}
780
		return $nom_complet;
833
		return $nom_complet;
781
	}
834
	}
-
 
835
 
-
 
836
	public function tronquerBiblio($valeur){
-
 
837
		$bib = strstr($valeur,',', true);
-
 
838
		if(strpos($bib,';')) {
-
 
839
			$bib = strstr($bib,';');
-
 
840
			$bib = str_replace('; ','',$bib);
-
 
841
		}
-
 
842
		return $bib;
-
 
843
	}
-
 
844
	
782
 
845
 
783
 
846
 
784
	public function correspondAUnCode($key) {
847
	public function correspondAUnCode($key) {
785
		return (strrpos($key, '.code') !== false) || (in_array($key.'.code', $this->correspondance_champs));
848
		return (strrpos($key, '.code') !== false) || (in_array($key.'.code', $this->correspondance_champs));
786
	}
849
	}
787
 
850
 
788
	public function correspondAUnId($key) {
851
	public function correspondAUnId($key) {
789
		return (strrpos($key, '.id') !== false) || (in_array($key.'.id', $this->correspondance_champs));
852
		return (strrpos($key, '.id') !== false) || (in_array($key.'.id', $this->correspondance_champs));
790
	}
853
	}
791
 
854
 
792
	public function estUnPoint($key) {
855
	public function estUnPoint($key) {
793
		if (strrpos($key, 'hybride.parent') !== false) {
856
		if (strrpos($key, 'hybride.parent') !== false) {
794
			$key = str_replace('hybride.parent', 'hybride_parent', $key);
857
			$key = str_replace('hybride.parent', 'hybride_parent', $key);
795
		}
858
		}
796
		return (strrpos($key, '.') !== false);
859
		return (strrpos($key, '.') !== false);
797
	}
860
	}
798
 
861
 
799
	public function recupererMasquePrincipal() {
862
	public function recupererMasquePrincipal() {
800
		$masque = null;
863
		$masque = null;
801
		$tab_masque   = array(
864
		$tab_masque   = array(
802
			'masque' => 'nom_sci',
865
			'masque' => 'nom_sci',
803
			'masque_sg' => 'nom_supra_generique',
866
			'masque_sg' => 'nom_supra_generique',
804
			'masque_gen' => 'genre',
867
			'masque_gen' => 'genre',
805
			'masque_sp' => 'epithete_sp',
868
			'masque_sp' => 'epithete_sp',
806
			'masque_ssp' => 'epithete_infra_sp',
869
			'masque_ssp' => 'epithete_infra_sp',
807
			'masque_au' => 'auteur',
870
			'masque_au' => 'auteur',
808
			'masque_an' => 'annee',
871
			'masque_an' => 'annee',
809
			'masque_bib' => 'biblio_origine',
872
			'masque_bib' => 'biblio_origine',
810
			'masque_ad' => 'addendum',
873
			'masque_ad' => 'addendum',
811
			'masque_rg' => 'rang');
874
			'masque_rg' => 'rang');
812
		$liste_masque = array();
875
		$liste_masque = array();
813
 
876
 
814
		if (isset($this->masque['num_nom'])) {
877
		if (isset($this->masque['num_nom'])) {
815
			$liste_masque[] = $this->masque['num_nom'];
878
			$liste_masque[] = $this->masque['num_nom'];
816
		}
879
		}
817
 
880
 
818
		foreach ($tab_masque as $key => $filtre) {
881
		foreach ($tab_masque as $key => $filtre) {
819
            if (isset($this->masque[$filtre])) {
882
            if (isset($this->masque[$filtre])) {
820
            	if (!isset($masque) && !in_array($filtre, array('rang', 'annee'))) {
883
            	if (!isset($masque) && !in_array($filtre, array('rang', 'annee'))) {
821
            		$masque = array($key, $filtre);
884
            		$masque = array($key, $filtre);
822
            	}
885
            	}
823
                $liste_masque[] = $this->masque[$filtre];
886
                $liste_masque[] = $this->masque[$filtre];
824
            }
887
            }
825
        }
888
        }
826
        $this->masque = $liste_masque;
889
        $this->masque = $liste_masque;
827
        return $masque;
890
        return $masque;
828
	}
891
	}
829
}
892
}
830
?>
893
?>