Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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