Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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