6 |
jpm |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Description :
|
|
|
5 |
* Classe Textes.php est une classe qui contient les méthodes permettant la consultation des textes (clé de détermination
|
|
|
6 |
* ou description). Les identifiants des textes correspondent au tag de type CleCoste1937TXXPXXNomSci pour le projet
|
|
|
7 |
* coste.
|
|
|
8 |
* Encodage en entrée : utf8
|
|
|
9 |
* Encodage en sortie : utf8
|
|
|
10 |
* @package framework-v3
|
|
|
11 |
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
|
|
|
12 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
13 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
14 |
* @version 1.0
|
|
|
15 |
* @copyright 1999-${year} Tela Botanica (accueil@tela-botanica.org)
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
class Textes extends Commun {
|
|
|
20 |
|
|
|
21 |
protected $limite_requete = array('depart' => 0, 'limite' => 100);
|
|
|
22 |
protected $requete_champ = ' t1.resource AS tag, t1.value AS num_nom, t2.value AS titre, p.body AS texte';
|
|
|
23 |
protected $requete_condition = null;
|
|
|
24 |
protected $requete_group_by = ' ORDER BY CAST( t1.value AS DECIMAL )';
|
|
|
25 |
protected $table_retour;
|
|
|
26 |
protected $retour_format = 'max';
|
|
|
27 |
protected $format_reponse = 'textes';
|
|
|
28 |
protected $table_param = array();
|
|
|
29 |
protected $total_resultat;
|
|
|
30 |
protected $table_ressources = array();
|
|
|
31 |
protected $html = 'txt';
|
|
|
32 |
protected $recherche = 'stricte';
|
|
|
33 |
protected $service = 'textes';
|
|
|
34 |
protected $masque = null;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
public function consulter($ressources, $parametres) {
|
|
|
38 |
$resultat_formate = '';
|
|
|
39 |
$this->table = array(Config::get("bdd_triples")." t1", Config::get("bdd_triples")." t2", Config::get("bdd_pages")." p");
|
|
|
40 |
$this->traiterParametres($parametres);
|
|
|
41 |
$this->traiterRessources($ressources);
|
|
|
42 |
if ($this->corps_http == '' && $this->entete_http == '') {
|
288 |
delphine |
43 |
$requete = $this->assemblerLaRequete();
|
6 |
jpm |
44 |
$resultat = $this->getBdd()->recupererTous($requete);
|
|
|
45 |
$this->testerResultat($resultat, $resultat_formate, $requete);
|
|
|
46 |
}
|
|
|
47 |
return $this->formerReponseHTTP($resultat_formate);
|
|
|
48 |
}
|
|
|
49 |
|
288 |
delphine |
50 |
public function formerReponseHTTP($resultat_formate, $mime = 'application/json', $encodage= 'utf-8') {
|
|
|
51 |
// Si aucune erreur n'a été établie (donc un tableau de résultat a bien ete renvoyé...)
|
|
|
52 |
if ($this->corps_http == '' && $this->entete_http == '') {
|
|
|
53 |
$this->entete_http = RestServeur::HTTP_CODE_OK;
|
|
|
54 |
$this->corps_http = $resultat_formate;
|
|
|
55 |
}
|
|
|
56 |
if ($this->entete_http != RestServeur::HTTP_CODE_OK) {
|
|
|
57 |
$mime = 'text/html';
|
|
|
58 |
}
|
|
|
59 |
// Gestion du type de contenu
|
|
|
60 |
if (!is_null($mime) && !is_null($encodage)) {
|
|
|
61 |
header("Content-Type: $mime; charset=$encodage");
|
|
|
62 |
} else if (!is_null($mime) && is_null($encodage)) {
|
|
|
63 |
header("Content-Type: $mime");
|
|
|
64 |
}
|
|
|
65 |
// Envoie de l'entête
|
|
|
66 |
RestServeur::envoyerEnteteStatutHttp($this->entete_http);
|
|
|
67 |
// Envoie du corps
|
|
|
68 |
return $this->corps_http;
|
|
|
69 |
}
|
6 |
jpm |
70 |
|
288 |
delphine |
71 |
|
6 |
jpm |
72 |
public function testerResultat($resultat, &$resultat_formate, $requete) {
|
|
|
73 |
if ($resultat == '') { //cas ou coste/services/ ou la requete comporte des erreurs
|
|
|
74 |
$e = 'La requête SQL formée comporte une erreur!';
|
|
|
75 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
|
|
|
76 |
Debug::printr($requete);
|
|
|
77 |
} elseif ($resultat) {
|
|
|
78 |
$resultat_formate = $this->retournerResultatFormate($resultat);
|
|
|
79 |
} else {
|
356 |
delphine |
80 |
if ($this->format_reponse == 'textes/relations') {
|
6 |
jpm |
81 |
$resultat_formate = 'null';
|
|
|
82 |
} else {
|
|
|
83 |
$m = 'Données introuvables dans la base';
|
|
|
84 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$m);
|
|
|
85 |
Debug::printr($requete);
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
//---------------------------------TRAITER RESSOURCES-----------------------------------------------------------------
|
|
|
92 |
|
|
|
93 |
public function traiterRessources(&$ressources) {
|
|
|
94 |
if (isset($ressources) && !empty($ressources)) {
|
|
|
95 |
$this->table = Config::get('bdd_triples');
|
|
|
96 |
$this->table_ressources = $ressources;
|
|
|
97 |
if ($ressources[0] == 'relations') {
|
|
|
98 |
$this->traiterRelationsProjet($ressources);
|
|
|
99 |
$this->format_reponse .= '/relations';
|
|
|
100 |
} elseif (isset($this->table_ressources[0]) && !empty($this->table_ressources[0])) {
|
|
|
101 |
$this->traiterRessourceId($this->table_ressources[0]);
|
|
|
102 |
if (isset($this->table_ressources[1]) && !empty($this->table_ressources[1])) {
|
|
|
103 |
$this->format_reponse .= '/champ';
|
|
|
104 |
}
|
|
|
105 |
} else {
|
|
|
106 |
$e = "Erreur dans votre requête. <br/> Les ressources disponibles sont :
|
|
|
107 |
<li> /textes/#id (id correspondant au tag de la page </li>
|
|
|
108 |
<li> /textes/#id/#champ+#champ </li>
|
|
|
109 |
<li> /textes/relations/bdtfx/#id (id correspondant au num_nom du projet bdtfx </li>";
|
|
|
110 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
111 |
}
|
|
|
112 |
} else {
|
|
|
113 |
$this->traiterRessourcesListe();
|
|
|
114 |
}
|
|
|
115 |
$this->requete_condition[] = "p.latest = 'Y'";
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
public function traiterRessourceId($id) {
|
|
|
119 |
$this->format_reponse .= '/id';
|
|
|
120 |
if ($this->recherche == 'etendue') {
|
|
|
121 |
$id = '%'.str_replace(' ','%', $id).'%';
|
289 |
delphine |
122 |
}
|
|
|
123 |
if (is_numeric($id)) {
|
|
|
124 |
$this->requete_condition[] = 'c.id ='.$this->getBdd()->proteger($id);
|
|
|
125 |
} else {
|
|
|
126 |
$id = explode('bdtfx.nn:', $id);
|
|
|
127 |
if (is_numeric($id[1])) {
|
|
|
128 |
$this->requete_condition[] = 'c.num_nom ='.$this->getBdd()->proteger($id[1]);
|
|
|
129 |
}
|
|
|
130 |
}
|
288 |
delphine |
131 |
|
|
|
132 |
$this->requete_champ = 'c.id AS num_nom, i.nom_sci AS titre, t1.resource AS tag, p.body AS texte';
|
|
|
133 |
$this->table = array(Config::get("bdd_correspondance_bdnff").' c',
|
|
|
134 |
Config::get("bdd_triples").' t1',
|
|
|
135 |
Config::get("bdd_index").' i',
|
|
|
136 |
Config::get("bdd_pages").' p');
|
289 |
delphine |
137 |
|
288 |
delphine |
138 |
$this->requete_condition[] = 'c.id = i.num_nom';
|
|
|
139 |
$this->requete_condition[] = 'i.nom_sci = t1.value';
|
|
|
140 |
$this->requete_condition[] = 't1.resource = p.tag';
|
|
|
141 |
|
|
|
142 |
/*$this->requete_champ = ' t1.resource AS tag, t1.value AS num_nom, t2.value AS titre, p.body AS texte';
|
6 |
jpm |
143 |
$this->requete_condition[] = 't1.resource LIKE '.$this->getBdd()->proteger($id);
|
|
|
144 |
$this->requete_condition[] = 't1.property = "num_nom"';
|
|
|
145 |
$this->requete_condition[] = '(t1.resource = t2.resource AND t2.property = "titre")';
|
|
|
146 |
$this->requete_condition[] = 't1.resource = p.tag';
|
|
|
147 |
$this->table = array(Config::get("bdd_triples").' t1',
|
|
|
148 |
Config::get("bdd_triples").' t2',
|
|
|
149 |
Config::get("bdd_pages").' p');
|
288 |
delphine |
150 |
$this->ajouterRechercheFloue('t1.resource', $id);*/
|
6 |
jpm |
151 |
}
|
|
|
152 |
|
|
|
153 |
public function traiterRessourcesListe() {
|
|
|
154 |
$this->requete_condition[] = "t1.property = 'num_nom'";
|
|
|
155 |
$this->requete_condition[] = "(t1.resource = t2.resource AND t2.property = 'titre')";
|
|
|
156 |
$this->requete_condition[] = "t1.resource = p.tag";
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
public function traiterRelationsProjet($tab_ress) {
|
|
|
160 |
$this->table = array(Config::get("bdd_triples")." t1", Config::get("bdd_pages")." p", Config::get("bdd_table").'_v0_1 c');
|
|
|
161 |
$projet = $tab_ress[1];
|
|
|
162 |
$num_nom = $tab_ress[2];
|
|
|
163 |
$nom_champ_projet = "flore_$projet"."_num";
|
|
|
164 |
if (isset($tab_ress[3])) {
|
|
|
165 |
$type = $tab_ress[3];
|
|
|
166 |
if (!in_array($type, array('cle', 'dsc'))) {
|
|
|
167 |
$e = "Le type de texte ne peut etre que clé ou description";
|
|
|
168 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
$this->requete_condition[] = "c.flore_bdnff_num = ".$this->getBdd()->proteger($num_nom);
|
|
|
172 |
$this->requete_condition[] = "t1.value = c.num_nom";
|
|
|
173 |
$this->requete_condition[] = "t1.property = 'num_nom'";
|
|
|
174 |
$this->requete_condition[] = "t1.resource = p.tag";
|
|
|
175 |
$this->requete_champ = 't1.resource AS tag, t1.value AS num_nom, p.body AS texte';
|
|
|
176 |
if (isset($type)) $this->requete_condition[] = "t1.resource LIKE ".$this->getBdd()->proteger(ucfirst($type.'%'));
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
public function ajouterRechercheFloue($nom_champ, $id) {
|
|
|
181 |
if ($this->recherche == 'floue') {
|
|
|
182 |
$id = $this->getBdd()->proteger($id);
|
|
|
183 |
$this->requete_condition[array_search("$nom_champ LIKE $id",
|
|
|
184 |
$this->requete_condition)] =
|
|
|
185 |
"($nom_champ LIKE $id)".
|
|
|
186 |
" OR ( SOUNDEX($nom_champ) = SOUNDEX($id))".
|
|
|
187 |
" OR SOUNDEX(REVERSE($nom_champ)) = SOUNDEX(REVERSE($id))))";
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
//---------------------------------------TRAITER PARAMETRES-------------------------------------------------------------
|
|
|
192 |
|
|
|
193 |
public function traiterParametres($parametres) {
|
|
|
194 |
if (isset($parametres) && !empty($parametres)) {
|
|
|
195 |
$this->table_param = $parametres;
|
|
|
196 |
if (isset($parametres['recherche']) && $parametres['recherche'] != '') {
|
|
|
197 |
$this->recherche = $parametres['recherche'];
|
|
|
198 |
}
|
|
|
199 |
foreach ($parametres as $param => $val) {
|
|
|
200 |
switch ($param) {
|
288 |
delphine |
201 |
case 'retour.format' : $this->retour_format = $val; break;
|
|
|
202 |
case 'masque.titre' : $this->ajouterLeFiltreMasque('titre', $val); break;
|
|
|
203 |
case 'masque.famille' : $this->ajouterLeFiltreMasque('famille', $val); break;
|
|
|
204 |
case 'masque.ns' : $this->ajouterLeFiltreMasque('nom_sci', $val); break;
|
|
|
205 |
case 'masque.type' : $this->ajouterLeFiltreMasque('type', $val); break;
|
|
|
206 |
case 'masque.txt' : $this->ajouterLeFiltreMasque('texte', $val); break;
|
|
|
207 |
case 'masque.page' : $this->ajouterLeFiltreMasque('page',$val); break;
|
|
|
208 |
case 'masque.tome' : $this->ajouterLeFiltreMasque('tome',$val); break;
|
|
|
209 |
case 'navigation.depart': $this->limite_requete['depart'] = $val; break;
|
|
|
210 |
case 'navigation.limite': $this->limite_requete['limite'] = $val; break;
|
6 |
jpm |
211 |
case 'recherche' : break;
|
290 |
delphine |
212 |
case 'txt.format' : break;
|
6 |
jpm |
213 |
default :
|
|
|
214 |
$e = "Erreur dans les paramètres de recherche de votre requête : </br> Le parametre $param n\'existe pas.";
|
|
|
215 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
|
|
216 |
break;
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
public function ajouterLeFiltreMasque($masque, $valeur) {
|
|
|
224 |
if ($this->recherche == 'etendue') {
|
|
|
225 |
$valeur = '%'.str_replace(' ','%', $valeur).'%';
|
|
|
226 |
}
|
|
|
227 |
$valeur = $this->getBdd()->proteger($valeur);
|
|
|
228 |
$this->masque[] = "$masque=$valeur";
|
|
|
229 |
switch ($masque) {
|
|
|
230 |
case 'famille' :
|
|
|
231 |
break;
|
|
|
232 |
case 'nom_sci' :
|
|
|
233 |
$this->requete_condition[] = "t1.value = c.num_nom AND nom_sci LIKE $valeur)";
|
|
|
234 |
$this->ajouterRechercheFloue('nom_sci', $valeur);
|
|
|
235 |
$this->table[] = Config::get("bdd_table").'_v0_1 c';
|
|
|
236 |
break;
|
|
|
237 |
case 'type' :
|
|
|
238 |
$type = ($this->getBdd()->proteger($valeur) == '"cle"') ? 'Cle%' : 'Dsc%';
|
|
|
239 |
$this->requete_condition[] = 't1.resource LIKE '.$this->getBdd()->proteger($type);
|
|
|
240 |
break;
|
|
|
241 |
case 'texte' :
|
|
|
242 |
$this->requete_condition[] = "p.body LIKE $valeur";
|
|
|
243 |
$this->ajouterRechercheFloue('p.body', $valeur);
|
|
|
244 |
break;
|
|
|
245 |
case 'titre' :
|
|
|
246 |
$this->requete_condition[] = "t2.value LIKE $valeur";
|
|
|
247 |
$this->ajouterRechercheFloue('t2.value', $valeur);
|
|
|
248 |
break;
|
|
|
249 |
case 'page' :
|
|
|
250 |
$this->requete_condition[] = "t1.value = c.num_nom AND c.page = $valeur";
|
|
|
251 |
$this->table[] = Config::get("bdd_table").'_v0_1 c';
|
|
|
252 |
break;
|
|
|
253 |
case 'tome' :
|
|
|
254 |
$this->requete_condition[] = "t1.value = c.num_nom AND c.tome = $valeur";
|
|
|
255 |
$this->table[] = Config::get("bdd_table").'_v0_1 c';
|
|
|
256 |
break;
|
|
|
257 |
default :
|
|
|
258 |
break;
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
|
|
|
264 |
|
|
|
265 |
public function assemblerLaRequete() {
|
|
|
266 |
$requete = ' SELECT '.$this->requete_champ.
|
|
|
267 |
' FROM '.implode(', ', $this->table)
|
|
|
268 |
.$this->retourneRequeteCondition()
|
|
|
269 |
.$this->requete_group_by
|
|
|
270 |
.$this->formerRequeteLimite();
|
|
|
271 |
return $requete;
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
public function retourneRequeteCondition() {
|
|
|
276 |
$condition = '';
|
|
|
277 |
if ($this->requete_condition !== null) {
|
|
|
278 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
279 |
}
|
|
|
280 |
return $condition;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
public function formerRequeteLimite() {
|
|
|
284 |
if (in_array($this->format_reponse , array('textes/id', 'textes/id/relations'))) {
|
|
|
285 |
$this->requete_limite = '';
|
|
|
286 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
|
|
287 |
$this->limite_requete['depart'] =
|
|
|
288 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
|
|
289 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
|
|
290 |
} else {
|
|
|
291 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
|
|
292 |
}
|
|
|
293 |
return $this->requete_limite;
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
/**
|
|
|
298 |
* Recupere le nombre total de résultat d'une requete lancée.
|
|
|
299 |
* Est utilisée lors de l'affichage du total dans le résultat retourné et pr déterminer les limites et départ
|
|
|
300 |
* @return nombre total de résultat
|
|
|
301 |
*/
|
|
|
302 |
public function recupererTotalResultat() {
|
|
|
303 |
$total = null;
|
|
|
304 |
$requete = 'SELECT count(*) as nombre FROM '
|
|
|
305 |
.implode(', ', $this->table).$this->retourneRequeteCondition()
|
|
|
306 |
.$this->requete_group_by;
|
|
|
307 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
308 |
if ($res) {
|
|
|
309 |
$total = $res['nombre'];
|
|
|
310 |
} else {
|
|
|
311 |
$e = 'Données introuvables dans la base ou erreur dans la requête SQL';
|
|
|
312 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
313 |
}
|
|
|
314 |
return $total;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
|
|
|
320 |
|
|
|
321 |
public function retournerResultatFormate($resultat) {
|
|
|
322 |
$reponse = '';
|
|
|
323 |
switch ($this->format_reponse) {
|
|
|
324 |
case 'textes' : $reponse = $this->formaterTextes($resultat); break;
|
|
|
325 |
case 'textes/relations' : $reponse = $this->formaterTextesRelations($resultat); break;
|
|
|
326 |
case 'textes/id' : $reponse = $this->formaterTextesId($resultat[0]); break;
|
|
|
327 |
case 'textes/id/champ' : $reponse = $this->formaterTextesIdChamp($resultat[0]); break;
|
|
|
328 |
default : break;
|
|
|
329 |
}
|
|
|
330 |
return $reponse;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
public function formaterTextes($resultat) {
|
|
|
335 |
$this->ajouterEnteteResultat($resultat);
|
|
|
336 |
$reponse['entete'] = $this->table_retour;
|
|
|
337 |
$this->table_retour = array();
|
|
|
338 |
foreach ($resultat as $description) {
|
|
|
339 |
$tag = $description['tag'];
|
|
|
340 |
$this->afficherDonnees('titre', $description['titre']);
|
|
|
341 |
$type = (preg_match('/^Cle.*$/', $tag)) ? '1' : '2' ;
|
|
|
342 |
$this->afficherDonnees('type', $type);
|
|
|
343 |
$this->table_retour['texte'] = $description['texte'];
|
|
|
344 |
$reponse['resultat'][$tag] = $this->table_retour;
|
|
|
345 |
$this->table_retour = array();
|
|
|
346 |
$reponse['resultat'][$tag]['href'] = $this->ajouterHref('textes', $tag);
|
|
|
347 |
}
|
|
|
348 |
return $reponse;
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
public function formaterTextesRelations($resultat) {
|
|
|
352 |
foreach ($resultat as $description) {
|
|
|
353 |
$tag = $description['tag'];
|
|
|
354 |
$type = (preg_match('/^Cle.*$/', $tag)) ? '1' : '2' ;
|
|
|
355 |
$this->afficherDonnees('type', $type);
|
|
|
356 |
$this->table_retour['texte'] = $description['texte'];
|
|
|
357 |
$reponse[$tag] = $this->table_retour;
|
|
|
358 |
$this->table_retour = array();
|
|
|
359 |
$reponse[$tag]['href'] = $this->ajouterHref('textes', $tag);
|
|
|
360 |
}
|
|
|
361 |
return $reponse;
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
public function ajouterEnteteResultat($resultat) {
|
|
|
365 |
if ($this->masque) {
|
|
|
366 |
$this->table_retour['masque'] = implode('&', $this->masque);
|
|
|
367 |
}
|
|
|
368 |
$this->table_retour['depart'] = $this->limite_requete['depart'];
|
|
|
369 |
$this->table_retour['limite'] = $this->limite_requete['limite'];
|
|
|
370 |
$this->table_retour['total'] = $this->total_resultat;
|
|
|
371 |
//formuler les urls
|
|
|
372 |
$url = $this->formulerUrl($this->total_resultat, '/'.$this->service);
|
|
|
373 |
if ($url['precedent'] != '') { $this->table_retour['href.precedent'] = $url['precedent']; }
|
|
|
374 |
if ($url['suivant'] != '') { $this->table_retour['href.suivant'] = $url['suivant']; }
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
public function formaterTextesId($reponse) {
|
|
|
379 |
|
|
|
380 |
$this->afficherDonnees('titre', $reponse['titre']);
|
|
|
381 |
$type = (preg_match('/^Cle.*$/', $reponse['tag'])) ? '2' : '1' ;
|
|
|
382 |
$this->afficherDonnees('type', $type);
|
|
|
383 |
$this->table_retour['texte'] = $reponse['texte'];
|
289 |
delphine |
384 |
//$this->afficherDonnees('id', $reponse['num_nom']);
|
6 |
jpm |
385 |
|
|
|
386 |
return $this->table_retour;
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
public function formaterTextesIdChamp($resultat) {
|
|
|
391 |
//on recupère tous les resultats possibles
|
|
|
392 |
$reponse_id = $this->formaterTextesId($resultat);
|
|
|
393 |
$this->table_retour = array();
|
|
|
394 |
//on recupère les résultats demandés à partir du tableau de résultat complet
|
|
|
395 |
$this->table_retour['id'] = $resultat['tag'];
|
|
|
396 |
$champs = explode(' ', $this->table_ressources[1]);
|
|
|
397 |
foreach ($champs as $champ) {
|
|
|
398 |
if ($this->verifierValiditeChamp($champ, $reponse_id)) {
|
|
|
399 |
if (preg_match('/^[^.]+\.\*$/', $champ)) {
|
|
|
400 |
$this->afficherPointEtoile($champ, $reponse_id);
|
|
|
401 |
} else {
|
|
|
402 |
$this->table_retour[$champ] = $reponse_id[$champ];
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
return $this->table_retour;
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
public function afficherPointEtoile($champ, $reponse_id) {
|
|
|
411 |
preg_match('/^([^.]+\.)\*$/', $champ, $match);
|
|
|
412 |
foreach ($reponse_id as $chp => $valeur) {
|
|
|
413 |
if (strrpos($chp, $match[1]) !== false) {
|
|
|
414 |
$this->table_retour[$chp] = $valeur;
|
|
|
415 |
}
|
|
|
416 |
}
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
public function verifierValiditeChamp($champ, $reponse_id) {
|
|
|
421 |
$validite = false;
|
|
|
422 |
preg_match('/^([^.]+)(:?\.([^.]+))?$/', $champ, $match);
|
|
|
423 |
if (array_key_exists($match[1], $reponse_id)) {
|
|
|
424 |
$validite = true;
|
|
|
425 |
if (isset($match[2]) && !empty($match[2])) {
|
|
|
426 |
if ($match[1] == 'type') {
|
|
|
427 |
$suffixes = array('.code', '.href', '.*');
|
|
|
428 |
$validite = (in_array($match[2], $suffixes)) ? true : false;
|
|
|
429 |
} else {
|
|
|
430 |
$validite = false;
|
|
|
431 |
}
|
|
|
432 |
}
|
|
|
433 |
}
|
|
|
434 |
if (!$validite) {
|
|
|
435 |
$champs = implode('</li><li>', array_keys($reponse_id));
|
|
|
436 |
$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas. Les champs disponibles
|
|
|
437 |
sont : <li>'.$champs.'</li>';
|
|
|
438 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
439 |
}
|
|
|
440 |
return $validite;
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
|
|
|
444 |
//------------------------------------------------Fonction d'affichage ------------------------------------------------
|
|
|
445 |
|
|
|
446 |
public function afficherDonnees($champ, $valeur) {
|
|
|
447 |
if ($this->retour_format == 'min') {
|
|
|
448 |
$champ = ($champ == 'type') ? $champ.'.code' : $champ;
|
|
|
449 |
$this->table_retour[$champ] = $valeur;
|
|
|
450 |
} else {
|
|
|
451 |
$this->afficherDonneesMax($champ, $valeur);
|
|
|
452 |
}
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
|
|
|
456 |
public function afficherDonneesMax($champ, $valeur) {
|
|
|
457 |
if ($champ == 'id') {
|
|
|
458 |
$this->table_retour[$champ] = "coste.".$valeur;
|
|
|
459 |
$this->table_retour['nom_sci'] = $this->recupererNomSci($valeur);
|
|
|
460 |
$this->table_retour['id.href'] = $this->ajouterHref('noms', $valeur);
|
|
|
461 |
} elseif (in_array($champ, array('type'))) {
|
|
|
462 |
$this->table_retour[$champ.'.code'] = $valeur;
|
|
|
463 |
$this->table_retour[$champ] = $this->recupererSignificationCode($valeur);
|
289 |
delphine |
464 |
$this->table_retour[$champ.'.href'] = $this->ajouterHrefAutreProjet('ontologies', 'texteType:', $valeur, 'eflore');
|
6 |
jpm |
465 |
} else {
|
|
|
466 |
$this->table_retour[$champ] = $valeur;
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
|
|
|
470 |
|
|
|
471 |
public function recupererSignificationCode($code) {
|
289 |
delphine |
472 |
$url = $this->ajouterHrefAutreProjet('ontologies', 'texteType:', $code.'/nom', 'eflore');
|
6 |
jpm |
473 |
$res = $this->consulterHref($url);
|
|
|
474 |
return $res->nom;
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
public function recupererNomSci($id) {
|
|
|
479 |
$req = 'SELECT nom_sci FROM coste_v0_1 WHERE num_nom = '.$id;
|
|
|
480 |
if ($this->html == 'htm') {
|
|
|
481 |
$req = str_replace('nom_sci', 'nom_sci_html as nom_sci', $req);
|
|
|
482 |
}
|
|
|
483 |
$res = $this->getBdd()->recuperer($req);
|
|
|
484 |
return $res['nom_sci'];
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
?>
|