Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1030 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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