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&...
|
655 |
jpm |
7 |
*
|
3 |
jpm |
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),
|
655 |
jpm |
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),
|
3 |
jpm |
10 |
* masque.nn (identifiant du nom), recherche, rang, distinct, retour.format, nl.format, nl.structure, navigation.depart et navigation.limite.
|
655 |
jpm |
11 |
* Les différentes requetes :
|
3 |
jpm |
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
|
655 |
jpm |
15 |
*
|
3 |
jpm |
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 {
|
655 |
jpm |
26 |
|
3 |
jpm |
27 |
protected $format_reponse = 'noms'; // Permet de stocker la requete formulée
|
536 |
gduche |
28 |
protected $service = 'noms';
|
655 |
jpm |
29 |
protected $serviceNom = 'noms';
|
3 |
jpm |
30 |
protected $requete_champ = 'num_nom, nom_sci, num_nom_retenu';
|
655 |
jpm |
31 |
protected $requete_condition = null;
|
3 |
jpm |
32 |
protected $requete_group_by = '';
|
|
|
33 |
/** Permet de stocker les limite de la requete SQL (par défaut seul les 100 premiers résultats seront retournés).*/
|
655 |
jpm |
34 |
protected $limite_requete = array('depart' => 0, 'limite' => 100);
|
536 |
gduche |
35 |
protected $distinct = null; // Valeur du paramètre de requete distinct (=0|1)
|
|
|
36 |
|
3 |
jpm |
37 |
public function consulter($ressources, $parametres) {
|
|
|
38 |
return parent::consulter($ressources, $parametres);
|
|
|
39 |
}
|
655 |
jpm |
40 |
|
3 |
jpm |
41 |
//+----------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
|
655 |
jpm |
42 |
|
3 |
jpm |
43 |
public function traiterParametresSpecifiques() {
|
|
|
44 |
foreach ($this->parametres as $param => $val) {
|
|
|
45 |
switch ($param) {
|
|
|
46 |
case 'masque' :
|
655 |
jpm |
47 |
$this->ajouterFiltreMasque('nom_sci', $val);
|
3 |
jpm |
48 |
break;
|
|
|
49 |
case 'masque.sg' :
|
655 |
jpm |
50 |
$this->ajouterFiltreMasque('nom_supra_generique', $val);
|
3 |
jpm |
51 |
break;
|
655 |
jpm |
52 |
case 'masque.gen' :
|
|
|
53 |
$this->ajouterFiltreMasque('genre', $val);
|
3 |
jpm |
54 |
break;
|
655 |
jpm |
55 |
case 'masque.sp' :
|
|
|
56 |
$this->ajouterFiltreMasque('epithete_sp', $val);
|
|
|
57 |
break;
|
|
|
58 |
case 'masque.ssp' :
|
|
|
59 |
$this->ajouterFiltreMasque('epithete_infra_sp',$val);
|
|
|
60 |
break;
|
|
|
61 |
case 'masque.au' :
|
|
|
62 |
$this->ajouterFiltreMasque('auteur', $val);
|
|
|
63 |
break;
|
|
|
64 |
case 'masque.an' :
|
|
|
65 |
$this->ajouterFiltreMasque('annee', $val);
|
|
|
66 |
break;
|
|
|
67 |
case 'masque.bib' :
|
|
|
68 |
$this->ajouterFiltreMasque('biblio_origine',$val);
|
|
|
69 |
break;
|
|
|
70 |
case 'masque.ad' :
|
|
|
71 |
$this->ajouterFiltreMasque('nom_addendum', $val);
|
|
|
72 |
break;
|
|
|
73 |
case 'masque.nn' :
|
|
|
74 |
$this->requete_condition []= 'num_nom IN ('.$val.')';
|
|
|
75 |
$this->masque['num_nom'] = "num_nom=$val";
|
|
|
76 |
break;
|
|
|
77 |
case 'masque.nt' :
|
|
|
78 |
$this->requete_condition []= 'num_taxonomique IN ('.$val.')';
|
|
|
79 |
$this->masque['num_tax'] = "num_taxonomique=$val";
|
|
|
80 |
break;
|
|
|
81 |
case 'masque.rg' :
|
|
|
82 |
$this->ajouterFiltreMasque('rang', $val);
|
|
|
83 |
break;
|
|
|
84 |
case 'retour.champs' :
|
|
|
85 |
$this->verifierParamChamps($param, $val);
|
|
|
86 |
break;
|
|
|
87 |
case 'distinct' :
|
|
|
88 |
$this->ajouterNomDistinct($val);
|
|
|
89 |
break;
|
|
|
90 |
case 'masque.fam' :
|
|
|
91 |
$this->ajouterFiltreMasque('famille', $val);
|
|
|
92 |
break;
|
|
|
93 |
case 'masque.prga' :
|
|
|
94 |
$this->ajouterFiltreMasque('presence_ga', $val);
|
|
|
95 |
break;
|
|
|
96 |
case 'masque.prco' :
|
|
|
97 |
$this->ajouterFiltreMasque('presence_co', $val);
|
|
|
98 |
break;
|
|
|
99 |
case 'masque.sto' :
|
|
|
100 |
$this->ajouterFiltreMasque('statut_origine', $val);
|
|
|
101 |
break;
|
|
|
102 |
case 'masque.sti' :
|
|
|
103 |
$this->ajouterFiltreMasque('statut_introduction', $val);
|
|
|
104 |
break;
|
|
|
105 |
case 'masque.stc' :
|
|
|
106 |
$this->ajouterFiltreMasque('statut_culture', $val);
|
|
|
107 |
break;
|
|
|
108 |
case 'masque.and' :
|
|
|
109 |
$this->requete_condition []= " annee >= ".$this->getBdd()->proteger($val);
|
|
|
110 |
break;
|
|
|
111 |
case 'masque.anf' :
|
|
|
112 |
$this->requete_condition []= " annee <= ".$this->getBdd()->proteger($val);
|
|
|
113 |
break;
|
3 |
jpm |
114 |
}
|
655 |
jpm |
115 |
|
3 |
jpm |
116 |
}
|
|
|
117 |
}
|
655 |
jpm |
118 |
|
3 |
jpm |
119 |
public function verifierParamChamps($param, $val) {
|
|
|
120 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
121 |
$champs_demandes = explode(',', $val);
|
|
|
122 |
$champs_verifies = array();
|
655 |
jpm |
123 |
$champs_api = array_flip($this->champs_api);
|
363 |
delphine |
124 |
$champs_supp = array('nom_retenu_complet'=>'num_nom_retenu', 'basionyme_complet'=>'basionyme');
|
|
|
125 |
$champs_api = array_merge($champs_api, $champs_supp);
|
3 |
jpm |
126 |
foreach ($champs_demandes as $champ) {
|
|
|
127 |
if (array_key_exists($champ, $champs_api)) {
|
|
|
128 |
$champs_verifies[] = $champs_api[$champ];
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
if (count($champs_verifies) > 0) {
|
|
|
132 |
$this->requete_champ .= ', '.implode(',', $champs_verifies);
|
|
|
133 |
}
|
655 |
jpm |
134 |
}
|
|
|
135 |
|
3 |
jpm |
136 |
/** Permet de rajouter à la requete sql le parametre distinct. N'est utilisé qu'avec le format oss */
|
567 |
mathilde |
137 |
public function ajouterNomDistinct($distinct) {
|
|
|
138 |
if (isset($distinct)) {
|
|
|
139 |
if ($distinct == 1 && $this->parametres['retour.format'] == 'oss') {
|
|
|
140 |
$this->distinct = ' distinct ';
|
|
|
141 |
} elseif ($distinct == 1 && $this->parametres['retour.format'] != 'oss') {
|
655 |
jpm |
142 |
$e = 'Erreur dans votre requête </br> L\'utilisation du paramètre distinct ne se fait que sous
|
3 |
jpm |
143 |
le format oss';
|
|
|
144 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
}
|
655 |
jpm |
148 |
|
3 |
jpm |
149 |
//-----------------FONCTION D'ANALYSE DES RESSOURCES--------------------------------------------------------------------
|
|
|
150 |
|
|
|
151 |
public function traiterRessourcesIdentifiant() {
|
|
|
152 |
//on initialise la condition de la requete sql et le format de réponse
|
|
|
153 |
$this->requete_condition = array(); //on vide la table dans le cas de plusieurs version
|
|
|
154 |
$this->requete_condition[] = 'num_nom = '.$this->getBdd()->proteger($this->ressources[0]);
|
|
|
155 |
$this->format_reponse = $this->service.'/id';
|
655 |
jpm |
156 |
if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
|
|
|
157 |
if ($this->ressources[1] == 'relations') {
|
3 |
jpm |
158 |
$this->traiterRessourceIdRelations();
|
|
|
159 |
} else {
|
|
|
160 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
|
|
161 |
<li> noms/#id/relations </li> <li> noms/#id/#champ+#champ </li>
|
|
|
162 |
<li> noms/#id/relations/synonymie </li> <li> noms/#id/relations/flores </li>
|
|
|
163 |
<li> noms/#id/relations/homonymie </li>';
|
|
|
164 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
165 |
}
|
|
|
166 |
} else { // requete de type noms/#id : rajout du nom_sci pour récupérer le format html par la fct mettreAuFormat()
|
|
|
167 |
$this->requete_champ = ' *, nom_sci ';
|
|
|
168 |
}
|
|
|
169 |
}
|
655 |
jpm |
170 |
|
3 |
jpm |
171 |
public function traiterRessourceRelations() {
|
|
|
172 |
$this->format_reponse .= '/relations';
|
|
|
173 |
$projet = $this->ressources[1];
|
|
|
174 |
$num_nom = $this->ressources[2];
|
|
|
175 |
if (strrpos($num_nom, 'nn.coste') !== false) {
|
|
|
176 |
list($p, $nn) = explode('=', $num_nom);
|
|
|
177 |
$num_nom = $nn;
|
655 |
jpm |
178 |
}
|
3 |
jpm |
179 |
$champ = "flore_$projet"."_num";
|
|
|
180 |
if (isset($this->ressources[3])) {
|
|
|
181 |
$type = $this->ressources[3];
|
|
|
182 |
if (!in_array($type, array('homonymie', 'synonymie', 'flores'))) {
|
|
|
183 |
$e = "Les types disponibles pour les noms sont homonymie, synonymie et flores";
|
|
|
184 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
185 |
}
|
655 |
jpm |
186 |
}
|
3 |
jpm |
187 |
$this->requete_champ = ' num_nom ';
|
|
|
188 |
$this->requete_condition = array();
|
|
|
189 |
$this->requete_condition[] = "$champ = ".$this->getBdd()->proteger($num_nom);
|
|
|
190 |
}
|
655 |
jpm |
191 |
|
3 |
jpm |
192 |
public function traiterRessourceIdRelations() {
|
|
|
193 |
$this->format_reponse .= '/relations';
|
|
|
194 |
if (isset($this->ressources[2]) && !empty($this->ressources[2])) {
|
|
|
195 |
// requete de type noms/#id/relations/#relation
|
|
|
196 |
switch ($this->ressources[2]) {
|
655 |
jpm |
197 |
case 'synonymie' :
|
3 |
jpm |
198 |
$this->traiterRessourceIdSynonymie();
|
|
|
199 |
break;
|
|
|
200 |
case 'flores' :
|
|
|
201 |
$this->traiterRessourceIdFlores();
|
655 |
jpm |
202 |
break;
|
3 |
jpm |
203 |
case 'homonymie' :
|
|
|
204 |
$this->traiterRessourceIdHomonymie();
|
|
|
205 |
break;
|
655 |
jpm |
206 |
default :
|
3 |
jpm |
207 |
$e = 'Erreur dans votre requête </br> Ressources disponibles : <br/>
|
655 |
jpm |
208 |
<li> noms/#id/relations </li> <li> noms/#id/relations/synonymie </li>
|
3 |
jpm |
209 |
<li> noms/#id/relations/flores </li> <li> noms/#id/relations/homonymie </li>';
|
655 |
jpm |
210 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
3 |
jpm |
211 |
break;
|
|
|
212 |
}
|
655 |
jpm |
213 |
}
|
3 |
jpm |
214 |
}
|
655 |
jpm |
215 |
|
3 |
jpm |
216 |
public function traiterRessourceIdSynonymie() {
|
|
|
217 |
// SELECT num_nom, nom_sci, num_nom_retenu, basionyme FROM bdtfx_v2_00 WHERE num_nom = X LIMIT 0,100;
|
|
|
218 |
$this->format_reponse .= '/synonymie';
|
|
|
219 |
if (strrpos($this->requete_champ, ', basionyme') === false) {
|
|
|
220 |
$this->requete_champ .= ', basionyme ';
|
|
|
221 |
}
|
|
|
222 |
$this->requete_condition[0] = 'num_nom_retenu = '.
|
|
|
223 |
'(SELECT num_nom_retenu FROM '.$this->table.' WHERE '.$this->requete_condition[0].')';
|
|
|
224 |
}
|
655 |
jpm |
225 |
|
3 |
jpm |
226 |
public function traiterRessourceIdHomonymie() {
|
|
|
227 |
// 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);
|
|
|
228 |
$this->format_reponse .= '/homonymie';
|
|
|
229 |
$this->requete_condition[0] = 'nom_sci = (SELECT nom_sci FROM '.$this->table
|
|
|
230 |
.' WHERE '.$this->requete_condition[0].')';
|
|
|
231 |
}
|
655 |
jpm |
232 |
|
3 |
jpm |
233 |
public function traiterRessourceIdFlores() {
|
|
|
234 |
$champ_flores = '';
|
|
|
235 |
foreach ($this->champs_table as $champ) {
|
|
|
236 |
if (preg_match('/^flore_.*$/', $champ)) {
|
|
|
237 |
$champ_flores .= ', '.$champ;
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
$this->format_reponse .= '/flores';
|
|
|
241 |
$this->requete_champ = 'num_nom'.$champ_flores;
|
|
|
242 |
}
|
655 |
jpm |
243 |
|
3 |
jpm |
244 |
public function traiterRessourceStatsRangs() {
|
|
|
245 |
// SELECT count(*) as nombre, rang FROM bdtfx_v2_00 [WHERE rang = 290] GROUP BY rang ORDER BY rang;
|
|
|
246 |
$this->format_reponse .= '/rangs';
|
655 |
jpm |
247 |
$this->requete_champ = 'count(*) as nombre, rang ';
|
3 |
jpm |
248 |
$this->requete_group_by = ' GROUP BY rang ORDER BY rang ';
|
|
|
249 |
}
|
655 |
jpm |
250 |
|
3 |
jpm |
251 |
public function traiterRessourceStatsAnnees() {
|
|
|
252 |
// SELECT count(*) as nombre, annee FROM bdtfx_v2_00 GROUP BY annee ORDER BY annee;
|
|
|
253 |
$this->format_reponse .= '/annees';
|
|
|
254 |
$this->requete_champ = 'count(*) as nombre, annee ';
|
|
|
255 |
$this->requete_condition = null;
|
655 |
jpm |
256 |
$this->requete_group_by = ' GROUP BY annee ORDER BY annee ';
|
3 |
jpm |
257 |
}
|
655 |
jpm |
258 |
|
3 |
jpm |
259 |
public function traiterRessourceStatsInitiales() {
|
|
|
260 |
// SELECT count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre GROUP BY rang, left(nom_sci, 2);
|
|
|
261 |
$this->format_reponse .= '/initiales';
|
655 |
jpm |
262 |
$this->requete_champ = 'count(left( nom_sci, 2 )) as nb, rang, left(nom_sci, 2) as lettre ';
|
3 |
jpm |
263 |
$this->requete_group_by = ' GROUP BY rang, left(nom_sci, 2)';
|
|
|
264 |
}
|
655 |
jpm |
265 |
|
|
|
266 |
|
|
|
267 |
|
3 |
jpm |
268 |
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
|
655 |
jpm |
269 |
|
3 |
jpm |
270 |
public function assemblerLaRequete() {
|
|
|
271 |
if ( strrpos($this->format_reponse, 'noms/stats/') === false ) {
|
|
|
272 |
$this->mettreAuFormat(); //Ds CommunNomsTaxons.php
|
|
|
273 |
}
|
660 |
jpm |
274 |
$requete = 'SELECT '.$this->retournerChamps().' '.
|
|
|
275 |
"FROM {$this->table} ".
|
|
|
276 |
$this->retournerRequeteCondition().' '.
|
|
|
277 |
$this->requete_group_by.' '.
|
|
|
278 |
$this->retournerOrderBy().' '.
|
740 |
raphael |
279 |
$this->formerRequeteLimite() .
|
|
|
280 |
' -- ' . __FILE__ . ':' . __LINE__ ;
|
655 |
jpm |
281 |
return $requete;
|
660 |
jpm |
282 |
}
|
655 |
jpm |
283 |
|
660 |
jpm |
284 |
public function retournerChamps() {
|
|
|
285 |
$sql = '';
|
|
|
286 |
if ($this->distinct) {
|
|
|
287 |
$sql .= $this->distinct.' ';
|
|
|
288 |
}
|
|
|
289 |
if ($this->requete_champ) {
|
|
|
290 |
$sql .= $this->requete_champ.' ';
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
// Champs "virtuels" pour tier sur l'ensemble des résultats
|
|
|
294 |
if (isset($this->parametres['retour.tri'])) {
|
|
|
295 |
list($champ, $ordre) = $this->decouperParametreRetourTri();
|
|
|
296 |
if ($champ == 'retenu') {
|
|
|
297 |
$sql .= ", IF(num_nom = num_nom_retenu, '0', '1') AS nom_retenu_tri ";
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
return $sql;
|
3 |
jpm |
302 |
}
|
|
|
303 |
|
660 |
jpm |
304 |
public function decouperParametreRetourTri() {
|
|
|
305 |
$tri = array('', '');
|
|
|
306 |
if (isset($this->parametres['retour.tri'])) {
|
|
|
307 |
if (preg_match('/^(retenu)(?:,(ASC|DESC)|)$/', $this->parametres['retour.tri'], $match))
|
|
|
308 |
$tri[0] = $match[1];
|
|
|
309 |
$tri[1] = isset($match[2]) ? $match[2] : '';
|
|
|
310 |
}
|
|
|
311 |
return $tri;
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public function retournerRequeteCondition() {
|
|
|
315 |
$condition = '';
|
|
|
316 |
if ($this->requete_condition) {
|
|
|
317 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
318 |
}
|
|
|
319 |
return $condition;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
public function retournerOrderBy() {
|
|
|
323 |
$orderBy = array();
|
|
|
324 |
|
|
|
325 |
// Tri sur l'ensemble des résultats
|
|
|
326 |
if (isset($this->parametres['retour.tri'])) {
|
|
|
327 |
list($champ, $ordre) = $this->decouperParametreRetourTri();
|
|
|
328 |
if ($champ == 'retenu') {
|
|
|
329 |
$orderBy[] = "nom_retenu_tri $ordre";
|
|
|
330 |
}
|
|
|
331 |
}
|
|
|
332 |
// Tri par défaut
|
|
|
333 |
if ($this->format_reponse == 'noms') {
|
|
|
334 |
$orderBy[] = 'nom_sci ASC';
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
$sql = '';
|
672 |
jpm |
338 |
if (count($orderBy) > 0) {
|
660 |
jpm |
339 |
$sql = 'ORDER BY '.implode(', ', $orderBy).' ';
|
|
|
340 |
}
|
|
|
341 |
return $sql;
|
|
|
342 |
}
|
|
|
343 |
|
3 |
jpm |
344 |
public function formerRequeteLimite() {
|
655 |
jpm |
345 |
if ($this->format_reponse != 'noms' && $this->format_reponse != 'noms/id/relations/synonymie'
|
660 |
jpm |
346 |
&& $this->format_reponse != 'noms/id/relations/homonymie') {
|
655 |
jpm |
347 |
$this->requete_limite = '';
|
3 |
jpm |
348 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
655 |
jpm |
349 |
$this->limite_requete['depart'] =
|
660 |
jpm |
350 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
655 |
jpm |
351 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
3 |
jpm |
352 |
} else {
|
655 |
jpm |
353 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
3 |
jpm |
354 |
}
|
|
|
355 |
return $this->requete_limite;
|
|
|
356 |
}
|
655 |
jpm |
357 |
|
3 |
jpm |
358 |
/** Recupere le nombre total de résultat d'une requete lancée. */
|
|
|
359 |
public function recupererTotalResultat() {
|
|
|
360 |
$total = null;
|
|
|
361 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.$this->retournerRequeteCondition().$this->requete_group_by;
|
|
|
362 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
363 |
if ($res) {
|
|
|
364 |
$total = $res['nombre'];
|
|
|
365 |
} else {
|
|
|
366 |
$e = 'Fct recupererTotalResultat() : <br/>Données introuvables dans la base';
|
|
|
367 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
368 |
}
|
|
|
369 |
return $total;
|
|
|
370 |
}
|
655 |
jpm |
371 |
|
|
|
372 |
|
3 |
jpm |
373 |
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
|
655 |
jpm |
374 |
|
272 |
delphine |
375 |
public function retournerResultatFormate($resultat) {
|
740 |
raphael |
376 |
|
3 |
jpm |
377 |
switch ($this->format_reponse) {
|
|
|
378 |
case 'noms/relations' :
|
|
|
379 |
$reponse = $this->formaterRelations($resultat[0]);
|
|
|
380 |
break;
|
|
|
381 |
case 'noms/id' : //ds CommunNomsTaxons
|
|
|
382 |
$reponse = $this->formaterId($resultat[0]);
|
|
|
383 |
break;
|
|
|
384 |
case 'noms/id/relations' :
|
|
|
385 |
$reponse = $this->formaterIdRelations($resultat[0]);
|
655 |
jpm |
386 |
break;
|
3 |
jpm |
387 |
case 'noms/id/relations/synonymie' :
|
|
|
388 |
$reponse = $this->formaterIdSynonymie($resultat);
|
|
|
389 |
break;
|
|
|
390 |
case 'noms/id/relations/homonymie' :
|
|
|
391 |
$reponse = $this->formaterIdHomonymie($resultat);
|
|
|
392 |
break;
|
|
|
393 |
case 'noms/id/relations/flores' : //ds CommunsNomsTaxons
|
|
|
394 |
$reponse = $this->formaterIdFlores($resultat[0]);
|
|
|
395 |
break;
|
|
|
396 |
case 'noms/stats/annees' : //ds CommunNomsTaxons
|
|
|
397 |
$reponse = $this->formaterStatsAnnee($resultat);
|
|
|
398 |
break;
|
|
|
399 |
case 'noms/stats/rangs' : //ds CommunNomsTaxons
|
|
|
400 |
$reponse = $this->formaterStatsRang($resultat);
|
|
|
401 |
break;
|
|
|
402 |
case 'noms/stats/initiales' : //ds CommunNomsTaxons
|
|
|
403 |
$reponse = $this->formaterStatsInitiales($resultat);
|
|
|
404 |
break;
|
|
|
405 |
case 'noms' :
|
|
|
406 |
$reponse = $this->formaterNoms($resultat);
|
|
|
407 |
break;
|
|
|
408 |
}
|
|
|
409 |
return $reponse;
|
|
|
410 |
}
|
655 |
jpm |
411 |
|
3 |
jpm |
412 |
//+---------------------concerne les resultats pour des requetes de type noms/id-----------------------------+
|
655 |
jpm |
413 |
|
3 |
jpm |
414 |
public function formaterRelations($resultat) {
|
|
|
415 |
$num_nom = $resultat['num_nom'];
|
|
|
416 |
if (isset($this->ressources[3])) {
|
|
|
417 |
$url = Config::get('url_service').$this->service."/$num_nom/relations";
|
|
|
418 |
} else {
|
|
|
419 |
$type = $this->ressources[3];
|
|
|
420 |
$url = Config::get('url_service')."/$this->service/$num_nom/relations/$type";
|
|
|
421 |
}
|
|
|
422 |
$res = $this->consulterHref($url);
|
|
|
423 |
return $res;
|
655 |
jpm |
424 |
}
|
|
|
425 |
|
3 |
jpm |
426 |
public function formaterIdRelations($resultat) {
|
|
|
427 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
655 |
jpm |
428 |
$this->resultat_req = $resultat;
|
3 |
jpm |
429 |
$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
|
655 |
jpm |
430 |
|
3 |
jpm |
431 |
//on recupère le resultat de chaque relation (appel du WS correspondant)
|
272 |
delphine |
432 |
$flores = $this->ajouterRelations('flores');
|
3 |
jpm |
433 |
if (isset($flores)) $retour_id_rel['resultat']['flores'] = $flores;
|
272 |
delphine |
434 |
$homonymes = $this->ajouterRelations('homonymie');
|
3 |
jpm |
435 |
if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
|
272 |
delphine |
436 |
$synonymes = $this->ajouterRelations('synonymie');
|
3 |
jpm |
437 |
if (isset($synonymes)) $retour_id_rel['resultat']['synonymes'] = $synonymes;
|
655 |
jpm |
438 |
|
3 |
jpm |
439 |
//on renvoit null si il n'existe aucune relations (on efface l'entete en premier lieu)
|
|
|
440 |
if (!isset($retour_id_rel['resultat'])) {
|
655 |
jpm |
441 |
$retour_id_rel = null;
|
3 |
jpm |
442 |
} else { //on rajoute l'entete si des relations existent
|
655 |
jpm |
443 |
$this->afficherDonnees('num_nom', $this->ressources[0]);
|
3 |
jpm |
444 |
$retour_id_rel['entete'] = $this->table_retour;
|
|
|
445 |
$this->table_retour = array();
|
|
|
446 |
}
|
|
|
447 |
return $retour_id_rel;
|
|
|
448 |
}
|
655 |
jpm |
449 |
|
3 |
jpm |
450 |
/**
|
655 |
jpm |
451 |
* Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
|
3 |
jpm |
452 |
* flores) par l'appel du web service [version]/noms/#id/relations/[type_relation]
|
|
|
453 |
*/
|
272 |
delphine |
454 |
public function ajouterRelations($relation) {
|
|
|
455 |
$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
|
3 |
jpm |
456 |
$res = null;
|
|
|
457 |
$parametres_url = '';
|
|
|
458 |
if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
|
272 |
delphine |
459 |
$url = Config::get('url_service').'/'.$this->service.'/'
|
3 |
jpm |
460 |
.$this->ressources[0].'/relations/'
|
272 |
delphine |
461 |
.$relation.$parametres_url; Debug::printr($url);
|
655 |
jpm |
462 |
|
3 |
jpm |
463 |
$relation = $this->consulterHref($url);
|
655 |
jpm |
464 |
|
3 |
jpm |
465 |
$res = $relation->resultat;
|
|
|
466 |
return $res;
|
|
|
467 |
}
|
655 |
jpm |
468 |
|
|
|
469 |
|
3 |
jpm |
470 |
public function formaterIdSynonymie($resultat) {
|
|
|
471 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
472 |
$retour_id_syn = array();
|
963 |
raphael |
473 |
if ($resultat[0]['num_nom_retenu'] == '') return array('nom_retenu N.D.');
|
|
|
474 |
|
|
|
475 |
// 1 ou + résultat(s)
|
|
|
476 |
$retour_id_syn['entete'] = $this->afficherEnteteResultat('/'.$this->service.'/'.$this->ressources[0].'/relations/synonymie');
|
|
|
477 |
$retour_id_syn['entete']['id'] = $this->ressources[0];
|
|
|
478 |
$retour_id_syn['resultat'] = array();
|
|
|
479 |
|
|
|
480 |
// résultat contient aussi l'original
|
|
|
481 |
if(count($resultat) > 1) {
|
655 |
jpm |
482 |
//on remplit d'abord l'entete du resultat
|
3 |
jpm |
483 |
foreach ($resultat as $tab) {
|
|
|
484 |
//pour chaque basionyme, on recupère le résultat : num_nom, nom_sci, basionyme et num_nom_retenu :
|
655 |
jpm |
485 |
$this->resultat_req = $tab;
|
3 |
jpm |
486 |
$num = $tab['num_nom'];
|
|
|
487 |
$this->afficherNomHrefRetenu($tab, $num);
|
655 |
jpm |
488 |
$this->afficherDonnees('basionyme', $tab['basionyme']);
|
3 |
jpm |
489 |
$retour_id_syn['resultat'][$num] = $this->table_retour;
|
|
|
490 |
$this->table_retour = array();
|
|
|
491 |
}
|
|
|
492 |
if (!isset($retour_id_syn['resultat']) && !in_array('nom_retenu N.D.', $retour_id_syn)) {
|
|
|
493 |
$retour_id_syn = null; //on initialise le resultat à null
|
655 |
jpm |
494 |
}
|
3 |
jpm |
495 |
}
|
|
|
496 |
return $retour_id_syn;
|
|
|
497 |
}
|
655 |
jpm |
498 |
|
3 |
jpm |
499 |
public function formaterIdHomonymie($resultat) {
|
|
|
500 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
272 |
delphine |
501 |
if (count($resultat) != 1) {
|
3 |
jpm |
502 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
503 |
$this->afficherEnteteResultat($resultat, '/'.$this->service.'/'.$this->ressources[0].'/relations/homonymie');
|
|
|
504 |
$retour_id_hom['entete'] = $this->table_retour;
|
|
|
505 |
$this->table_retour = array();
|
|
|
506 |
foreach ($resultat as $homonyme) {
|
|
|
507 |
$this->resultat_req = $homonyme;
|
|
|
508 |
$id = $homonyme['num_nom'];
|
|
|
509 |
$this->afficherDonnees('num_nom', $id);
|
|
|
510 |
if ($homonyme['num_nom_retenu'] != '') {
|
562 |
delphine |
511 |
$retenu = ($id == $homonyme['num_nom_retenu']) ? 'true' : 'false';
|
|
|
512 |
} else {
|
|
|
513 |
$retenu = 'absent';
|
|
|
514 |
}
|
655 |
jpm |
515 |
$this->table_retour['retenu'] = $retenu;
|
3 |
jpm |
516 |
$retour_id_hom['resultat'][$id] = $this->table_retour;
|
|
|
517 |
unset($retour_id_hom['resultat'][$id]['id']);
|
|
|
518 |
$this->table_retour = array();
|
|
|
519 |
}
|
533 |
gduche |
520 |
} else {
|
655 |
jpm |
521 |
$retour_id_hom = null;
|
3 |
jpm |
522 |
}
|
|
|
523 |
return $retour_id_hom;
|
|
|
524 |
}
|
655 |
jpm |
525 |
|
357 |
delphine |
526 |
public function obtenirSynonymesParNumNomAvecInfosFlore($num_nom, $version='1_02') {
|
655 |
jpm |
527 |
|
|
|
528 |
$champs_flore = 'flore_bonnier_num, flore_bonnier_rem,'.
|
306 |
aurelien |
529 |
'flore_cnrs_num, flore_cnrs_rem '.
|
|
|
530 |
'flore_fe_num, flore_fe_rem '.
|
655 |
jpm |
531 |
'flore_coste_num, flore_coste_rem '.
|
|
|
532 |
'flore_fh_num, flore_fh_rem '.
|
306 |
aurelien |
533 |
'flore_fournier_num, flore_fournier_rem';
|
655 |
jpm |
534 |
|
306 |
aurelien |
535 |
$requete = 'SELECT num_nom, nom_sci, '.$champs_flore.' '.
|
357 |
delphine |
536 |
'FROM '.$this->table.' '.
|
306 |
aurelien |
537 |
'WHERE num_nom_retenu = '.
|
|
|
538 |
'('.
|
357 |
delphine |
539 |
'SELECT num_nom_retenu FROM '.$this->table.' WHERE num_nom = "'.$num_nom.'"'.
|
306 |
aurelien |
540 |
')';
|
655 |
jpm |
541 |
|
740 |
raphael |
542 |
return $this->getBdd()->recupererTous($requete . ' -- ' . __FILE__ . ':' . __LINE__ );
|
306 |
aurelien |
543 |
}
|
655 |
jpm |
544 |
|
3 |
jpm |
545 |
public function formaterIdFlores($resultat) {
|
|
|
546 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp,noms_projets');
|
655 |
jpm |
547 |
$this->resultat_req = $resultat;
|
3 |
jpm |
548 |
$id = array_shift($resultat);
|
|
|
549 |
$reponse['entete']['id'] = $id;
|
306 |
aurelien |
550 |
$synonymes_flores = $this->obtenirSynonymesParNumNomAvecInfosFlore($this->ressources[0]);
|
|
|
551 |
if(is_array($synonymes_flores)) {
|
|
|
552 |
foreach ($synonymes_flores as $synonyme) {
|
|
|
553 |
$nom_sci = $synonyme['nom_sci'];
|
|
|
554 |
$num_nom = $synonyme['num_nom'];
|
|
|
555 |
unset($synonyme['nom_sci']);
|
|
|
556 |
unset($synonyme['num_nom']);
|
|
|
557 |
foreach ($synonyme as $flores => $valeur) {
|
|
|
558 |
if ($valeur != '' && $valeur != '0') {
|
|
|
559 |
$this->afficherInfosFlore($synonyme, $flores, $valeur, $nom_sci, $num_nom);
|
|
|
560 |
}
|
|
|
561 |
}
|
3 |
jpm |
562 |
}
|
|
|
563 |
}
|
306 |
aurelien |
564 |
|
3 |
jpm |
565 |
if ($this->table_retour != array()) {
|
|
|
566 |
$reponse['resultat'] = $this->table_retour;
|
|
|
567 |
$this->table_retour = array();
|
655 |
jpm |
568 |
} else {
|
|
|
569 |
$reponse = null;
|
3 |
jpm |
570 |
}
|
|
|
571 |
return $reponse;
|
|
|
572 |
}
|
655 |
jpm |
573 |
|
306 |
aurelien |
574 |
public function getNomCompletFlore($flore) {
|
|
|
575 |
return Config::get($flore.'_texte');
|
|
|
576 |
}
|
655 |
jpm |
577 |
|
306 |
aurelien |
578 |
public function afficherInfosFlore(&$resultat, $flores, $valeur, $nom_sci, $num_nom) {
|
655 |
jpm |
579 |
$flore = substr($flores,0,strrpos($flores, '_'));
|
3 |
jpm |
580 |
$projet = $this->noms_projets[$flore];
|
655 |
jpm |
581 |
|
306 |
aurelien |
582 |
//TODO voir si l'on peut factoriser les affectations à la table retour
|
|
|
583 |
// et simplifier ce gros pavé
|
655 |
jpm |
584 |
if (strrpos($flores, 'num') !== false) {
|
|
|
585 |
if (preg_match('/^([0-9]+)(?:[.]syn[^a-z]*|(.*))?$/', $valeur, $match)) {
|
306 |
aurelien |
586 |
$this->table_retour[$num_nom][$flore]['id'] = $match[1];
|
3 |
jpm |
587 |
if ($projet == 'coste') {
|
306 |
aurelien |
588 |
$this->table_retour[$num_nom][$flore]['href'] = $this->ajouterHrefAutreProjet('noms', 'nn_coste:', $match[1], $projet);
|
3 |
jpm |
589 |
}
|
306 |
aurelien |
590 |
if (isset($match[2]) && $match[2] != '') $this->table_retour[$num_nom][$flore]['cle'] = $match[2];
|
|
|
591 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
592 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
655 |
jpm |
593 |
}
|
3 |
jpm |
594 |
if (isset($resultat[$flore.'_rem']) && !empty($resultat[$flore.'_rem'])) {
|
306 |
aurelien |
595 |
$this->table_retour[$num_nom][$flore]['remarque'] = $resultat[$flore.'_rem'];
|
|
|
596 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
597 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
3 |
jpm |
598 |
unset($resultat[$flore.'_rem']);
|
|
|
599 |
}
|
|
|
600 |
} elseif (strrpos($flores,'belge') !== false) {
|
|
|
601 |
if (preg_match('/^([0-9]+) (R|S)?$/', $valeur, $match)) {
|
|
|
602 |
if (isset($match[2])) $type = ($match[2] == 'R') ? 'taxons' : 'synonyme';
|
306 |
aurelien |
603 |
$this->table_retour[$num_nom][$flore]['page'] = $match[1];
|
|
|
604 |
$this->table_retour[$num_nom][$flore]['type'] = $type;
|
|
|
605 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
606 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
3 |
jpm |
607 |
}
|
|
|
608 |
}
|
655 |
jpm |
609 |
}
|
|
|
610 |
|
3 |
jpm |
611 |
//+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
|
|
|
612 |
|
566 |
aurelien |
613 |
public function formaterNoms($resultat) {
|
3 |
jpm |
614 |
if ($this->parametres['retour.format'] == 'oss') {
|
|
|
615 |
$reponse = $this->formaterEnOss($resultat); //Ds CommunNomsTaxons.php
|
|
|
616 |
} else {
|
|
|
617 |
$reponse = $this->formaterEnJsonMax($resultat);
|
|
|
618 |
}
|
|
|
619 |
return $reponse;
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
public function formaterEnJsonMax($resultat) {
|
|
|
623 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
660 |
jpm |
624 |
|
952 |
raphael |
625 |
// TODO : améliorer le tri des résultats
|
660 |
jpm |
626 |
// ATTENTION : ce comportement est étrange
|
3 |
jpm |
627 |
$masque = $this->recupererMasquePrincipal();
|
952 |
raphael |
628 |
if ($masque && isset($this->parametres[$masque[0]] /* à éclaircir */ ) && !isset($this->parametres['retour.tri'])) {
|
3 |
jpm |
629 |
$resultat = $this->trierRechercheFloue($this->parametres[$masque[0]], $resultat, $masque[1]);
|
|
|
630 |
}
|
660 |
jpm |
631 |
|
963 |
raphael |
632 |
$table_retour_json['entete'] = $this->afficherEnteteResultat('/'.$this->service);
|
655 |
jpm |
633 |
$table_retour_json['resultat'] = $this->remplirJsonResultat($resultat);
|
606 |
mathilde |
634 |
return $table_retour_json;
|
|
|
635 |
}
|
|
|
636 |
|
|
|
637 |
public function remplirJsonResultat($resultat) {
|
3 |
jpm |
638 |
$champs = null;
|
|
|
639 |
if (array_key_exists('retour.champs', $this->parametres)) {
|
|
|
640 |
$champs = explode(',', $this->parametres['retour.champs']);
|
|
|
641 |
}
|
660 |
jpm |
642 |
|
655 |
jpm |
643 |
$noms = array();
|
3 |
jpm |
644 |
foreach ($resultat as $tab) {
|
|
|
645 |
$this->table_retour = array();
|
|
|
646 |
$num = $tab['num_nom'];
|
93 |
delphine |
647 |
$this->afficherNomHrefRetenu($tab, $num); // ajoute le nom_sci, href et si le nom est retenu dans $this->table_retour
|
|
|
648 |
$retour = $this->table_retour;
|
|
|
649 |
$this->table_retour = array();
|
|
|
650 |
if ($champs != null) {
|
|
|
651 |
$reponse_id = $this->formaterId($tab);
|
|
|
652 |
$this->table_retour = array();
|
|
|
653 |
$this->ajouterChampsPersonnalises($champs, $reponse_id);
|
|
|
654 |
$retour = array_merge($retour, $this->table_retour);
|
|
|
655 |
}
|
660 |
jpm |
656 |
$noms[$num] = $retour;
|
3 |
jpm |
657 |
}
|
655 |
jpm |
658 |
|
660 |
jpm |
659 |
return $noms;
|
3 |
jpm |
660 |
}
|
|
|
661 |
}
|
|
|
662 |
?>
|