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 == '') {
|
|
|
43 |
$requete = $this->assemblerLaRequete();
|
|
|
44 |
$resultat = $this->getBdd()->recupererTous($requete);
|
|
|
45 |
$this->testerResultat($resultat, $resultat_formate, $requete);
|
|
|
46 |
}
|
|
|
47 |
return $this->formerReponseHTTP($resultat_formate);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
public function testerResultat($resultat, &$resultat_formate, $requete) {
|
|
|
52 |
if ($resultat == '') { //cas ou coste/services/ ou la requete comporte des erreurs
|
|
|
53 |
$e = 'La requête SQL formée comporte une erreur!';
|
|
|
54 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
|
|
|
55 |
Debug::printr($requete);
|
|
|
56 |
} elseif ($resultat) {
|
|
|
57 |
$resultat_formate = $this->retournerResultatFormate($resultat);
|
|
|
58 |
} else {
|
|
|
59 |
if ($this->format_reponse = 'textes/relations') {
|
|
|
60 |
$resultat_formate = 'null';
|
|
|
61 |
} else {
|
|
|
62 |
$m = 'Données introuvables dans la base';
|
|
|
63 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$m);
|
|
|
64 |
Debug::printr($requete);
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
//---------------------------------TRAITER RESSOURCES-----------------------------------------------------------------
|
|
|
71 |
|
|
|
72 |
public function traiterRessources(&$ressources) {
|
|
|
73 |
if (isset($ressources) && !empty($ressources)) {
|
|
|
74 |
$this->table = Config::get('bdd_triples');
|
|
|
75 |
$this->table_ressources = $ressources;
|
|
|
76 |
if ($ressources[0] == 'relations') {
|
|
|
77 |
$this->traiterRelationsProjet($ressources);
|
|
|
78 |
$this->format_reponse .= '/relations';
|
|
|
79 |
} elseif (isset($this->table_ressources[0]) && !empty($this->table_ressources[0])) {
|
|
|
80 |
$this->traiterRessourceId($this->table_ressources[0]);
|
|
|
81 |
if (isset($this->table_ressources[1]) && !empty($this->table_ressources[1])) {
|
|
|
82 |
$this->format_reponse .= '/champ';
|
|
|
83 |
}
|
|
|
84 |
} else {
|
|
|
85 |
$e = "Erreur dans votre requête. <br/> Les ressources disponibles sont :
|
|
|
86 |
<li> /textes/#id (id correspondant au tag de la page </li>
|
|
|
87 |
<li> /textes/#id/#champ+#champ </li>
|
|
|
88 |
<li> /textes/relations/bdtfx/#id (id correspondant au num_nom du projet bdtfx </li>";
|
|
|
89 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
90 |
}
|
|
|
91 |
} else {
|
|
|
92 |
$this->traiterRessourcesListe();
|
|
|
93 |
}
|
|
|
94 |
$this->requete_condition[] = "p.latest = 'Y'";
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public function traiterRessourceId($id) {
|
|
|
98 |
$this->format_reponse .= '/id';
|
|
|
99 |
if ($this->recherche == 'etendue') {
|
|
|
100 |
$id = '%'.str_replace(' ','%', $id).'%';
|
|
|
101 |
}
|
|
|
102 |
$this->requete_champ = ' t1.resource AS tag, t1.value AS num_nom, t2.value AS titre, p.body AS texte';
|
|
|
103 |
$this->requete_condition[] = 't1.resource LIKE '.$this->getBdd()->proteger($id);
|
|
|
104 |
$this->requete_condition[] = 't1.property = "num_nom"';
|
|
|
105 |
$this->requete_condition[] = '(t1.resource = t2.resource AND t2.property = "titre")';
|
|
|
106 |
$this->requete_condition[] = 't1.resource = p.tag';
|
|
|
107 |
$this->table = array(Config::get("bdd_triples").' t1',
|
|
|
108 |
Config::get("bdd_triples").' t2',
|
|
|
109 |
Config::get("bdd_pages").' p');
|
|
|
110 |
$this->ajouterRechercheFloue('t1.resource', $id);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
public function traiterRessourcesListe() {
|
|
|
114 |
$this->requete_condition[] = "t1.property = 'num_nom'";
|
|
|
115 |
$this->requete_condition[] = "(t1.resource = t2.resource AND t2.property = 'titre')";
|
|
|
116 |
$this->requete_condition[] = "t1.resource = p.tag";
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
public function traiterRelationsProjet($tab_ress) {
|
|
|
120 |
$this->table = array(Config::get("bdd_triples")." t1", Config::get("bdd_pages")." p", Config::get("bdd_table").'_v0_1 c');
|
|
|
121 |
$projet = $tab_ress[1];
|
|
|
122 |
$num_nom = $tab_ress[2];
|
|
|
123 |
$nom_champ_projet = "flore_$projet"."_num";
|
|
|
124 |
if (isset($tab_ress[3])) {
|
|
|
125 |
$type = $tab_ress[3];
|
|
|
126 |
if (!in_array($type, array('cle', 'dsc'))) {
|
|
|
127 |
$e = "Le type de texte ne peut etre que clé ou description";
|
|
|
128 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
$this->requete_condition[] = "c.flore_bdnff_num = ".$this->getBdd()->proteger($num_nom);
|
|
|
132 |
$this->requete_condition[] = "t1.value = c.num_nom";
|
|
|
133 |
$this->requete_condition[] = "t1.property = 'num_nom'";
|
|
|
134 |
$this->requete_condition[] = "t1.resource = p.tag";
|
|
|
135 |
$this->requete_champ = 't1.resource AS tag, t1.value AS num_nom, p.body AS texte';
|
|
|
136 |
if (isset($type)) $this->requete_condition[] = "t1.resource LIKE ".$this->getBdd()->proteger(ucfirst($type.'%'));
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
public function ajouterRechercheFloue($nom_champ, $id) {
|
|
|
141 |
if ($this->recherche == 'floue') {
|
|
|
142 |
$id = $this->getBdd()->proteger($id);
|
|
|
143 |
$this->requete_condition[array_search("$nom_champ LIKE $id",
|
|
|
144 |
$this->requete_condition)] =
|
|
|
145 |
"($nom_champ LIKE $id)".
|
|
|
146 |
" OR ( SOUNDEX($nom_champ) = SOUNDEX($id))".
|
|
|
147 |
" OR SOUNDEX(REVERSE($nom_champ)) = SOUNDEX(REVERSE($id))))";
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
//---------------------------------------TRAITER PARAMETRES-------------------------------------------------------------
|
|
|
152 |
|
|
|
153 |
public function traiterParametres($parametres) {
|
|
|
154 |
if (isset($parametres) && !empty($parametres)) {
|
|
|
155 |
$this->table_param = $parametres;
|
|
|
156 |
if (isset($parametres['recherche']) && $parametres['recherche'] != '') {
|
|
|
157 |
$this->recherche = $parametres['recherche'];
|
|
|
158 |
}
|
|
|
159 |
foreach ($parametres as $param => $val) {
|
|
|
160 |
switch ($param) {
|
|
|
161 |
case 'retour_format' : $this->retour_format = $val; break;
|
|
|
162 |
case 'masque_titre' : $this->ajouterLeFiltreMasque('titre', $val); break;
|
|
|
163 |
case 'masque_famille' : $this->ajouterLeFiltreMasque('famille', $val); break;
|
|
|
164 |
case 'masque_ns' : $this->ajouterLeFiltreMasque('nom_sci', $val); break;
|
|
|
165 |
case 'masque_type' : $this->ajouterLeFiltreMasque('type', $val); break;
|
|
|
166 |
case 'masque_txt' : $this->ajouterLeFiltreMasque('texte', $val); break;
|
|
|
167 |
case 'masque_page' : $this->ajouterLeFiltreMasque('page',$val); break;
|
|
|
168 |
case 'masque_tome' : $this->ajouterLeFiltreMasque('tome',$val); break;
|
|
|
169 |
case 'navigation_depart': $this->limite_requete['depart'] = $val; break;
|
|
|
170 |
case 'navigation_limite': $this->limite_requete['limite'] = $val; break;
|
|
|
171 |
case 'recherche' : break;
|
|
|
172 |
default :
|
|
|
173 |
$e = "Erreur dans les paramètres de recherche de votre requête : </br> Le parametre $param n\'existe pas.";
|
|
|
174 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE,$e);
|
|
|
175 |
break;
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
public function ajouterLeFiltreMasque($masque, $valeur) {
|
|
|
183 |
if ($this->recherche == 'etendue') {
|
|
|
184 |
$valeur = '%'.str_replace(' ','%', $valeur).'%';
|
|
|
185 |
}
|
|
|
186 |
$valeur = $this->getBdd()->proteger($valeur);
|
|
|
187 |
$this->masque[] = "$masque=$valeur";
|
|
|
188 |
switch ($masque) {
|
|
|
189 |
case 'famille' :
|
|
|
190 |
break;
|
|
|
191 |
case 'nom_sci' :
|
|
|
192 |
$this->requete_condition[] = "t1.value = c.num_nom AND nom_sci LIKE $valeur)";
|
|
|
193 |
$this->ajouterRechercheFloue('nom_sci', $valeur);
|
|
|
194 |
$this->table[] = Config::get("bdd_table").'_v0_1 c';
|
|
|
195 |
break;
|
|
|
196 |
case 'type' :
|
|
|
197 |
$type = ($this->getBdd()->proteger($valeur) == '"cle"') ? 'Cle%' : 'Dsc%';
|
|
|
198 |
$this->requete_condition[] = 't1.resource LIKE '.$this->getBdd()->proteger($type);
|
|
|
199 |
break;
|
|
|
200 |
case 'texte' :
|
|
|
201 |
$this->requete_condition[] = "p.body LIKE $valeur";
|
|
|
202 |
$this->ajouterRechercheFloue('p.body', $valeur);
|
|
|
203 |
break;
|
|
|
204 |
case 'titre' :
|
|
|
205 |
$this->requete_condition[] = "t2.value LIKE $valeur";
|
|
|
206 |
$this->ajouterRechercheFloue('t2.value', $valeur);
|
|
|
207 |
break;
|
|
|
208 |
case 'page' :
|
|
|
209 |
$this->requete_condition[] = "t1.value = c.num_nom AND c.page = $valeur";
|
|
|
210 |
$this->table[] = Config::get("bdd_table").'_v0_1 c';
|
|
|
211 |
break;
|
|
|
212 |
case 'tome' :
|
|
|
213 |
$this->requete_condition[] = "t1.value = c.num_nom AND c.tome = $valeur";
|
|
|
214 |
$this->table[] = Config::get("bdd_table").'_v0_1 c';
|
|
|
215 |
break;
|
|
|
216 |
default :
|
|
|
217 |
break;
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
//-----------------------------FONCTIONS DASSEMBLAGE DE LA REQUETE-----------------------------------------------------
|
|
|
223 |
|
|
|
224 |
public function assemblerLaRequete() {
|
|
|
225 |
$requete = ' SELECT '.$this->requete_champ.
|
|
|
226 |
' FROM '.implode(', ', $this->table)
|
|
|
227 |
.$this->retourneRequeteCondition()
|
|
|
228 |
.$this->requete_group_by
|
|
|
229 |
.$this->formerRequeteLimite();
|
|
|
230 |
return $requete;
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
public function retourneRequeteCondition() {
|
|
|
235 |
$condition = '';
|
|
|
236 |
if ($this->requete_condition !== null) {
|
|
|
237 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
|
|
238 |
}
|
|
|
239 |
return $condition;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
public function formerRequeteLimite() {
|
|
|
243 |
if (in_array($this->format_reponse , array('textes/id', 'textes/id/relations'))) {
|
|
|
244 |
$this->requete_limite = '';
|
|
|
245 |
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
|
|
|
246 |
$this->limite_requete['depart'] =
|
|
|
247 |
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
|
|
|
248 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
|
|
249 |
} else {
|
|
|
250 |
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
|
|
|
251 |
}
|
|
|
252 |
return $this->requete_limite;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
/**
|
|
|
257 |
* Recupere le nombre total de résultat d'une requete lancée.
|
|
|
258 |
* Est utilisée lors de l'affichage du total dans le résultat retourné et pr déterminer les limites et départ
|
|
|
259 |
* @return nombre total de résultat
|
|
|
260 |
*/
|
|
|
261 |
public function recupererTotalResultat() {
|
|
|
262 |
$total = null;
|
|
|
263 |
$requete = 'SELECT count(*) as nombre FROM '
|
|
|
264 |
.implode(', ', $this->table).$this->retourneRequeteCondition()
|
|
|
265 |
.$this->requete_group_by;
|
|
|
266 |
$res = $this->getBdd()->recuperer($requete);
|
|
|
267 |
if ($res) {
|
|
|
268 |
$total = $res['nombre'];
|
|
|
269 |
} else {
|
|
|
270 |
$e = 'Données introuvables dans la base ou erreur dans la requête SQL';
|
|
|
271 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
|
|
|
272 |
}
|
|
|
273 |
return $total;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
//-------------------FONCTIONS POUR LE FORMATAGE EN JSON----------------------------------------------------------------
|
|
|
279 |
|
|
|
280 |
public function retournerResultatFormate($resultat) {
|
|
|
281 |
$reponse = '';
|
|
|
282 |
switch ($this->format_reponse) {
|
|
|
283 |
case 'textes' : $reponse = $this->formaterTextes($resultat); break;
|
|
|
284 |
case 'textes/relations' : $reponse = $this->formaterTextesRelations($resultat); break;
|
|
|
285 |
case 'textes/id' : $reponse = $this->formaterTextesId($resultat[0]); break;
|
|
|
286 |
case 'textes/id/champ' : $reponse = $this->formaterTextesIdChamp($resultat[0]); break;
|
|
|
287 |
default : break;
|
|
|
288 |
}
|
|
|
289 |
$reponse = json_encode($reponse);
|
|
|
290 |
return $reponse;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
public function formaterTextes($resultat) {
|
|
|
295 |
$this->ajouterEnteteResultat($resultat);
|
|
|
296 |
$reponse['entete'] = $this->table_retour;
|
|
|
297 |
$this->table_retour = array();
|
|
|
298 |
foreach ($resultat as $description) {
|
|
|
299 |
$tag = $description['tag'];
|
|
|
300 |
$this->afficherDonnees('titre', $description['titre']);
|
|
|
301 |
$type = (preg_match('/^Cle.*$/', $tag)) ? '1' : '2' ;
|
|
|
302 |
$this->afficherDonnees('type', $type);
|
|
|
303 |
$this->table_retour['texte'] = $description['texte'];
|
|
|
304 |
$reponse['resultat'][$tag] = $this->table_retour;
|
|
|
305 |
$this->table_retour = array();
|
|
|
306 |
$reponse['resultat'][$tag]['href'] = $this->ajouterHref('textes', $tag);
|
|
|
307 |
}
|
|
|
308 |
return $reponse;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
public function formaterTextesRelations($resultat) {
|
|
|
312 |
foreach ($resultat as $description) {
|
|
|
313 |
$tag = $description['tag'];
|
|
|
314 |
$type = (preg_match('/^Cle.*$/', $tag)) ? '1' : '2' ;
|
|
|
315 |
$this->afficherDonnees('type', $type);
|
|
|
316 |
$this->table_retour['texte'] = $description['texte'];
|
|
|
317 |
$reponse[$tag] = $this->table_retour;
|
|
|
318 |
$this->table_retour = array();
|
|
|
319 |
$reponse[$tag]['href'] = $this->ajouterHref('textes', $tag);
|
|
|
320 |
}
|
|
|
321 |
return $reponse;
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
public function ajouterEnteteResultat($resultat) {
|
|
|
325 |
if ($this->masque) {
|
|
|
326 |
$this->table_retour['masque'] = implode('&', $this->masque);
|
|
|
327 |
}
|
|
|
328 |
$this->table_retour['depart'] = $this->limite_requete['depart'];
|
|
|
329 |
$this->table_retour['limite'] = $this->limite_requete['limite'];
|
|
|
330 |
$this->table_retour['total'] = $this->total_resultat;
|
|
|
331 |
//formuler les urls
|
|
|
332 |
$url = $this->formulerUrl($this->total_resultat, '/'.$this->service);
|
|
|
333 |
if ($url['precedent'] != '') { $this->table_retour['href.precedent'] = $url['precedent']; }
|
|
|
334 |
if ($url['suivant'] != '') { $this->table_retour['href.suivant'] = $url['suivant']; }
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
public function formaterTextesId($reponse) {
|
|
|
339 |
|
|
|
340 |
$this->afficherDonnees('titre', $reponse['titre']);
|
|
|
341 |
$type = (preg_match('/^Cle.*$/', $reponse['tag'])) ? '2' : '1' ;
|
|
|
342 |
$this->afficherDonnees('type', $type);
|
|
|
343 |
$this->table_retour['texte'] = $reponse['texte'];
|
|
|
344 |
$this->afficherDonnees('id', $reponse['num_nom']);
|
|
|
345 |
|
|
|
346 |
return $this->table_retour;
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
|
|
|
350 |
public function formaterTextesIdChamp($resultat) {
|
|
|
351 |
//on recupère tous les resultats possibles
|
|
|
352 |
$reponse_id = $this->formaterTextesId($resultat);
|
|
|
353 |
$this->table_retour = array();
|
|
|
354 |
//on recupère les résultats demandés à partir du tableau de résultat complet
|
|
|
355 |
$this->table_retour['id'] = $resultat['tag'];
|
|
|
356 |
$champs = explode(' ', $this->table_ressources[1]);
|
|
|
357 |
foreach ($champs as $champ) {
|
|
|
358 |
if ($this->verifierValiditeChamp($champ, $reponse_id)) {
|
|
|
359 |
if (preg_match('/^[^.]+\.\*$/', $champ)) {
|
|
|
360 |
$this->afficherPointEtoile($champ, $reponse_id);
|
|
|
361 |
} else {
|
|
|
362 |
$this->table_retour[$champ] = $reponse_id[$champ];
|
|
|
363 |
}
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
return $this->table_retour;
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
public function afficherPointEtoile($champ, $reponse_id) {
|
|
|
371 |
preg_match('/^([^.]+\.)\*$/', $champ, $match);
|
|
|
372 |
foreach ($reponse_id as $chp => $valeur) {
|
|
|
373 |
if (strrpos($chp, $match[1]) !== false) {
|
|
|
374 |
$this->table_retour[$chp] = $valeur;
|
|
|
375 |
}
|
|
|
376 |
}
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
public function verifierValiditeChamp($champ, $reponse_id) {
|
|
|
381 |
$validite = false;
|
|
|
382 |
preg_match('/^([^.]+)(:?\.([^.]+))?$/', $champ, $match);
|
|
|
383 |
if (array_key_exists($match[1], $reponse_id)) {
|
|
|
384 |
$validite = true;
|
|
|
385 |
if (isset($match[2]) && !empty($match[2])) {
|
|
|
386 |
if ($match[1] == 'type') {
|
|
|
387 |
$suffixes = array('.code', '.href', '.*');
|
|
|
388 |
$validite = (in_array($match[2], $suffixes)) ? true : false;
|
|
|
389 |
} else {
|
|
|
390 |
$validite = false;
|
|
|
391 |
}
|
|
|
392 |
}
|
|
|
393 |
}
|
|
|
394 |
if (!$validite) {
|
|
|
395 |
$champs = implode('</li><li>', array_keys($reponse_id));
|
|
|
396 |
$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas. Les champs disponibles
|
|
|
397 |
sont : <li>'.$champs.'</li>';
|
|
|
398 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
|
|
|
399 |
}
|
|
|
400 |
return $validite;
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
//------------------------------------------------Fonction d'affichage ------------------------------------------------
|
|
|
405 |
|
|
|
406 |
public function afficherDonnees($champ, $valeur) {
|
|
|
407 |
if ($this->retour_format == 'min') {
|
|
|
408 |
$champ = ($champ == 'type') ? $champ.'.code' : $champ;
|
|
|
409 |
$this->table_retour[$champ] = $valeur;
|
|
|
410 |
} else {
|
|
|
411 |
$this->afficherDonneesMax($champ, $valeur);
|
|
|
412 |
}
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
public function afficherDonneesMax($champ, $valeur) {
|
|
|
417 |
if ($champ == 'id') {
|
|
|
418 |
$this->table_retour[$champ] = "coste.".$valeur;
|
|
|
419 |
$this->table_retour['nom_sci'] = $this->recupererNomSci($valeur);
|
|
|
420 |
$this->table_retour['id.href'] = $this->ajouterHref('noms', $valeur);
|
|
|
421 |
} elseif (in_array($champ, array('type'))) {
|
|
|
422 |
$this->table_retour[$champ.'.code'] = $valeur;
|
|
|
423 |
$this->table_retour[$champ] = $this->recupererSignificationCode($valeur);
|
|
|
424 |
$this->table_retour[$champ.'.href'] = $this->ajouterHrefAutreProjet('ontologies', 'texteType:', $valeur, 'commun');
|
|
|
425 |
} else {
|
|
|
426 |
$this->table_retour[$champ] = $valeur;
|
|
|
427 |
}
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
public function recupererSignificationCode($code) {
|
|
|
432 |
$url = $this->ajouterHrefAutreProjet('ontologies', 'texteType:', $code.'/nom', 'commun');
|
|
|
433 |
$res = $this->consulterHref($url);
|
|
|
434 |
return $res->nom;
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
|
|
|
438 |
public function recupererNomSci($id) {
|
|
|
439 |
$req = 'SELECT nom_sci FROM coste_v0_1 WHERE num_nom = '.$id;
|
|
|
440 |
if ($this->html == 'htm') {
|
|
|
441 |
$req = str_replace('nom_sci', 'nom_sci_html as nom_sci', $req);
|
|
|
442 |
}
|
|
|
443 |
$res = $this->getBdd()->recuperer($req);
|
|
|
444 |
return $res['nom_sci'];
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
?>
|