Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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