Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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