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