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();
|
655 |
jpm |
280 |
return $requete;
|
660 |
jpm |
281 |
}
|
655 |
jpm |
282 |
|
660 |
jpm |
283 |
public function retournerChamps() {
|
|
|
284 |
$sql = '';
|
|
|
285 |
if ($this->distinct) {
|
|
|
286 |
$sql .= $this->distinct.' ';
|
|
|
287 |
}
|
|
|
288 |
if ($this->requete_champ) {
|
|
|
289 |
$sql .= $this->requete_champ.' ';
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
// Champs "virtuels" pour tier sur l'ensemble des résultats
|
|
|
293 |
if (isset($this->parametres['retour.tri'])) {
|
|
|
294 |
list($champ, $ordre) = $this->decouperParametreRetourTri();
|
|
|
295 |
if ($champ == 'retenu') {
|
|
|
296 |
$sql .= ", IF(num_nom = num_nom_retenu, '0', '1') AS nom_retenu_tri ";
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
return $sql;
|
3 |
jpm |
301 |
}
|
|
|
302 |
|
660 |
jpm |
303 |
public function decouperParametreRetourTri() {
|
|
|
304 |
$tri = array('', '');
|
|
|
305 |
if (isset($this->parametres['retour.tri'])) {
|
|
|
306 |
if (preg_match('/^(retenu)(?:,(ASC|DESC)|)$/', $this->parametres['retour.tri'], $match))
|
|
|
307 |
$tri[0] = $match[1];
|
|
|
308 |
$tri[1] = isset($match[2]) ? $match[2] : '';
|
|
|
309 |
}
|
|
|
310 |
return $tri;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
public function retournerRequeteCondition() {
|
|
|
314 |
$condition = '';
|
|
|
315 |
if ($this->requete_condition) {
|
|
|
316 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
317 |
}
|
|
|
318 |
return $condition;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
public function retournerOrderBy() {
|
|
|
322 |
$orderBy = array();
|
|
|
323 |
|
|
|
324 |
// Tri sur l'ensemble des résultats
|
|
|
325 |
if (isset($this->parametres['retour.tri'])) {
|
|
|
326 |
list($champ, $ordre) = $this->decouperParametreRetourTri();
|
|
|
327 |
if ($champ == 'retenu') {
|
|
|
328 |
$orderBy[] = "nom_retenu_tri $ordre";
|
|
|
329 |
}
|
|
|
330 |
}
|
|
|
331 |
// Tri par défaut
|
|
|
332 |
if ($this->format_reponse == 'noms') {
|
|
|
333 |
$orderBy[] = 'nom_sci ASC';
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
$sql = '';
|
672 |
jpm |
337 |
if (count($orderBy) > 0) {
|
660 |
jpm |
338 |
$sql = 'ORDER BY '.implode(', ', $orderBy).' ';
|
|
|
339 |
}
|
|
|
340 |
return $sql;
|
|
|
341 |
}
|
|
|
342 |
|
3 |
jpm |
343 |
public function formerRequeteLimite() {
|
655 |
jpm |
344 |
if ($this->format_reponse != 'noms' && $this->format_reponse != 'noms/id/relations/synonymie'
|
660 |
jpm |
345 |
&& $this->format_reponse != 'noms/id/relations/homonymie') {
|
655 |
jpm |
346 |
$this->requete_limite = '';
|
3 |
jpm |
347 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
655 |
jpm |
348 |
$this->limite_requete['depart'] =
|
660 |
jpm |
349 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
655 |
jpm |
350 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
3 |
jpm |
351 |
} else {
|
655 |
jpm |
352 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
3 |
jpm |
353 |
}
|
|
|
354 |
return $this->requete_limite;
|
|
|
355 |
}
|
655 |
jpm |
356 |
|
3 |
jpm |
357 |
/** Recupere le nombre total de résultat d'une requete lancée. */
|
|
|
358 |
public function recupererTotalResultat() {
|
|
|
359 |
$total = null;
|
|
|
360 |
$requete = 'SELECT count(*) as nombre FROM '.$this->table.$this->retournerRequeteCondition().$this->requete_group_by;
|
|
|
361 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
362 |
if ($res) {
|
|
|
363 |
$total = $res['nombre'];
|
|
|
364 |
} else {
|
|
|
365 |
$e = 'Fct recupererTotalResultat() : <br/>Données introuvables dans la base';
|
|
|
366 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
367 |
}
|
|
|
368 |
return $total;
|
|
|
369 |
}
|
655 |
jpm |
370 |
|
|
|
371 |
|
3 |
jpm |
372 |
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
|
655 |
jpm |
373 |
|
272 |
delphine |
374 |
public function retournerResultatFormate($resultat) {
|
3 |
jpm |
375 |
switch ($this->format_reponse) {
|
|
|
376 |
case 'noms/relations' :
|
|
|
377 |
$reponse = $this->formaterRelations($resultat[0]);
|
|
|
378 |
break;
|
|
|
379 |
case 'noms/id' : //ds CommunNomsTaxons
|
|
|
380 |
$reponse = $this->formaterId($resultat[0]);
|
|
|
381 |
break;
|
|
|
382 |
case 'noms/id/relations' :
|
|
|
383 |
$reponse = $this->formaterIdRelations($resultat[0]);
|
655 |
jpm |
384 |
break;
|
3 |
jpm |
385 |
case 'noms/id/relations/synonymie' :
|
|
|
386 |
$reponse = $this->formaterIdSynonymie($resultat);
|
|
|
387 |
break;
|
|
|
388 |
case 'noms/id/relations/homonymie' :
|
|
|
389 |
$reponse = $this->formaterIdHomonymie($resultat);
|
|
|
390 |
break;
|
|
|
391 |
case 'noms/id/relations/flores' : //ds CommunsNomsTaxons
|
|
|
392 |
$reponse = $this->formaterIdFlores($resultat[0]);
|
|
|
393 |
break;
|
|
|
394 |
case 'noms/stats/annees' : //ds CommunNomsTaxons
|
|
|
395 |
$reponse = $this->formaterStatsAnnee($resultat);
|
|
|
396 |
break;
|
|
|
397 |
case 'noms/stats/rangs' : //ds CommunNomsTaxons
|
|
|
398 |
$reponse = $this->formaterStatsRang($resultat);
|
|
|
399 |
break;
|
|
|
400 |
case 'noms/stats/initiales' : //ds CommunNomsTaxons
|
|
|
401 |
$reponse = $this->formaterStatsInitiales($resultat);
|
|
|
402 |
break;
|
|
|
403 |
case 'noms' :
|
|
|
404 |
$reponse = $this->formaterNoms($resultat);
|
|
|
405 |
break;
|
|
|
406 |
}
|
|
|
407 |
return $reponse;
|
|
|
408 |
}
|
655 |
jpm |
409 |
|
3 |
jpm |
410 |
//+---------------------concerne les resultats pour des requetes de type noms/id-----------------------------+
|
655 |
jpm |
411 |
|
3 |
jpm |
412 |
public function formaterRelations($resultat) {
|
|
|
413 |
$num_nom = $resultat['num_nom'];
|
|
|
414 |
if (isset($this->ressources[3])) {
|
|
|
415 |
$url = Config::get('url_service').$this->service."/$num_nom/relations";
|
|
|
416 |
} else {
|
|
|
417 |
$type = $this->ressources[3];
|
|
|
418 |
$url = Config::get('url_service')."/$this->service/$num_nom/relations/$type";
|
|
|
419 |
}
|
|
|
420 |
$res = $this->consulterHref($url);
|
|
|
421 |
return $res;
|
655 |
jpm |
422 |
}
|
|
|
423 |
|
3 |
jpm |
424 |
public function formaterIdRelations($resultat) {
|
|
|
425 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
655 |
jpm |
426 |
$this->resultat_req = $resultat;
|
3 |
jpm |
427 |
$retour_id_rel = array ('entete' => array()); //on initialise pr que l'entete apparaisse en premier lors de l'affichage
|
655 |
jpm |
428 |
|
3 |
jpm |
429 |
//on recupère le resultat de chaque relation (appel du WS correspondant)
|
272 |
delphine |
430 |
$flores = $this->ajouterRelations('flores');
|
3 |
jpm |
431 |
if (isset($flores)) $retour_id_rel['resultat']['flores'] = $flores;
|
272 |
delphine |
432 |
$homonymes = $this->ajouterRelations('homonymie');
|
3 |
jpm |
433 |
if (isset($homonymes)) $retour_id_rel['resultat']['homonymes'] = $homonymes;
|
272 |
delphine |
434 |
$synonymes = $this->ajouterRelations('synonymie');
|
3 |
jpm |
435 |
if (isset($synonymes)) $retour_id_rel['resultat']['synonymes'] = $synonymes;
|
655 |
jpm |
436 |
|
3 |
jpm |
437 |
//on renvoit null si il n'existe aucune relations (on efface l'entete en premier lieu)
|
|
|
438 |
if (!isset($retour_id_rel['resultat'])) {
|
655 |
jpm |
439 |
$retour_id_rel = null;
|
3 |
jpm |
440 |
} else { //on rajoute l'entete si des relations existent
|
655 |
jpm |
441 |
$this->afficherDonnees('num_nom', $this->ressources[0]);
|
3 |
jpm |
442 |
$retour_id_rel['entete'] = $this->table_retour;
|
|
|
443 |
$this->table_retour = array();
|
|
|
444 |
}
|
|
|
445 |
return $retour_id_rel;
|
|
|
446 |
}
|
655 |
jpm |
447 |
|
3 |
jpm |
448 |
/**
|
655 |
jpm |
449 |
* Recupere les relations (type de la relation passée en paramètres :[type_relation] = synonymie, homonymie ou
|
3 |
jpm |
450 |
* flores) par l'appel du web service [version]/noms/#id/relations/[type_relation]
|
|
|
451 |
*/
|
272 |
delphine |
452 |
public function ajouterRelations($relation) {
|
|
|
453 |
$version = str_replace(Config::get('bdd_table').'_', '', $this->table);
|
3 |
jpm |
454 |
$res = null;
|
|
|
455 |
$parametres_url = '';
|
|
|
456 |
if ($this->parametres != array()) $parametres_url = '?'.http_build_query($this->parametres, '', '&');
|
272 |
delphine |
457 |
$url = Config::get('url_service').'/'.$this->service.'/'
|
3 |
jpm |
458 |
.$this->ressources[0].'/relations/'
|
272 |
delphine |
459 |
.$relation.$parametres_url; Debug::printr($url);
|
655 |
jpm |
460 |
|
3 |
jpm |
461 |
$relation = $this->consulterHref($url);
|
655 |
jpm |
462 |
|
3 |
jpm |
463 |
$res = $relation->resultat;
|
|
|
464 |
return $res;
|
|
|
465 |
}
|
655 |
jpm |
466 |
|
|
|
467 |
|
3 |
jpm |
468 |
public function formaterIdSynonymie($resultat) {
|
|
|
469 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
|
|
470 |
$retour_id_syn = array();
|
|
|
471 |
if ($resultat[0]['num_nom_retenu'] == '') {
|
|
|
472 |
$retour_id_syn[] = 'nom_retenu N.D.';
|
655 |
jpm |
473 |
} elseif (count($resultat) != 1) {
|
|
|
474 |
//on remplit d'abord l'entete du resultat
|
3 |
jpm |
475 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
476 |
$this->afficherEnteteResultat('/'.$this->service.'/'.$this->ressources[0].'/relations/synonymie');
|
|
|
477 |
$retour_id_syn['entete'] = $this->table_retour;
|
|
|
478 |
$this->table_retour = array();
|
|
|
479 |
foreach ($resultat as $tab) {
|
|
|
480 |
//pour chaque basionyme, on recupère le résultat : num_nom, nom_sci, basionyme et num_nom_retenu :
|
655 |
jpm |
481 |
$this->resultat_req = $tab;
|
3 |
jpm |
482 |
$num = $tab['num_nom'];
|
|
|
483 |
$this->afficherNomHrefRetenu($tab, $num);
|
655 |
jpm |
484 |
$this->afficherDonnees('basionyme', $tab['basionyme']);
|
3 |
jpm |
485 |
$retour_id_syn['resultat'][$num] = $this->table_retour;
|
|
|
486 |
$this->table_retour = array();
|
|
|
487 |
}
|
|
|
488 |
if (!isset($retour_id_syn['resultat']) && !in_array('nom_retenu N.D.', $retour_id_syn)) {
|
|
|
489 |
$retour_id_syn = null; //on initialise le resultat à null
|
655 |
jpm |
490 |
}
|
3 |
jpm |
491 |
}
|
|
|
492 |
return $retour_id_syn;
|
|
|
493 |
}
|
655 |
jpm |
494 |
|
3 |
jpm |
495 |
public function formaterIdHomonymie($resultat) {
|
|
|
496 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
272 |
delphine |
497 |
if (count($resultat) != 1) {
|
3 |
jpm |
498 |
$this->table_retour['id'] = $this->ressources[0];
|
|
|
499 |
$this->afficherEnteteResultat($resultat, '/'.$this->service.'/'.$this->ressources[0].'/relations/homonymie');
|
|
|
500 |
$retour_id_hom['entete'] = $this->table_retour;
|
|
|
501 |
$this->table_retour = array();
|
|
|
502 |
foreach ($resultat as $homonyme) {
|
|
|
503 |
$this->resultat_req = $homonyme;
|
|
|
504 |
$id = $homonyme['num_nom'];
|
|
|
505 |
$this->afficherDonnees('num_nom', $id);
|
|
|
506 |
if ($homonyme['num_nom_retenu'] != '') {
|
562 |
delphine |
507 |
$retenu = ($id == $homonyme['num_nom_retenu']) ? 'true' : 'false';
|
|
|
508 |
} else {
|
|
|
509 |
$retenu = 'absent';
|
|
|
510 |
}
|
655 |
jpm |
511 |
$this->table_retour['retenu'] = $retenu;
|
3 |
jpm |
512 |
$retour_id_hom['resultat'][$id] = $this->table_retour;
|
|
|
513 |
unset($retour_id_hom['resultat'][$id]['id']);
|
|
|
514 |
$this->table_retour = array();
|
|
|
515 |
}
|
533 |
gduche |
516 |
} else {
|
655 |
jpm |
517 |
$retour_id_hom = null;
|
3 |
jpm |
518 |
}
|
|
|
519 |
return $retour_id_hom;
|
|
|
520 |
}
|
655 |
jpm |
521 |
|
357 |
delphine |
522 |
public function obtenirSynonymesParNumNomAvecInfosFlore($num_nom, $version='1_02') {
|
655 |
jpm |
523 |
|
|
|
524 |
$champs_flore = 'flore_bonnier_num, flore_bonnier_rem,'.
|
306 |
aurelien |
525 |
'flore_cnrs_num, flore_cnrs_rem '.
|
|
|
526 |
'flore_fe_num, flore_fe_rem '.
|
655 |
jpm |
527 |
'flore_coste_num, flore_coste_rem '.
|
|
|
528 |
'flore_fh_num, flore_fh_rem '.
|
306 |
aurelien |
529 |
'flore_fournier_num, flore_fournier_rem';
|
655 |
jpm |
530 |
|
306 |
aurelien |
531 |
$requete = 'SELECT num_nom, nom_sci, '.$champs_flore.' '.
|
357 |
delphine |
532 |
'FROM '.$this->table.' '.
|
306 |
aurelien |
533 |
'WHERE num_nom_retenu = '.
|
|
|
534 |
'('.
|
357 |
delphine |
535 |
'SELECT num_nom_retenu FROM '.$this->table.' WHERE num_nom = "'.$num_nom.'"'.
|
306 |
aurelien |
536 |
')';
|
655 |
jpm |
537 |
|
|
|
538 |
return $this->getBdd()->recupererTous($requete);
|
306 |
aurelien |
539 |
}
|
655 |
jpm |
540 |
|
3 |
jpm |
541 |
public function formaterIdFlores($resultat) {
|
|
|
542 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp,noms_projets');
|
655 |
jpm |
543 |
$this->resultat_req = $resultat;
|
3 |
jpm |
544 |
$id = array_shift($resultat);
|
|
|
545 |
$reponse['entete']['id'] = $id;
|
306 |
aurelien |
546 |
$synonymes_flores = $this->obtenirSynonymesParNumNomAvecInfosFlore($this->ressources[0]);
|
|
|
547 |
if(is_array($synonymes_flores)) {
|
|
|
548 |
foreach ($synonymes_flores as $synonyme) {
|
|
|
549 |
$nom_sci = $synonyme['nom_sci'];
|
|
|
550 |
$num_nom = $synonyme['num_nom'];
|
|
|
551 |
unset($synonyme['nom_sci']);
|
|
|
552 |
unset($synonyme['num_nom']);
|
|
|
553 |
foreach ($synonyme as $flores => $valeur) {
|
|
|
554 |
if ($valeur != '' && $valeur != '0') {
|
|
|
555 |
$this->afficherInfosFlore($synonyme, $flores, $valeur, $nom_sci, $num_nom);
|
|
|
556 |
}
|
|
|
557 |
}
|
3 |
jpm |
558 |
}
|
|
|
559 |
}
|
306 |
aurelien |
560 |
|
3 |
jpm |
561 |
if ($this->table_retour != array()) {
|
|
|
562 |
$reponse['resultat'] = $this->table_retour;
|
|
|
563 |
$this->table_retour = array();
|
655 |
jpm |
564 |
} else {
|
|
|
565 |
$reponse = null;
|
3 |
jpm |
566 |
}
|
|
|
567 |
return $reponse;
|
|
|
568 |
}
|
655 |
jpm |
569 |
|
306 |
aurelien |
570 |
public function getNomCompletFlore($flore) {
|
|
|
571 |
return Config::get($flore.'_texte');
|
|
|
572 |
}
|
655 |
jpm |
573 |
|
306 |
aurelien |
574 |
public function afficherInfosFlore(&$resultat, $flores, $valeur, $nom_sci, $num_nom) {
|
655 |
jpm |
575 |
$flore = substr($flores,0,strrpos($flores, '_'));
|
3 |
jpm |
576 |
$projet = $this->noms_projets[$flore];
|
655 |
jpm |
577 |
|
306 |
aurelien |
578 |
//TODO voir si l'on peut factoriser les affectations à la table retour
|
|
|
579 |
// et simplifier ce gros pavé
|
655 |
jpm |
580 |
if (strrpos($flores, 'num') !== false) {
|
|
|
581 |
if (preg_match('/^([0-9]+)(?:[.]syn[^a-z]*|(.*))?$/', $valeur, $match)) {
|
306 |
aurelien |
582 |
$this->table_retour[$num_nom][$flore]['id'] = $match[1];
|
3 |
jpm |
583 |
if ($projet == 'coste') {
|
306 |
aurelien |
584 |
$this->table_retour[$num_nom][$flore]['href'] = $this->ajouterHrefAutreProjet('noms', 'nn_coste:', $match[1], $projet);
|
3 |
jpm |
585 |
}
|
306 |
aurelien |
586 |
if (isset($match[2]) && $match[2] != '') $this->table_retour[$num_nom][$flore]['cle'] = $match[2];
|
|
|
587 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
588 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
655 |
jpm |
589 |
}
|
3 |
jpm |
590 |
if (isset($resultat[$flore.'_rem']) && !empty($resultat[$flore.'_rem'])) {
|
306 |
aurelien |
591 |
$this->table_retour[$num_nom][$flore]['remarque'] = $resultat[$flore.'_rem'];
|
|
|
592 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
593 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
3 |
jpm |
594 |
unset($resultat[$flore.'_rem']);
|
|
|
595 |
}
|
|
|
596 |
} elseif (strrpos($flores,'belge') !== false) {
|
|
|
597 |
if (preg_match('/^([0-9]+) (R|S)?$/', $valeur, $match)) {
|
|
|
598 |
if (isset($match[2])) $type = ($match[2] == 'R') ? 'taxons' : 'synonyme';
|
306 |
aurelien |
599 |
$this->table_retour[$num_nom][$flore]['page'] = $match[1];
|
|
|
600 |
$this->table_retour[$num_nom][$flore]['type'] = $type;
|
|
|
601 |
$this->table_retour[$num_nom][$flore]['nom_flore'] = $this->getNomCompletFlore($flore);
|
|
|
602 |
$this->table_retour[$num_nom][$flore]['nom_sci'] = $nom_sci;
|
3 |
jpm |
603 |
}
|
|
|
604 |
}
|
655 |
jpm |
605 |
}
|
|
|
606 |
|
3 |
jpm |
607 |
//+---------------------concerne les resultats pour des requetes de type /noms avec ou sans paramètres-------+
|
|
|
608 |
|
566 |
aurelien |
609 |
public function formaterNoms($resultat) {
|
3 |
jpm |
610 |
if ($this->parametres['retour.format'] == 'oss') {
|
|
|
611 |
$reponse = $this->formaterEnOss($resultat); //Ds CommunNomsTaxons.php
|
|
|
612 |
} else {
|
|
|
613 |
$reponse = $this->formaterEnJsonMax($resultat);
|
|
|
614 |
}
|
|
|
615 |
return $reponse;
|
|
|
616 |
}
|
|
|
617 |
|
|
|
618 |
public function formaterEnJsonMax($resultat) {
|
|
|
619 |
$this->recupererTableSignification('correspondance_champs,champs_api,champs_comp');
|
660 |
jpm |
620 |
|
|
|
621 |
// TODO : améliorer le trie des résultats
|
|
|
622 |
// ATTENTION : ce comportement est étrange
|
3 |
jpm |
623 |
$masque = $this->recupererMasquePrincipal();
|
671 |
jpm |
624 |
if (isset($masque) && !isset($this->parametres['retour.tri'])) {
|
3 |
jpm |
625 |
$resultat = $this->trierRechercheFloue($this->parametres[$masque[0]], $resultat, $masque[1]);
|
|
|
626 |
}
|
660 |
jpm |
627 |
|
606 |
mathilde |
628 |
$table_retour_json['entete'] = $this->remplirJsonEntete();
|
655 |
jpm |
629 |
$table_retour_json['resultat'] = $this->remplirJsonResultat($resultat);
|
606 |
mathilde |
630 |
return $table_retour_json;
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
public function remplirJsonResultat($resultat) {
|
3 |
jpm |
634 |
$champs = null;
|
|
|
635 |
if (array_key_exists('retour.champs', $this->parametres)) {
|
|
|
636 |
$champs = explode(',', $this->parametres['retour.champs']);
|
|
|
637 |
}
|
660 |
jpm |
638 |
|
655 |
jpm |
639 |
$noms = array();
|
3 |
jpm |
640 |
foreach ($resultat as $tab) {
|
|
|
641 |
$this->table_retour = array();
|
|
|
642 |
$num = $tab['num_nom'];
|
93 |
delphine |
643 |
$this->afficherNomHrefRetenu($tab, $num); // ajoute le nom_sci, href et si le nom est retenu dans $this->table_retour
|
|
|
644 |
$retour = $this->table_retour;
|
|
|
645 |
$this->table_retour = array();
|
|
|
646 |
if ($champs != null) {
|
|
|
647 |
$reponse_id = $this->formaterId($tab);
|
|
|
648 |
$this->table_retour = array();
|
|
|
649 |
$this->ajouterChampsPersonnalises($champs, $reponse_id);
|
|
|
650 |
$retour = array_merge($retour, $this->table_retour);
|
|
|
651 |
}
|
660 |
jpm |
652 |
$noms[$num] = $retour;
|
3 |
jpm |
653 |
}
|
655 |
jpm |
654 |
|
660 |
jpm |
655 |
return $noms;
|
3 |
jpm |
656 |
}
|
655 |
jpm |
657 |
|
606 |
mathilde |
658 |
public function remplirJsonEntete() {
|
|
|
659 |
$entete = array();
|
|
|
660 |
if (isset($this->masque)) {
|
|
|
661 |
$this->table_retour['masque'] = implode('&', $this->masque);
|
|
|
662 |
}
|
655 |
jpm |
663 |
parent::afficherEnteteResultat('/'.$this->service);
|
606 |
mathilde |
664 |
return $this->table_retour;
|
|
|
665 |
}
|
3 |
jpm |
666 |
}
|
|
|
667 |
?>
|