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().' '.
|
|
|
279 |
$this->formerRequeteLimite();
|
|
|
280 |
// Debug::printr($requete);
|
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 = '';
|
|
|
338 |
if (count($orderBy > 0)) {
|
|
|
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) {
|
3 |
jpm |
376 |
switch ($this->format_reponse) {
|
|
|
377 |
case 'noms/relations' :
|
|
|
378 |
$reponse = $this->formaterRelations($resultat[0]);
|
|
|
379 |
break;
|
|
|
380 |
case 'noms/id' : //ds CommunNomsTaxons
|
|
|
381 |
$reponse = $this->formaterId($resultat[0]);
|
|
|
382 |
break;
|
|
|
383 |
case 'noms/id/relations' :
|
|
|
384 |
$reponse = $this->formaterIdRelations($resultat[0]);
|
655 |
jpm |
385 |
break;
|
3 |
jpm |
386 |
case 'noms/id/relations/synonymie' :
|
|
|
387 |
$reponse = $this->formaterIdSynonymie($resultat);
|
|
|
388 |
break;
|
|
|
389 |
case 'noms/id/relations/homonymie' :
|
|
|
390 |
$reponse = $this->formaterIdHomonymie($resultat);
|
|
|
391 |
break;
|
|
|
392 |
case 'noms/id/relations/flores' : //ds CommunsNomsTaxons
|
|
|
393 |
$reponse = $this->formaterIdFlores($resultat[0]);
|
|
|
394 |
break;
|
|
|
395 |
case 'noms/stats/annees' : //ds CommunNomsTaxons
|
|
|
396 |
$reponse = $this->formaterStatsAnnee($resultat);
|
|
|
397 |
break;
|
|
|
398 |
case 'noms/stats/rangs' : //ds CommunNomsTaxons
|
|
|
399 |
$reponse = $this->formaterStatsRang($resultat);
|
|
|
400 |
break;
|
|
|
401 |
case 'noms/stats/initiales' : //ds CommunNomsTaxons
|
|
|
402 |
$reponse = $this->formaterStatsInitiales($resultat);
|
|
|
403 |
break;
|
|
|
404 |
case 'noms' :
|
|
|
405 |
$reponse = $this->formaterNoms($resultat);
|
|
|
406 |
break;
|
|
|
407 |
}
|
|
|
408 |
return $reponse;
|
|
|
409 |
}
|
655 |
jpm |
410 |
|
3 |
jpm |
411 |
//+---------------------concerne les resultats pour des requetes de type noms/id-----------------------------+
|
655 |
jpm |
412 |
|
3 |
jpm |
413 |
public function formaterRelations($resultat) {
|
|
|
414 |
$num_nom = $resultat['num_nom'];
|
|
|
415 |
if (isset($this->ressources[3])) {
|
|
|
416 |
$url = Config::get('url_service').$this->service."/$num_nom/relations";
|
|
|
417 |
} else {
|
|
|
418 |
$type = $this->ressources[3];
|
|
|
419 |
$url = Config::get('url_service')."/$this->service/$num_nom/relations/$type";
|
|
|
420 |
}
|
|
|
421 |
$res = $this->consulterHref($url);
|
|
|
422 |
return $res;
|
655 |
jpm |
423 |
}
|
|
|
424 |
|
3 |
jpm |
425 |
public function formaterIdRelations($resultat) {
|
|
|
426 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
655 |
jpm |
427 |
$this->resultat_req = $resultat;
|
3 |
jpm |
428 |
$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
|
655 |
jpm |
429 |
|
3 |
jpm |
430 |
//on recupère le resultat de chaque relation (appel du WS correspondant)
|
272 |
delphine |
431 |
$flores = $this->ajouterRelations('flores');
|
3 |
jpm |
432 |
if (isset($flores)) $retour_id_rel['resultat']['flores'] = $flores;
|
272 |
delphine |
433 |
$homonymes = $this->ajouterRelations('homonymie');
|
3 |
jpm |
434 |
if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
|
272 |
delphine |
435 |
$synonymes = $this->ajouterRelations('synonymie');
|
3 |
jpm |
436 |
if (isset($synonymes)) $retour_id_rel['resultat']['synonymes'] = $synonymes;
|
655 |
jpm |
437 |
|
3 |
jpm |
438 |
//on renvoit null si il n'existe aucune relations (on efface l'entete en premier lieu)
|
|
|
439 |
if (!isset($retour_id_rel['resultat'])) {
|
655 |
jpm |
440 |
$retour_id_rel = null;
|
3 |
jpm |
441 |
} else { //on rajoute l'entete si des relations existent
|
655 |
jpm |
442 |
$this->afficherDonnees('num_nom', $this->ressources[0]);
|
3 |
jpm |
443 |
$retour_id_rel['entete'] = $this->table_retour;
|
|
|
444 |
$this->table_retour = array();
|
|
|
445 |
}
|
|
|
446 |
return $retour_id_rel;
|
|
|
447 |
}
|
655 |
jpm |
448 |
|
3 |
jpm |
449 |
/**
|
655 |
jpm |
450 |
* Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
|
3 |
jpm |
451 |
* flores) par l'appel du web service [version]/noms/#id/relations/[type_relation]
|
|
|
452 |
*/
|
272 |
delphine |
453 |
public function ajouterRelations($relation) {
|
|
|
454 |
$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
|
3 |
jpm |
455 |
$res = null;
|
|
|
456 |
$parametres_url = '';
|
|
|
457 |
if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
|
272 |
delphine |
458 |
$url = Config::get('url_service').'/'.$this->service.'/'
|
3 |
jpm |
459 |
.$this->ressources[0].'/relations/'
|
272 |
delphine |
460 |
.$relation.$parametres_url; Debug::printr($url);
|
655 |
jpm |
461 |
|
3 |
jpm |
462 |
$relation = $this->consulterHref($url);
|
655 |
jpm |
463 |
|
3 |
jpm |
464 |
$res = $relation->resultat;
|
|
|
465 |
return $res;
|
|
|
466 |
}
|
655 |
jpm |
467 |
|
|
|
468 |
|
3 |
jpm |
469 |
public function formaterIdSynonymie($resultat) {
|
|
|
470 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
471 |
$retour_id_syn = array();
|
|
|
472 |
if ($resultat[0]['num_nom_retenu'] == '') {
|
|
|
473 |
$retour_id_syn[] = 'nom_retenu N.D.';
|
655 |
jpm |
474 |
} elseif (count($resultat) != 1) {
|
|
|
475 |
//on remplit d'abord l'entete du resultat
|
3 |
jpm |
476 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
477 |
$this->afficherEnteteResultat('/'.$this->service.'/'.$this->ressources[0].'/relations/synonymie');
|
|
|
478 |
$retour_id_syn['entete'] = $this->table_retour;
|
|
|
479 |
$this->table_retour = array();
|
|
|
480 |
foreach ($resultat as $tab) {
|
|
|
481 |
//pour chaque basionyme, on recupère le résultat : num_nom, nom_sci, basionyme et num_nom_retenu :
|
655 |
jpm |
482 |
$this->resultat_req = $tab;
|
3 |
jpm |
483 |
$num = $tab['num_nom'];
|
|
|
484 |
$this->afficherNomHrefRetenu($tab, $num);
|
655 |
jpm |
485 |
$this->afficherDonnees('basionyme', $tab['basionyme']);
|
3 |
jpm |
486 |
$retour_id_syn['resultat'][$num] = $this->table_retour;
|
|
|
487 |
$this->table_retour = array();
|
|
|
488 |
}
|
|
|
489 |
if (!isset($retour_id_syn['resultat']) && !in_array('nom_retenu N.D.', $retour_id_syn)) {
|
|
|
490 |
$retour_id_syn = null; //on initialise le resultat à null
|
655 |
jpm |
491 |
}
|
3 |
jpm |
492 |
}
|
|
|
493 |
return $retour_id_syn;
|
|
|
494 |
}
|
655 |
jpm |
495 |
|
3 |
jpm |
496 |
public function formaterIdHomonymie($resultat) {
|
|
|
497 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
272 |
delphine |
498 |
if (count($resultat) != 1) {
|
3 |
jpm |
499 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
500 |
$this->afficherEnteteResultat($resultat, '/'.$this->service.'/'.$this->ressources[0].'/relations/homonymie');
|
|
|
501 |
$retour_id_hom['entete'] = $this->table_retour;
|
|
|
502 |
$this->table_retour = array();
|
|
|
503 |
foreach ($resultat as $homonyme) {
|
|
|
504 |
$this->resultat_req = $homonyme;
|
|
|
505 |
$id = $homonyme['num_nom'];
|
|
|
506 |
$this->afficherDonnees('num_nom', $id);
|
|
|
507 |
if ($homonyme['num_nom_retenu'] != '') {
|
562 |
delphine |
508 |
$retenu = ($id == $homonyme['num_nom_retenu']) ? 'true' : 'false';
|
|
|
509 |
} else {
|
|
|
510 |
$retenu = 'absent';
|
|
|
511 |
}
|
655 |
jpm |
512 |
$this->table_retour['retenu'] = $retenu;
|
3 |
jpm |
513 |
$retour_id_hom['resultat'][$id] = $this->table_retour;
|
|
|
514 |
unset($retour_id_hom['resultat'][$id]['id']);
|
|
|
515 |
$this->table_retour = array();
|
|
|
516 |
}
|
533 |
gduche |
517 |
} else {
|
655 |
jpm |
518 |
$retour_id_hom = null;
|
3 |
jpm |
519 |
}
|
|
|
520 |
return $retour_id_hom;
|
|
|
521 |
}
|
655 |
jpm |
522 |
|
357 |
delphine |
523 |
public function obtenirSynonymesParNumNomAvecInfosFlore($num_nom, $version='1_02') {
|
655 |
jpm |
524 |
|
|
|
525 |
$champs_flore = 'flore_bonnier_num, flore_bonnier_rem,'.
|
306 |
aurelien |
526 |
'flore_cnrs_num, flore_cnrs_rem '.
|
|
|
527 |
'flore_fe_num, flore_fe_rem '.
|
655 |
jpm |
528 |
'flore_coste_num, flore_coste_rem '.
|
|
|
529 |
'flore_fh_num, flore_fh_rem '.
|
306 |
aurelien |
530 |
'flore_fournier_num, flore_fournier_rem';
|
655 |
jpm |
531 |
|
306 |
aurelien |
532 |
$requete = 'SELECT num_nom, nom_sci, '.$champs_flore.' '.
|
357 |
delphine |
533 |
'FROM '.$this->table.' '.
|
306 |
aurelien |
534 |
'WHERE num_nom_retenu = '.
|
|
|
535 |
'('.
|
357 |
delphine |
536 |
'SELECT num_nom_retenu FROM '.$this->table.' WHERE num_nom = "'.$num_nom.'"'.
|
306 |
aurelien |
537 |
')';
|
655 |
jpm |
538 |
|
|
|
539 |
return $this->getBdd()->recupererTous($requete);
|
306 |
aurelien |
540 |
}
|
655 |
jpm |
541 |
|
3 |
jpm |
542 |
public function formaterIdFlores($resultat) {
|
|
|
543 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp,noms_projets');
|
655 |
jpm |
544 |
$this->resultat_req = $resultat;
|
3 |
jpm |
545 |
$id = array_shift($resultat);
|
|
|
546 |
$reponse['entete']['id'] = $id;
|
306 |
aurelien |
547 |
$synonymes_flores = $this->obtenirSynonymesParNumNomAvecInfosFlore($this->ressources[0]);
|
|
|
548 |
if(is_array($synonymes_flores)) {
|
|
|
549 |
foreach ($synonymes_flores as $synonyme) {
|
|
|
550 |
$nom_sci = $synonyme['nom_sci'];
|
|
|
551 |
$num_nom = $synonyme['num_nom'];
|
|
|
552 |
unset($synonyme['nom_sci']);
|
|
|
553 |
unset($synonyme['num_nom']);
|
|
|
554 |
foreach ($synonyme as $flores => $valeur) {
|
|
|
555 |
if ($valeur != '' && $valeur != '0') {
|
|
|
556 |
$this->afficherInfosFlore($synonyme, $flores, $valeur, $nom_sci, $num_nom);
|
|
|
557 |
}
|
|
|
558 |
}
|
3 |
jpm |
559 |
}
|
|
|
560 |
}
|
306 |
aurelien |
561 |
|
3 |
jpm |
562 |
if ($this->table_retour != array()) {
|
|
|
563 |
$reponse['resultat'] = $this->table_retour;
|
|
|
564 |
$this->table_retour = array();
|
655 |
jpm |
565 |
} else {
|
|
|
566 |
$reponse = null;
|
3 |
jpm |
567 |
}
|
|
|
568 |
return $reponse;
|
|
|
569 |
}
|
655 |
jpm |
570 |
|
306 |
aurelien |
571 |
public function getNomCompletFlore($flore) {
|
|
|
572 |
return Config::get($flore.'_texte');
|
|
|
573 |
}
|
655 |
jpm |
574 |
|
306 |
aurelien |
575 |
public function afficherInfosFlore(&$resultat, $flores, $valeur, $nom_sci, $num_nom) {
|
655 |
jpm |
576 |
$flore = substr($flores,0,strrpos($flores, '_'));
|
3 |
jpm |
577 |
$projet = $this->noms_projets[$flore];
|
655 |
jpm |
578 |
|
306 |
aurelien |
579 |
//TODO voir si l'on peut factoriser les affectations à la table retour
|
|
|
580 |
// et simplifier ce gros pavé
|
655 |
jpm |
581 |
if (strrpos($flores, 'num') !== false) {
|
|
|
582 |
if (preg_match('/^([0-9]+)(?:[.]syn[^a-z]*|(.*))?$/', $valeur, $match)) {
|
306 |
aurelien |
583 |
$this->table_retour[$num_nom][$flore]['id'] = $match[1];
|
3 |
jpm |
584 |
if ($projet == 'coste') {
|
306 |
aurelien |
585 |
$this->table_retour[$num_nom][$flore]['href'] = $this->ajouterHrefAutreProjet('noms', 'nn_coste:', $match[1], $projet);
|
3 |
jpm |
586 |
}
|
306 |
aurelien |
587 |
if (isset($match[2]) && $match[2] != '') $this->table_retour[$num_nom][$flore]['cle'] = $match[2];
|
|
|
588 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
589 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
655 |
jpm |
590 |
}
|
3 |
jpm |
591 |
if (isset($resultat[$flore.'_rem']) && !empty($resultat[$flore.'_rem'])) {
|
306 |
aurelien |
592 |
$this->table_retour[$num_nom][$flore]['remarque'] = $resultat[$flore.'_rem'];
|
|
|
593 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
594 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
3 |
jpm |
595 |
unset($resultat[$flore.'_rem']);
|
|
|
596 |
}
|
|
|
597 |
} elseif (strrpos($flores,'belge') !== false) {
|
|
|
598 |
if (preg_match('/^([0-9]+) (R|S)?$/', $valeur, $match)) {
|
|
|
599 |
if (isset($match[2])) $type = ($match[2] == 'R') ? 'taxons' : 'synonyme';
|
306 |
aurelien |
600 |
$this->table_retour[$num_nom][$flore]['page'] = $match[1];
|
|
|
601 |
$this->table_retour[$num_nom][$flore]['type'] = $type;
|
|
|
602 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
603 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
3 |
jpm |
604 |
}
|
|
|
605 |
}
|
655 |
jpm |
606 |
}
|
|
|
607 |
|
3 |
jpm |
608 |
//+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
|
|
|
609 |
|
566 |
aurelien |
610 |
public function formaterNoms($resultat) {
|
3 |
jpm |
611 |
if ($this->parametres['retour.format'] == 'oss') {
|
|
|
612 |
$reponse = $this->formaterEnOss($resultat); //Ds CommunNomsTaxons.php
|
|
|
613 |
} else {
|
|
|
614 |
$reponse = $this->formaterEnJsonMax($resultat);
|
|
|
615 |
}
|
|
|
616 |
return $reponse;
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
public function formaterEnJsonMax($resultat) {
|
|
|
620 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
660 |
jpm |
621 |
|
|
|
622 |
// TODO : améliorer le trie des résultats
|
|
|
623 |
// ATTENTION : ce comportement est étrange
|
3 |
jpm |
624 |
$masque = $this->recupererMasquePrincipal();
|
|
|
625 |
if (isset($masque)) {
|
|
|
626 |
$resultat = $this->trierRechercheFloue($this->parametres[$masque[0]], $resultat, $masque[1]);
|
|
|
627 |
}
|
660 |
jpm |
628 |
|
606 |
mathilde |
629 |
$table_retour_json['entete'] = $this->remplirJsonEntete();
|
655 |
jpm |
630 |
$table_retour_json['resultat'] = $this->remplirJsonResultat($resultat);
|
606 |
mathilde |
631 |
return $table_retour_json;
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
public function remplirJsonResultat($resultat) {
|
3 |
jpm |
635 |
$champs = null;
|
|
|
636 |
if (array_key_exists('retour.champs', $this->parametres)) {
|
|
|
637 |
$champs = explode(',', $this->parametres['retour.champs']);
|
|
|
638 |
}
|
660 |
jpm |
639 |
|
655 |
jpm |
640 |
$noms = array();
|
3 |
jpm |
641 |
foreach ($resultat as $tab) {
|
|
|
642 |
$this->table_retour = array();
|
|
|
643 |
$num = $tab['num_nom'];
|
93 |
delphine |
644 |
$this->afficherNomHrefRetenu($tab, $num); // ajoute le nom_sci, href et si le nom est retenu dans $this->table_retour
|
|
|
645 |
$retour = $this->table_retour;
|
|
|
646 |
$this->table_retour = array();
|
|
|
647 |
if ($champs != null) {
|
|
|
648 |
$reponse_id = $this->formaterId($tab);
|
|
|
649 |
$this->table_retour = array();
|
|
|
650 |
$this->ajouterChampsPersonnalises($champs, $reponse_id);
|
|
|
651 |
$retour = array_merge($retour, $this->table_retour);
|
|
|
652 |
}
|
660 |
jpm |
653 |
$noms[$num] = $retour;
|
3 |
jpm |
654 |
}
|
655 |
jpm |
655 |
|
660 |
jpm |
656 |
return $noms;
|
3 |
jpm |
657 |
}
|
655 |
jpm |
658 |
|
606 |
mathilde |
659 |
public function remplirJsonEntete() {
|
|
|
660 |
$entete = array();
|
|
|
661 |
if (isset($this->masque)) {
|
|
|
662 |
$this->table_retour['masque'] = implode('&', $this->masque);
|
|
|
663 |
}
|
655 |
jpm |
664 |
parent::afficherEnteteResultat('/'.$this->service);
|
606 |
mathilde |
665 |
return $this->table_retour;
|
|
|
666 |
}
|
3 |
jpm |
667 |
}
|
|
|
668 |
?>
|