584 |
mathilde |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* /syntaxons --> retourne l'ensemble des tuples de la table
|
|
|
5 |
* /syntaxons?masque.catminat=#catminat&masque.niveau=#niveau etc.--> retourne les syntaxons répondant à ces critères
|
|
|
6 |
*
|
|
|
7 |
* * @package eflore-projets
|
|
|
8 |
* @author mathilde Salthun-Lassalle
|
|
|
9 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
10 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
11 |
* @version 1.0
|
|
|
12 |
* @copyright 1999-2012 Tela Botanica (accueil@tela-botanica.org)
|
|
|
13 |
*
|
|
|
14 |
*/
|
|
|
15 |
|
|
|
16 |
class SyntaxonsTous extends SyntaxonsCommun {
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
function __construct(Conteneur $conteneur) {
|
|
|
20 |
parent::__construct($conteneur);
|
|
|
21 |
$this->champs_recherches = 'cle, code_catminat, syntaxon, code_fixe_nom, code_natura_2000, niveau ';
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function consulter($ressources, $parametres) {
|
|
|
25 |
$this->ressources = $ressources;
|
|
|
26 |
$this->parametres = $parametres;
|
|
|
27 |
$this->traiterParametres();
|
|
|
28 |
$this->definirTables();
|
|
|
29 |
$resultats = null;
|
|
|
30 |
foreach ($this->table_version as $version) {
|
|
|
31 |
$this->table = $version;
|
|
|
32 |
$requete = $this->assemblerLaRequete();
|
|
|
33 |
$resultat = $this->Bdd->recupererTous($requete);
|
|
|
34 |
$versionResultat = $this->traiterResultat($resultat);
|
|
|
35 |
if (count($this->table_version) > 1) {
|
|
|
36 |
$resultats[$version] = $versionResultat;
|
|
|
37 |
} else {
|
|
|
38 |
$resultats = $versionResultat;
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
return $resultats;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
//+-------------------------------------traitement des ressources et des paramètres----------------------------------------+//
|
|
|
47 |
|
|
|
48 |
public function traiterParametres() {
|
|
|
49 |
if (isset($this->parametres) && !empty($this->parametres) ) {
|
|
|
50 |
foreach ($this->parametres as $param => $valeur) {
|
|
|
51 |
switch ($param) {
|
|
|
52 |
case 'navigation.depart' :
|
|
|
53 |
$this->definirNavigationDepart($valeur);
|
|
|
54 |
break;
|
|
|
55 |
case 'navigation.limite' :
|
|
|
56 |
$this->definirNavigationLimite($valeur);
|
|
|
57 |
break;
|
|
|
58 |
case 'version.projet' :
|
|
|
59 |
$this->traiterVersion($valeur);
|
|
|
60 |
break;
|
|
|
61 |
case 'masque.catminat' :
|
|
|
62 |
$this->traiterCatminat($valeur);
|
|
|
63 |
break;
|
|
|
64 |
case 'masque.niveau' :
|
|
|
65 |
$this->traiterNiveau($valeur);
|
|
|
66 |
break;
|
|
|
67 |
case 'masque.retenu' :
|
|
|
68 |
$this->traiterRetenu($valeur);
|
|
|
69 |
break;
|
|
|
70 |
case 'masque.fixe' :
|
|
|
71 |
$this->requete_condition[] = ' code_fixe_nom = \''.$valeur.'\' ';
|
|
|
72 |
break;
|
|
|
73 |
case 'retour.champs' :
|
|
|
74 |
$this->champs_recherches .= ','.$valeur.' ';
|
|
|
75 |
break;
|
|
|
76 |
default :
|
|
|
77 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
|
|
78 |
.$param.' " n\'existe pas.';
|
|
|
79 |
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e); break;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
public function traiterRetenu($valeur) {
|
|
|
87 |
$valeur = trim($valeur);
|
|
|
88 |
if( $valeur == 'true') {
|
|
|
89 |
$this->requete_condition[] = ' niveau NOT LIKE \'syn%\' ';
|
|
|
90 |
} elseif ( $valeur == 'false') {
|
|
|
91 |
$this->requete_condition[] = ' niveau LIKE \'syn%\' ';
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public function traiterCatminat($valeur) {
|
|
|
96 |
$valeur = trim($valeur);
|
|
|
97 |
$valeur = str_replace('-', '/', $valeur);
|
|
|
98 |
$this->requete_condition[] = ' code_catminat = '.$this->getBdd()->proteger($valeur).'';
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public function traiterNiveau($valeur) {
|
|
|
102 |
$valeur = strtoupper(trim($valeur));
|
|
|
103 |
if (in_array($valeur,$this->niv)) {
|
|
|
104 |
$this->requete_condition[] = ' niveau = '.$this->getBdd()->proteger($valeur).'';
|
|
|
105 |
//$this->requete_condition[] = ' code_catminat = '.$this->catminat.'';
|
|
|
106 |
} else {
|
|
|
107 |
$e = "Erreur : valeur inconnue pour masque.niveau."
|
|
|
108 |
." valeurs possibles : ALL|ORD|CLA|SUBCLA|SUBORD|SUBALL|ASS|SUBASS|BC|DC|GRPT";
|
|
|
109 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
//+--------------------------formatages de resultats -------------------------------------------+
|
|
|
115 |
|
|
|
116 |
public function retournerResultatFormate($resultat) {
|
|
|
117 |
$resultat_json = array();
|
|
|
118 |
$resultat_json['entete'] = $this->ajouterEnteteResultat();
|
|
|
119 |
foreach ($resultat as $cle => $res) {
|
|
|
120 |
$resultat[$cle]['href'] = $this->ajouterHref('syntaxons','cle:'.$res['cle']);
|
|
|
121 |
$resultat[$cle] = array_merge($resultat[$cle],$this->traiterOntologieNiveau($res['niveau']));
|
|
|
122 |
unset($resultat[$cle]['niveau']);
|
|
|
123 |
}
|
|
|
124 |
$resultat_json['resultat'] = $resultat;
|
|
|
125 |
return $resultat_json;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
public function ajouterEnteteResultat() {
|
|
|
131 |
$entete['depart'] = $this->limite_requete['depart'];
|
|
|
132 |
$entete['limite'] = $this->limite_requete['limite'];
|
|
|
133 |
$entete['total'] = $this->total_resultat;
|
|
|
134 |
$entete['version'] = $this->version_projet;
|
|
|
135 |
$ressources = (empty($this->ressources)) ? '/syntaxons' : '/syntaxons/' ;
|
|
|
136 |
$url = $this->formulerUrl($this->total_resultat, $ressources.implode('/',$this->ressources));
|
|
|
137 |
if (isset($url['precedent']) && $url['precedent'] != '') {
|
|
|
138 |
$entete['href.precedent'] = $url['precedent'];
|
|
|
139 |
}
|
|
|
140 |
if (isset($url['suivant']) && $url['suivant'] != '') {
|
|
|
141 |
$entete['href.suivant'] = $url['suivant'];
|
|
|
142 |
}
|
|
|
143 |
return $entete;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
?>
|