3 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe permettant de fournir des informations sur les noms scientifiques.
|
|
|
5 |
* Si l'url finit par /noms on retourne une liste de noms latin et leurs identifiants (seulement les 100 premeiers noms par défaut).
|
|
|
6 |
* L'url peut contenir des paramètres optionnels passés après le ? : /noms?param1=val1¶m2=val2&...
|
|
|
7 |
*
|
|
|
8 |
* Les paramètres de requête disponibles sont : masque, masque.gen (nom de genre), masque.sp (épithète d'espèce), masque.ssp (épithète infra-spécifique),
|
|
|
9 |
* masque.au (auteur du nom), masque.an (année de publication du nom), masque.bib (réf biblio de la publi d'origine du nom), masque.ad (nomen addendum),
|
|
|
10 |
* masque.nn (identifiant du nom), recherche, rang, distinct, retour.format, nl.format, nl.structure, navigation.depart et navigation.limite.
|
|
|
11 |
* Les différentes requetes :
|
|
|
12 |
* - noms | noms/relations/#projet/#id_projet | noms/#id | noms/#id/#champ+#champ
|
|
|
13 |
* - noms/#id/relations | noms/#id/relations/synonymie | noms/#id/relations/homonymie | noms/#id/relations/flores
|
|
|
14 |
* - noms/stats/rangs | noms/stats/annees | noms/stats/initiales
|
|
|
15 |
*
|
|
|
16 |
* @package bdtfx
|
|
|
17 |
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
|
|
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
20 |
* @version $Id$
|
|
|
21 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
|
|
22 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Noms
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
class Noms extends CommunNomsTaxons {
|
|
|
26 |
|
|
|
27 |
protected $format_reponse = 'noms'; // Permet de stocker la requete formulée
|
|
|
28 |
protected $service = 'noms';
|
|
|
29 |
protected $requete_champ = 'num_nom, nom_sci, num_nom_retenu';
|
|
|
30 |
protected $requete_condition = null;
|
|
|
31 |
protected $requete_group_by = '';
|
|
|
32 |
/** Permet de stocker les limite de la requete SQL (par défaut seul les 100 premiers résultats seront retournés).*/
|
|
|
33 |
protected $limite_requete = array('depart' => 0, 'limite' => 100);
|
|
|
34 |
protected $distinct = null; // Valeur du paramètre de requete distinct (=0|1)
|
|
|
35 |
|
|
|
36 |
public function consulter($ressources, $parametres) {
|
|
|
37 |
return parent::consulter($ressources, $parametres);
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
//+----------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
|
|
|
41 |
|
|
|
42 |
public function traiterParametresSpecifiques() {
|
|
|
43 |
foreach ($this->parametres as $param => $val) {
|
|
|
44 |
switch ($param) {
|
|
|
45 |
case 'masque' :
|
|
|
46 |
$this->ajouterFiltreMasque('nom_sci', $val);
|
|
|
47 |
break;
|
|
|
48 |
case 'masque.sg' :
|
|
|
49 |
$this->ajouterFiltreMasque('nom_supra_generique', $val);
|
|
|
50 |
break;
|
|
|
51 |
case 'masque.gen' :
|
|
|
52 |
$this->ajouterFiltreMasque('genre', $val);
|
|
|
53 |
break;
|
|
|
54 |
case 'masque.sp' :
|
|
|
55 |
$this->ajouterFiltreMasque('epithete_sp', $val);
|
|
|
56 |
break;
|
|
|
57 |
case 'masque.ssp' :
|
|
|
58 |
$this->ajouterFiltreMasque('epithete_infra_sp',$val);
|
|
|
59 |
break;
|
|
|
60 |
case 'masque.au' :
|
|
|
61 |
$this->ajouterFiltreMasque('auteur', $val);
|
|
|
62 |
break;
|
|
|
63 |
case 'masque.an' :
|
|
|
64 |
$this->ajouterFiltreMasque('annee', $val);
|
|
|
65 |
break;
|
|
|
66 |
case 'masque.bib' :
|
|
|
67 |
$this->ajouterFiltreMasque('biblio_origine',$val);
|
|
|
68 |
break;
|
|
|
69 |
case 'masque.ad' :
|
|
|
70 |
$this->ajouterFiltreMasque('nom_addendum', $val);
|
|
|
71 |
break;
|
|
|
72 |
case 'masque.nn' :
|
|
|
73 |
$this->requete_condition []= 'num_nom IN ('.$val.')';
|
|
|
74 |
$this->masque['num_nom'] = "num_nom=$val";
|
|
|
75 |
break;
|
|
|
76 |
case 'masque.rg' :
|
|
|
77 |
$this->ajouterFiltreMasque('rang', $val);
|
|
|
78 |
break;
|
|
|
79 |
case 'retour.champs' :
|
|
|
80 |
$this->verifierParamChamps($param, $val);
|
|
|
81 |
break;
|
|
|
82 |
case 'distinct' :
|
|
|
83 |
$this->distinct = $val;
|
|
|
84 |
break;
|
|
|
85 |
}
|
|
|
86 |
$this->ajouterNomDistinct();
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public function verifierParamChamps($param, $val) {
|
|
|
91 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
92 |
$champs_demandes = explode(',', $val);
|
|
|
93 |
$champs_verifies = array();
|
|
|
94 |
$champs_api = array_flip($this->champs_api);
|
|
|
95 |
foreach ($champs_demandes as $champ) {
|
|
|
96 |
if (array_key_exists($champ, $champs_api)) {
|
|
|
97 |
$champs_verifies[] = $champs_api[$champ];
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
if (count($champs_verifies) > 0) {
|
|
|
101 |
$this->requete_champ .= ', '.implode(',', $champs_verifies);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/** Permet de rajouter à la requete sql le parametre distinct. N'est utilisé qu'avec le format oss */
|
|
|
106 |
public function ajouterNomDistinct() {
|
|
|
107 |
if (isset($this->distinct)) {
|
|
|
108 |
if ($this->distinct == 1 && $this->parametres['retour.format'] == 'oss') {
|
|
|
109 |
if ($this->compo_nom == '') {
|
|
|
110 |
$this->requete_champ = ' DISTINCT nom_sci ';
|
|
|
111 |
} else {
|
|
|
112 |
$this->requete_champ = ' DISTINCT nom_sci, '.implode(', ',$this->compo_nom);
|
|
|
113 |
}
|
|
|
114 |
} elseif ($this->distinct == 1 && $this->parametres['retour.format'] != 'oss') {
|
|
|
115 |
$e = 'Erreur dans votre requête </br> L\'utilisation du paramètre distinct ne se fait que sous
|
|
|
116 |
le format oss';
|
|
|
117 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
//-----------------FONCTION D'ANALYSE DES RESSOURCES--------------------------------------------------------------------
|
|
|
123 |
|
|
|
124 |
public function traiterRessourcesIdentifiant() {
|
|
|
125 |
//on initialise la condition de la requete sql et le format de réponse
|
|
|
126 |
$this->requete_condition = array(); //on vide la table dans le cas de plusieurs version
|
|
|
127 |
$this->requete_condition[] = 'num_nom = '.$this->getBdd()->proteger($this->ressources[0]);
|
|
|
128 |
$this->format_reponse = $this->service.'/id';
|
|
|
129 |
if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
|
104 |
delphine |
130 |
if ($this->ressources[1] == 'relations') {
|
3 |
jpm |
131 |
$this->traiterRessourceIdRelations();
|
|
|
132 |
} else {
|
|
|
133 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
|
|
134 |
<li> noms/#id/relations </li> <li> noms/#id/#champ+#champ </li>
|
|
|
135 |
<li> noms/#id/relations/synonymie </li> <li> noms/#id/relations/flores </li>
|
|
|
136 |
<li> noms/#id/relations/homonymie </li>';
|
|
|
137 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
138 |
}
|
|
|
139 |
} else { // requete de type noms/#id : rajout du nom_sci pour récupérer le format html par la fct mettreAuFormat()
|
|
|
140 |
$this->requete_champ = ' *, nom_sci ';
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public function traiterRessourceRelations() {
|
|
|
145 |
$this->format_reponse .= '/relations';
|
|
|
146 |
$projet = $this->ressources[1];
|
|
|
147 |
$num_nom = $this->ressources[2];
|
|
|
148 |
if (strrpos($num_nom, 'nn.coste') !== false) {
|
|
|
149 |
list($p, $nn) = explode('=', $num_nom);
|
|
|
150 |
$num_nom = $nn;
|
|
|
151 |
}
|
|
|
152 |
$champ = "flore_$projet"."_num";
|
|
|
153 |
if (isset($this->ressources[3])) {
|
|
|
154 |
$type = $this->ressources[3];
|
|
|
155 |
if (!in_array($type, array('homonymie', 'synonymie', 'flores'))) {
|
|
|
156 |
$e = "Les types disponibles pour les noms sont homonymie, synonymie et flores";
|
|
|
157 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
$this->requete_champ = ' num_nom ';
|
|
|
161 |
$this->requete_condition = array();
|
|
|
162 |
$this->requete_condition[] = "$champ = ".$this->getBdd()->proteger($num_nom);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
public function traiterRessourceIdRelations() {
|
|
|
166 |
$this->format_reponse .= '/relations';
|
|
|
167 |
if (isset($this->ressources[2]) && !empty($this->ressources[2])) {
|
|
|
168 |
// requete de type noms/#id/relations/#relation
|
|
|
169 |
switch ($this->ressources[2]) {
|
|
|
170 |
case 'synonymie' :
|
|
|
171 |
$this->traiterRessourceIdSynonymie();
|
|
|
172 |
break;
|
|
|
173 |
case 'flores' :
|
|
|
174 |
$this->traiterRessourceIdFlores();
|
|
|
175 |
break;
|
|
|
176 |
case 'homonymie' :
|
|
|
177 |
$this->traiterRessourceIdHomonymie();
|
|
|
178 |
break;
|
|
|
179 |
default :
|
|
|
180 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
|
|
181 |
<li> noms/#id/relations </li> <li> noms/#id/relations/synonymie </li>
|
|
|
182 |
<li> noms/#id/relations/flores </li> <li> noms/#id/relations/homonymie </li>';
|
|
|
183 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
184 |
break;
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
public function traiterRessourceIdSynonymie() {
|
|
|
190 |
// SELECT num_nom, nom_sci, num_nom_retenu, basionyme FROM bdtfx_v2_00 WHERE num_nom = X LIMIT 0,100;
|
|
|
191 |
$this->format_reponse .= '/synonymie';
|
|
|
192 |
if (strrpos($this->requete_champ, ', basionyme') === false) {
|
|
|
193 |
$this->requete_champ .= ', basionyme ';
|
|
|
194 |
}
|
|
|
195 |
$this->requete_condition[0] = 'num_nom_retenu = '.
|
|
|
196 |
'(SELECT num_nom_retenu FROM '.$this->table.' WHERE '.$this->requete_condition[0].')';
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public function traiterRessourceIdHomonymie() {
|
|
|
200 |
// SELECT num_nom, nom_sci, num_nom_retenu FROM bdtfx_v2_00 WHERE nom_sci = (SELECT nom_sci FROM bdtfx_v2_00 WHERE num_nom = X);
|
|
|
201 |
$this->format_reponse .= '/homonymie';
|
|
|
202 |
$this->requete_condition[0] = 'nom_sci = (SELECT nom_sci FROM '.$this->table
|
|
|
203 |
.' WHERE '.$this->requete_condition[0].')';
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
public function traiterRessourceIdFlores() {
|
|
|
207 |
$champ_flores = '';
|
|
|
208 |
foreach ($this->champs_table as $champ) {
|
|
|
209 |
if (preg_match('/^flore_.*$/', $champ)) {
|
|
|
210 |
$champ_flores .= ', '.$champ;
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
$this->format_reponse .= '/flores';
|
|
|
214 |
$this->requete_champ = 'num_nom'.$champ_flores;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
public function traiterRessourceStatsRangs() {
|
|
|
218 |
// SELECT count(*) as nombre, rang FROM bdtfx_v2_00 [WHERE rang = 290] GROUP BY rang ORDER BY rang;
|
|
|
219 |
$this->format_reponse .= '/rangs';
|
|
|
220 |
$this->requete_champ = 'count(*) as nombre, rang ';
|
|
|
221 |
$this->requete_group_by = ' GROUP BY rang ORDER BY rang ';
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
public function traiterRessourceStatsAnnees() {
|
|
|
225 |
// SELECT count(*) as nombre, annee FROM bdtfx_v2_00 GROUP BY annee ORDER BY annee;
|
|
|
226 |
$this->format_reponse .= '/annees';
|
|
|
227 |
$this->requete_champ = 'count(*) as nombre, annee ';
|
|
|
228 |
$this->requete_condition = null;
|
|
|
229 |
$this->requete_group_by = ' GROUP BY annee ORDER BY annee ';
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public function traiterRessourceStatsInitiales() {
|
|
|
233 |
// SELECT count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre GROUP BY rang, left(nom_sci, 2);
|
|
|
234 |
$this->format_reponse .= '/initiales';
|
|
|
235 |
$this->requete_champ = 'count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre ';
|
|
|
236 |
$this->requete_group_by = ' GROUP BY rang, left(nom_sci, 2)';
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
|
|
|
242 |
|
|
|
243 |
public function assemblerLaRequete() {
|
|
|
244 |
if ( strrpos($this->format_reponse, 'noms/stats/') === false ) {
|
|
|
245 |
$this->mettreAuFormat(); //Ds CommunNomsTaxons.php
|
|
|
246 |
}
|
|
|
247 |
$requete = ' SELECT '.$this->requete_champ.
|
|
|
248 |
' FROM '.$this->table
|
|
|
249 |
.$this->retournerRequeteCondition()
|
|
|
250 |
.$this->requete_group_by
|
|
|
251 |
.$this->formerRequeteLimite();
|
|
|
252 |
return $requete;
|
|
|
253 |
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
public function formerRequeteLimite() {
|
|
|
257 |
if ($this->format_reponse != 'noms' && $this->format_reponse != 'noms/id/relations/synonymie'
|
|
|
258 |
&& $this->format_reponse != 'noms/id/relations/homonymie') {
|
|
|
259 |
$this->requete_limite = '';
|
|
|
260 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
|
|
261 |
$this->limite_requete['depart'] =
|
|
|
262 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
|
|
263 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
|
|
264 |
} else {
|
|
|
265 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
|
|
266 |
}
|
|
|
267 |
return $this->requete_limite;
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
public function retournerRequeteCondition() {
|
|
|
271 |
$condition = '';
|
|
|
272 |
if ($this->requete_condition) {
|
|
|
273 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
274 |
}
|
|
|
275 |
return $condition;
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
/** Recupere le nombre total de résultat d'une requete lancée. */
|
|
|
280 |
public function recupererTotalResultat() {
|
|
|
281 |
$total = null;
|
|
|
282 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.$this->retournerRequeteCondition().$this->requete_group_by;
|
|
|
283 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
284 |
if ($res) {
|
|
|
285 |
$total = $res['nombre'];
|
|
|
286 |
} else {
|
|
|
287 |
$e = 'Fct recupererTotalResultat() : <br/>Données introuvables dans la base';
|
|
|
288 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
289 |
}
|
|
|
290 |
return $total;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
|
|
|
295 |
|
272 |
delphine |
296 |
public function retournerResultatFormate($resultat) {
|
3 |
jpm |
297 |
switch ($this->format_reponse) {
|
|
|
298 |
case 'noms/relations' :
|
|
|
299 |
$reponse = $this->formaterRelations($resultat[0]);
|
|
|
300 |
break;
|
|
|
301 |
case 'noms/id' : //ds CommunNomsTaxons
|
|
|
302 |
$reponse = $this->formaterId($resultat[0]);
|
|
|
303 |
break;
|
|
|
304 |
case 'noms/id/relations' :
|
|
|
305 |
$reponse = $this->formaterIdRelations($resultat[0]);
|
|
|
306 |
break;
|
|
|
307 |
case 'noms/id/relations/synonymie' :
|
|
|
308 |
$reponse = $this->formaterIdSynonymie($resultat);
|
|
|
309 |
break;
|
|
|
310 |
case 'noms/id/relations/homonymie' :
|
|
|
311 |
$reponse = $this->formaterIdHomonymie($resultat);
|
|
|
312 |
break;
|
|
|
313 |
case 'noms/id/relations/flores' : //ds CommunsNomsTaxons
|
|
|
314 |
$reponse = $this->formaterIdFlores($resultat[0]);
|
|
|
315 |
break;
|
|
|
316 |
case 'noms/stats/annees' : //ds CommunNomsTaxons
|
|
|
317 |
$reponse = $this->formaterStatsAnnee($resultat);
|
|
|
318 |
break;
|
|
|
319 |
case 'noms/stats/rangs' : //ds CommunNomsTaxons
|
|
|
320 |
$reponse = $this->formaterStatsRang($resultat);
|
|
|
321 |
break;
|
|
|
322 |
case 'noms/stats/initiales' : //ds CommunNomsTaxons
|
|
|
323 |
$reponse = $this->formaterStatsInitiales($resultat);
|
|
|
324 |
break;
|
|
|
325 |
case 'noms' :
|
|
|
326 |
$reponse = $this->formaterNoms($resultat);
|
|
|
327 |
break;
|
|
|
328 |
}
|
|
|
329 |
return $reponse;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
//+---------------------concerne les resultats pour des requetes de type noms/id-----------------------------+
|
|
|
333 |
|
|
|
334 |
public function formaterRelations($resultat) {
|
|
|
335 |
$num_nom = $resultat['num_nom'];
|
|
|
336 |
if (isset($this->ressources[3])) {
|
|
|
337 |
$url = Config::get('url_service').$this->service."/$num_nom/relations";
|
|
|
338 |
} else {
|
|
|
339 |
$type = $this->ressources[3];
|
|
|
340 |
$url = Config::get('url_service')."/$this->service/$num_nom/relations/$type";
|
|
|
341 |
}
|
|
|
342 |
$res = $this->consulterHref($url);
|
|
|
343 |
return $res;
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
public function formaterIdRelations($resultat) {
|
|
|
347 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
348 |
$this->resultat_req = $resultat;
|
|
|
349 |
$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
|
|
|
350 |
|
|
|
351 |
//on recupère le resultat de chaque relation (appel du WS correspondant)
|
272 |
delphine |
352 |
$flores = $this->ajouterRelations('flores');
|
3 |
jpm |
353 |
if (isset($flores)) $retour_id_rel['resultat']['flores'] = $flores;
|
272 |
delphine |
354 |
$homonymes = $this->ajouterRelations('homonymie');
|
3 |
jpm |
355 |
if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
|
272 |
delphine |
356 |
$synonymes = $this->ajouterRelations('synonymie');
|
3 |
jpm |
357 |
if (isset($synonymes)) $retour_id_rel['resultat']['synonymes'] = $synonymes;
|
|
|
358 |
|
|
|
359 |
//on renvoit null si il n'existe aucune relations (on efface l'entete en premier lieu)
|
|
|
360 |
if (!isset($retour_id_rel['resultat'])) {
|
|
|
361 |
$retour_id_rel = null;
|
|
|
362 |
} else { //on rajoute l'entete si des relations existent
|
|
|
363 |
$this->afficherDonnees('num_nom', $this->ressources[0]);
|
|
|
364 |
$retour_id_rel['entete'] = $this->table_retour;
|
|
|
365 |
$this->table_retour = array();
|
|
|
366 |
}
|
|
|
367 |
return $retour_id_rel;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
/**
|
|
|
371 |
* Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
|
|
|
372 |
* flores) par l'appel du web service [version]/noms/#id/relations/[type_relation]
|
|
|
373 |
*/
|
272 |
delphine |
374 |
public function ajouterRelations($relation) {
|
|
|
375 |
$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
|
3 |
jpm |
376 |
$res = null;
|
|
|
377 |
$parametres_url = '';
|
|
|
378 |
if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
|
272 |
delphine |
379 |
$url = Config::get('url_service').'/'.$this->service.'/'
|
3 |
jpm |
380 |
.$this->ressources[0].'/relations/'
|
272 |
delphine |
381 |
.$relation.$parametres_url; Debug::printr($url);
|
3 |
jpm |
382 |
$relation = $this->consulterHref($url);
|
|
|
383 |
$res = $relation->resultat;
|
|
|
384 |
return $res;
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
public function formaterIdSynonymie($resultat) {
|
|
|
389 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
390 |
$retour_id_syn = array();
|
|
|
391 |
if ($resultat[0]['num_nom_retenu'] == '') {
|
|
|
392 |
$retour_id_syn[] = 'nom_retenu N.D.';
|
|
|
393 |
} elseif (count($resultat) != 1) {
|
|
|
394 |
//on remplit d'abord l'entete du resultat
|
|
|
395 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
396 |
$this->afficherEnteteResultat('/'.$this->service.'/'.$this->ressources[0].'/relations/synonymie');
|
|
|
397 |
$retour_id_syn['entete'] = $this->table_retour;
|
|
|
398 |
$this->table_retour = array();
|
|
|
399 |
foreach ($resultat as $tab) {
|
|
|
400 |
//pour chaque basionyme, on recupère le résultat : num_nom, nom_sci, basionyme et num_nom_retenu :
|
|
|
401 |
$this->resultat_req = $tab;
|
|
|
402 |
$num = $tab['num_nom'];
|
|
|
403 |
$this->afficherNomHrefRetenu($tab, $num);
|
|
|
404 |
$this->afficherDonnees('basionyme', $tab['basionyme']);
|
|
|
405 |
$retour_id_syn['resultat'][$num] = $this->table_retour;
|
|
|
406 |
$this->table_retour = array();
|
|
|
407 |
}
|
|
|
408 |
if (!isset($retour_id_syn['resultat']) && !in_array('nom_retenu N.D.', $retour_id_syn)) {
|
|
|
409 |
$retour_id_syn = null; //on initialise le resultat à null
|
|
|
410 |
}
|
|
|
411 |
}
|
|
|
412 |
return $retour_id_syn;
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
public function formaterIdHomonymie($resultat) {
|
|
|
416 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
272 |
delphine |
417 |
if (count($resultat) != 1) {
|
3 |
jpm |
418 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
419 |
$this->afficherEnteteResultat($resultat, '/'.$this->service.'/'.$this->ressources[0].'/relations/homonymie');
|
|
|
420 |
$retour_id_hom['entete'] = $this->table_retour;
|
|
|
421 |
$this->table_retour = array();
|
|
|
422 |
foreach ($resultat as $homonyme) {
|
|
|
423 |
$this->resultat_req = $homonyme;
|
|
|
424 |
$id = $homonyme['num_nom'];
|
|
|
425 |
$this->afficherDonnees('num_nom', $id);
|
|
|
426 |
if ($homonyme['num_nom_retenu'] != '') {
|
|
|
427 |
$retenu = ($id == $homonyme['num_nom_retenu']) ? 'true' : 'false';
|
|
|
428 |
$this->table_retour['retenu'] = $retenu;
|
|
|
429 |
}
|
|
|
430 |
$retour_id_hom['resultat'][$id] = $this->table_retour;
|
|
|
431 |
unset($retour_id_hom['resultat'][$id]['id']);
|
|
|
432 |
$this->table_retour = array();
|
|
|
433 |
}
|
272 |
delphine |
434 |
} else {Debug::printr($resultat);
|
3 |
jpm |
435 |
$retour_id_hom = null;
|
|
|
436 |
}
|
|
|
437 |
return $retour_id_hom;
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
public function formaterIdFlores($resultat) {
|
|
|
441 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp,noms_projets');
|
|
|
442 |
$this->resultat_req = $resultat;
|
|
|
443 |
$id = array_shift($resultat);
|
|
|
444 |
$reponse['entete']['id'] = $id;
|
|
|
445 |
foreach ($resultat as $flores => $valeur) {
|
|
|
446 |
if ($valeur != '' && $valeur != '0') {
|
272 |
delphine |
447 |
$this->afficherInfosFlore($resultat, $flores, $valeur);
|
3 |
jpm |
448 |
}
|
|
|
449 |
}
|
|
|
450 |
if ($this->table_retour != array()) {
|
|
|
451 |
$reponse['resultat'] = $this->table_retour;
|
|
|
452 |
$this->table_retour = array();
|
|
|
453 |
} else {
|
|
|
454 |
$reponse = null;
|
|
|
455 |
}
|
|
|
456 |
return $reponse;
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
public function afficherInfosFlore(&$resultat, $flores, $valeur) {
|
|
|
460 |
$flore = substr($flores,0,strrpos($flores, '_'));
|
|
|
461 |
$projet = $this->noms_projets[$flore];
|
|
|
462 |
if (strrpos($flores, 'num') !== false) {
|
|
|
463 |
if (preg_match('/^([0-9]+)(?:[.]syn[^a-z]*|(.*))?$/', $valeur, $match)) {
|
|
|
464 |
$this->table_retour[$flore]['id'] = $match[1];
|
|
|
465 |
if ($projet == 'coste') {
|
|
|
466 |
$this->table_retour[$flore]['href'] = $this->ajouterHrefAutreProjet('noms', 'nn_coste:', $match[1], $projet);
|
|
|
467 |
}
|
|
|
468 |
if (isset($match[2]) && $match[2] != '') $this->table_retour[$flore]['cle'] = $match[2];
|
|
|
469 |
}
|
|
|
470 |
if (isset($resultat[$flore.'_rem']) && !empty($resultat[$flore.'_rem'])) {
|
|
|
471 |
$this->table_retour[$flore]['remarque'] = $resultat[$flore.'_rem'];
|
|
|
472 |
unset($resultat[$flore.'_rem']);
|
|
|
473 |
}
|
|
|
474 |
} elseif (strrpos($flores,'belge') !== false) {
|
|
|
475 |
if (preg_match('/^([0-9]+) (R|S)?$/', $valeur, $match)) {
|
|
|
476 |
if (isset($match[2])) $type = ($match[2] == 'R') ? 'taxons' : 'synonyme';
|
|
|
477 |
$this->table_retour[$flore]['page'] = $match[1];
|
|
|
478 |
$this->table_retour[$flore]['type'] = $type;
|
|
|
479 |
}
|
|
|
480 |
}
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
//+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
|
|
|
486 |
|
|
|
487 |
public function formaterNoms($resultat) {
|
|
|
488 |
if ($this->parametres['retour.format'] == 'oss') {
|
|
|
489 |
$reponse = $this->formaterEnOss($resultat); //Ds CommunNomsTaxons.php
|
|
|
490 |
} else {
|
|
|
491 |
$reponse = $this->formaterEnJsonMax($resultat);
|
|
|
492 |
}
|
|
|
493 |
return $reponse;
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
public function formaterEnJsonMax($resultat) {
|
|
|
497 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
498 |
$masque = $this->recupererMasquePrincipal();
|
|
|
499 |
if (isset($masque)) {
|
|
|
500 |
$resultat = $this->trierRechercheFloue($this->parametres[$masque[0]], $resultat, $masque[1]);
|
|
|
501 |
}
|
|
|
502 |
if (isset($this->masque)) {
|
99 |
delphine |
503 |
$this->table_retour['masque'] = implode('&', $this->masque);
|
3 |
jpm |
504 |
}
|
|
|
505 |
$this->afficherEnteteResultat('/'.$this->service); //communNomTaxons
|
|
|
506 |
$table_retour_json['entete'] = $this->table_retour;
|
|
|
507 |
//on remplit la table $table_retour_json['resultat']
|
|
|
508 |
$champs = null;
|
|
|
509 |
if (array_key_exists('retour.champs', $this->parametres)) {
|
|
|
510 |
$champs = explode(',', $this->parametres['retour.champs']);
|
|
|
511 |
}
|
|
|
512 |
$resultat_json = null;
|
|
|
513 |
foreach ($resultat as $tab) {
|
|
|
514 |
$this->table_retour = array();
|
|
|
515 |
$num = $tab['num_nom'];
|
93 |
delphine |
516 |
$this->afficherNomHrefRetenu($tab, $num); // ajoute le nom_sci, href et si le nom est retenu dans $this->table_retour
|
|
|
517 |
$retour = $this->table_retour;
|
|
|
518 |
$this->table_retour = array();
|
|
|
519 |
if ($champs != null) {
|
|
|
520 |
$reponse_id = $this->formaterId($tab);
|
|
|
521 |
$this->table_retour = array();
|
|
|
522 |
$this->ajouterChampsPersonnalises($champs, $reponse_id);
|
|
|
523 |
$retour = array_merge($retour, $this->table_retour);
|
|
|
524 |
}
|
|
|
525 |
$resultat_json[$num] = $retour;
|
3 |
jpm |
526 |
}
|
|
|
527 |
$table_retour_json['resultat'] = $resultat_json;
|
|
|
528 |
return $table_retour_json;
|
|
|
529 |
}
|
|
|
530 |
}
|
|
|
531 |
?>
|