1 |
<?php
|
1 |
<?php
|
2 |
|
2 |
|
3 |
/**
|
3 |
/**
|
4 |
* Classe InformationsBaseflor.php permet de faire des requetes de baseflor en fonction d'un référentiel
|
4 |
* Classe InformationsBaseflor.php permet de faire des requetes de baseflor en fonction d'un référentiel
|
5 |
*( BDTFX, BDAFX, BDBFX ) et d'un numéro nomenclatural ( différent de 0 ).
|
5 |
*( BDTFX, BDAFX, BDBFX ) et d'un numéro nomenclatural ( différent de 0 ).
|
6 |
* fin d'url possibles :
|
6 |
* fin d'url possibles :
|
7 |
* /informations/#bdnt.nn:#num_nomen --> retourne tous les champs pour un BDNT et un num_nomen
|
7 |
* /informations/#bdnt.nn:#num_nomen --> retourne tous les champs pour un BDNT et un num_nomen
|
8 |
* /informations/#bdnt.nn:#num_nomen?champs=description --> retourne champs description pour un BDNT et un num_nomen
|
8 |
* /informations/#bdnt.nn:#num_nomen?champs=description --> retourne champs description pour un BDNT et un num_nomen
|
9 |
* /informations/#bdnt.nn:#num_nomen?champs=ecologie --> retourne champs ecologiques pour un BDNT et un num_nomen
|
9 |
* /informations/#bdnt.nn:#num_nomen?champs=ecologie --> retourne champs ecologiques pour un BDNT et un num_nomen
|
10 |
*
|
10 |
*
|
11 |
*
|
11 |
*
|
12 |
* Encodage en entrée : utf8
|
12 |
* Encodage en entrée : utf8
|
13 |
* Encodage en sortie : utf8
|
13 |
* Encodage en sortie : utf8
|
14 |
* @package eflore-projets
|
14 |
* @package eflore-projets
|
15 |
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
|
15 |
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
|
16 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
16 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
17 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
17 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
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>
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
20 |
* @version 1.0
|
20 |
* @version 1.0
|
21 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
21 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
22 |
*/
|
22 |
*/
|
23 |
|
23 |
|
24 |
class InformationsBaseflor extends Commun{
|
24 |
class InformationsBaseflor extends Commun{
|
25 |
|
25 |
|
26 |
protected $table = "";
|
26 |
protected $table = "";
|
27 |
private $format_reponse = 'informations';
|
27 |
private $format_reponse = 'informations';
|
28 |
private $retour_format = 'max';
|
28 |
private $retour_format = 'max';
|
29 |
private $champs_ontologiques = array();
|
29 |
private $champs_ontologiques = array();
|
30 |
protected $serviceNom = 'informations';
|
30 |
protected $serviceNom = 'informations';
|
31 |
private $Bdd;
|
31 |
private $Bdd;
|
32 |
private $requete_condition = "";
|
32 |
private $requete_condition = "";
|
33 |
private $champs_recherches = '*';
|
33 |
private $champs_recherches = '*';
|
34 |
private $resultat_json;
|
34 |
private $resultat_json;
|
35 |
|
35 |
|
36 |
|
36 |
|
37 |
public function consulter($ressources, $parametres) {
|
37 |
public function consulter($ressources, $parametres) {
|
38 |
$this->ressources = $ressources;
|
38 |
$this->ressources = $ressources;
|
39 |
$this->parametres = $parametres;
|
39 |
$this->parametres = $parametres;
|
40 |
$this->traiterParametres();
|
40 |
$this->traiterParametres();
|
41 |
$this->definirTables();
|
41 |
$this->definirTables();
|
42 |
$this->traiterRessources();
|
42 |
$this->traiterRessources();
|
43 |
$resultats = null;
|
43 |
$resultats = null;
|
44 |
foreach ($this->table_version as $version) {
|
44 |
foreach ($this->table_version as $version) {
|
45 |
$this->table = $version;
|
45 |
$this->table = $version;
|
46 |
$requete = $this->assemblerLaRequete();
|
46 |
$requete = $this->assemblerLaRequete();
|
47 |
$resultat = $this->Bdd->recupererTous($requete);
|
47 |
$resultat = $this->Bdd->recupererTous($requete);
|
48 |
$versionResultat = $this->analyserResultat($resultat);
|
48 |
$versionResultat = $this->analyserResultat($resultat);
|
49 |
if (count($this->table_version) > 1) {
|
49 |
if (count($this->table_version) > 1) {
|
50 |
$resultats[$version] = $versionResultat;
|
50 |
$resultats[$version] = $versionResultat;
|
51 |
} else {
|
51 |
} else {
|
52 |
$resultats = $versionResultat;
|
52 |
$resultats = $versionResultat;
|
53 |
}
|
53 |
}
|
54 |
}
|
54 |
}
|
55 |
return $resultats;
|
55 |
return $resultats;
|
56 |
}
|
56 |
}
|
57 |
|
57 |
|
58 |
public function __construct(Conteneur $Conteneur) {
|
58 |
public function __construct(Conteneur $Conteneur) {
|
59 |
$this->Bdd = $Conteneur->getBdd();
|
59 |
$this->Bdd = $Conteneur->getBdd();
|
60 |
}
|
60 |
}
|
61 |
|
61 |
|
62 |
|
62 |
|
63 |
public function analyserResultat($resultat) {
|
63 |
public function analyserResultat($resultat) {
|
64 |
$versionResultat = null;
|
64 |
$versionResultat = null;
|
65 |
if ($resultat == '') {
|
65 |
if ($resultat == '') {
|
66 |
$message = 'La requête SQL formée comporte une erreur!';
|
66 |
$message = 'La requête SQL formée comporte une erreur!';
|
67 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
67 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
68 |
throw new Exception($message, $code);
|
68 |
throw new Exception($message, $code);
|
69 |
} elseif ($resultat) {
|
69 |
} elseif ($resultat) {
|
70 |
$versionResultat = $this->retournerResultatFormate($resultat);
|
70 |
$versionResultat = $this->retournerResultatFormate($resultat);
|
71 |
}
|
71 |
}
|
72 |
return $versionResultat;
|
72 |
return $versionResultat;
|
73 |
}
|
73 |
}
|
74 |
|
74 |
|
75 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
75 |
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
|
76 |
public function traiterParametres() {
|
76 |
public function traiterParametres() {
|
77 |
if (isset($this->parametres) && !empty($this->parametres)) {
|
77 |
if (isset($this->parametres) && !empty($this->parametres)) {
|
78 |
foreach ($this->parametres as $param => $valeur) {
|
78 |
foreach ($this->parametres as $param => $valeur) {
|
79 |
switch ($param) {
|
79 |
switch ($param) {
|
80 |
case 'categorie' :
|
80 |
case 'categorie' :
|
81 |
if ($valeur == "description") {
|
81 |
if ($valeur == "description") {
|
82 |
$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
|
82 |
$this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence,"
|
83 |
." sexualite, ordre_maturation, "
|
83 |
." sexualite, ordre_maturation, "
|
84 |
."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
|
84 |
."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, "
|
85 |
."form_vegetale ";
|
85 |
."form_vegetale ";
|
86 |
$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
|
86 |
$this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ".
|
87 |
"OR sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
|
87 |
"OR sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ".
|
88 |
"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
|
88 |
"OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ".
|
89 |
"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
|
89 |
"OR floraison != '' OR type_bio != '' OR form_vegetale != '' )";
|
90 |
}elseif ($valeur == "ecologie") {
|
90 |
}elseif ($valeur == "ecologie") {
|
91 |
$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
|
91 |
$this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature,"
|
92 |
." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
|
92 |
." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol,"
|
93 |
." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
|
93 |
." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, "
|
94 |
." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
|
94 |
." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph,"
|
95 |
." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
|
95 |
." vi_reaction_sol, vi_nutriments_sol, vi_salinite ";
|
96 |
$this->requete_condition[] = "( ve_lumiere != '' OR ve_temperature != '' ".
|
96 |
$this->requete_condition[] = "( ve_lumiere != '' OR ve_temperature != '' ".
|
97 |
"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
|
97 |
"OR ve_continentalite != '' OR ve_humidite_atmos != '' ".
|
98 |
"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
|
98 |
"OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ".
|
99 |
"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
|
99 |
"OR ve_nutriments_sol != '' OR ve_salinite != '' ".
|
100 |
"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
|
100 |
"OR ve_texture_sol != '' OR ve_mat_org_sol != '' )";
|
101 |
} else {
|
101 |
} else {
|
102 |
$e = "Valeur de paramètre inconnue pour 'categorie'.";
|
102 |
$e = "Valeur de paramètre inconnue pour 'categorie'.";
|
103 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
103 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
104 |
}
|
104 |
}
|
105 |
break;
|
105 |
break;
|
106 |
case 'retour.format' :
|
106 |
case 'retour.format' :
|
107 |
if ($valeur == 'min' || $valeur == 'max') {
|
107 |
if ($valeur == 'min' || $valeur == 'max') {
|
108 |
$this->retour_format = $valeur;
|
108 |
$this->retour_format = $valeur;
|
109 |
break;
|
109 |
break;
|
110 |
} else {
|
110 |
} else {
|
111 |
$e = "Valeur de paramètre inconnue pour 'retour.format'.";
|
111 |
$e = "Valeur de paramètre inconnue pour 'retour.format'.";
|
112 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
112 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
113 |
}
|
113 |
}
|
114 |
case 'version.projet' :
|
114 |
case 'version.projet' :
|
115 |
$this->traiterVersion($valeur);
|
115 |
$this->traiterVersion($valeur);
|
116 |
break;
|
116 |
break;
|
117 |
default :
|
117 |
default :
|
118 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
118 |
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
|
119 |
.$param.' " n\'existe pas.';
|
119 |
.$param.' " n\'existe pas.';
|
120 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
120 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
121 |
break;
|
121 |
break;
|
122 |
}
|
122 |
}
|
123 |
}
|
123 |
}
|
124 |
}
|
124 |
}
|
125 |
}
|
125 |
}
|
126 |
|
126 |
|
127 |
|
127 |
|
128 |
|
128 |
|
129 |
public function traiterRessources() {
|
129 |
public function traiterRessources() {
|
130 |
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
|
130 |
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){
|
131 |
switch ($retour[1]) {
|
131 |
switch ($retour[1]) {
|
132 |
case 'bdtfx' :
|
132 |
case 'bdtfx' :
|
133 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
|
133 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDTFX' ";
|
134 |
break;
|
134 |
break;
|
135 |
case 'bdafx' :
|
135 |
case 'bdafx' :
|
136 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
|
136 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDAFX' ";
|
137 |
break;
|
137 |
break;
|
138 |
case 'bdbfx' :
|
138 |
case 'bdbfx' :
|
139 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
|
139 |
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND BDNT = 'BDBFX' ";
|
140 |
break;
|
140 |
break;
|
141 |
default :
|
141 |
default :
|
142 |
$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
|
142 |
$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
|
143 |
.$retour[1].' " n\'existe pas.';
|
143 |
.$retour[1].' " n\'existe pas.';
|
144 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
144 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
145 |
break;
|
145 |
break;
|
146 |
}
|
146 |
}
|
147 |
|
147 |
|
148 |
} else {
|
148 |
} else {
|
149 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.';
|
149 |
$e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.';
|
150 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
150 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
151 |
break;
|
151 |
break;
|
152 |
}
|
152 |
}
|
153 |
}
|
153 |
}
|
154 |
|
154 |
|
155 |
//+++------------------------------traitement des versions----------------------------------------++
|
155 |
//+++------------------------------traitement des versions----------------------------------------++
|
156 |
|
156 |
|
157 |
public function traiterVersion($valeur) {
|
157 |
public function traiterVersion($valeur) {
|
158 |
if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '*' || $valeur == '+') {
|
158 |
if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '*' || $valeur == '+') {
|
159 |
$this->version_projet = $valeur;
|
159 |
$this->version_projet = $valeur;
|
160 |
} else {
|
160 |
} else {
|
161 |
$e = "Erreur : La version est inconnue.";
|
161 |
$e = "Erreur : La version est inconnue.";
|
162 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
162 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
163 |
}
|
163 |
}
|
164 |
|
164 |
|
165 |
}
|
165 |
}
|
166 |
|
166 |
|
167 |
public function definirTables() {
|
167 |
public function definirTables() {
|
168 |
$table_num_version = $this->recupererVersionDisponible();
|
168 |
$table_num_version = $this->recupererVersionDisponible();
|
169 |
$prefixe_table = config::get('bdd_table');
|
169 |
$prefixe_table = config::get('bdd_table');
|
170 |
if ( in_array($this->version_projet,$table_num_version) ) {
|
170 |
if ( in_array($this->version_projet,$table_num_version) ) {
|
171 |
$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
|
171 |
$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
|
172 |
} elseif ($this->version_projet == '+') {
|
172 |
} elseif ($this->version_projet == '+') {
|
173 |
$derniere_version = $table_num_version[count($table_num_version) - 1];
|
173 |
$derniere_version = $table_num_version[count($table_num_version) - 1];
|
174 |
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
|
174 |
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
|
175 |
} elseif ($this->version_projet == '*') {
|
175 |
} elseif ($this->version_projet == '*') {
|
176 |
foreach ($table_num_version as $num_version) {
|
176 |
foreach ($table_num_version as $num_version) {
|
177 |
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
|
177 |
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
|
178 |
}
|
178 |
}
|
179 |
} else {
|
179 |
} else {
|
180 |
$e = "Erreur : La version est inconnue.";
|
180 |
$e = "Erreur : La version est inconnue.";
|
181 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
181 |
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
|
182 |
}
|
182 |
}
|
183 |
}
|
183 |
}
|
184 |
|
184 |
|
185 |
//+--------------------------formatages de resultats -------------------------------------------+
|
185 |
//+--------------------------formatages de resultats -------------------------------------------+
|
186 |
|
186 |
|
187 |
public function retournerResultatFormate($resultat) {
|
187 |
public function retournerResultatFormate($resultat) {
|
188 |
$resultat_json = $resultat[0];
|
188 |
$resultat_json = $resultat[0];
|
189 |
if ($this->retour_format == 'max'){
|
189 |
if ($this->retour_format == 'max'){
|
190 |
if (!isset($this->parametres['categorie']) ) {
|
190 |
if (!isset($this->parametres['categorie']) ) {
|
191 |
$this->formaterResultatsTousChamps($resultat_json);
|
191 |
$this->formaterResultatsTousChamps($resultat_json);
|
192 |
} elseif ($this->parametres['categorie'] == 'ecologie') {
|
192 |
} elseif ($this->parametres['categorie'] == 'ecologie') {
|
193 |
$this->formaterResultatsChampsEcologie($resultat_json);
|
193 |
$this->formaterResultatsChampsEcologie($resultat_json);
|
194 |
} elseif ($this->parametres['categorie'] == 'description') {
|
194 |
} elseif ($this->parametres['categorie'] == 'description') {
|
195 |
$this->formaterResultatsChampsDescription($resultat_json);
|
195 |
$this->formaterResultatsChampsDescription($resultat_json);
|
196 |
}
|
196 |
}
|
197 |
}
|
197 |
}
|
198 |
return $this->resultat_json;
|
198 |
return $this->resultat_json;
|
199 |
}
|
199 |
}
|
200 |
|
200 |
|
201 |
public function formaterResultatsTousChamps($resultat) {
|
201 |
public function formaterResultatsTousChamps($resultat) {
|
202 |
$this->resultat_json = $resultat;
|
202 |
$this->resultat_json = $resultat;
|
203 |
$this->traiterTypeBio();
|
203 |
$this->traiterTypeBio();
|
204 |
$graphique_presence = $this->traiterOntologieEcologie() ;
|
204 |
$graphique_presence = $this->traiterOntologieEcologie() ;
|
205 |
if ($graphique_presence) {
|
205 |
if ($graphique_presence) {
|
206 |
$graphique = $this->ajouterLiensGraphique();
|
206 |
$graphique = $this->ajouterLiensGraphique();
|
207 |
}
|
207 |
}
|
208 |
}
|
208 |
}
|
209 |
|
209 |
|
210 |
public function formaterResultatsChampsEcologie($resultat) {
|
210 |
public function formaterResultatsChampsEcologie($resultat) {
|
211 |
$this->resultat_json = $resultat;
|
211 |
$this->resultat_json = $resultat;
|
212 |
$graphique_presence = $this->traiterOntologieEcologie() ;
|
212 |
$graphique_presence = $this->traiterOntologieEcologie() ;
|
213 |
if ($graphique_presence) {
|
213 |
if ($graphique_presence) {
|
214 |
$graphique = $this->ajouterLiensGraphique();
|
214 |
$graphique = $this->ajouterLiensGraphique();
|
215 |
}
|
215 |
}
|
216 |
}
|
216 |
}
|
217 |
|
217 |
|
218 |
|
218 |
|
219 |
public function formaterResultatsChampsDescription($resultat) {
|
219 |
public function formaterResultatsChampsDescription($resultat) {
|
220 |
$this->resultat_json = $resultat;
|
220 |
$this->resultat_json = $resultat;
|
221 |
$this->traiterTypeBio();
|
221 |
$this->traiterTypeBio();
|
222 |
}
|
222 |
}
|
223 |
|
223 |
|
224 |
public function traiterOntologieEcologie() {
|
224 |
public function traiterOntologieEcologie() {
|
225 |
$donnees_presence = false;
|
225 |
$donnees_presence = false;
|
226 |
$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
|
226 |
$this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques');
|
227 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
227 |
foreach ($this->champs_ontologiques as $cle => $valeur){
|
228 |
if ($this->resultat_json[$cle] != ""){
|
228 |
if ($this->resultat_json[$cle] != ""){
|
229 |
$donnees_presence = true;
|
229 |
$donnees_presence = true;
|
230 |
$this->recupererOntologies($this->resultat_json[$cle], $cle);
|
230 |
$this->recupererOntologies($this->resultat_json[$cle], $cle);
|
231 |
unset($this->resultat_json[$cle]);
|
231 |
unset($this->resultat_json[$cle]);
|
232 |
}
|
232 |
}
|
233 |
}
|
233 |
}
|
234 |
return $donnees_presence;
|
234 |
return $donnees_presence;
|
235 |
}
|
235 |
}
|
236 |
|
236 |
|
237 |
public function traiterTypeBio() {
|
237 |
public function traiterTypeBio() {
|
238 |
if ($this->resultat_json['type_bio'] != ""){
|
238 |
if ($this->resultat_json['type_bio'] != ""){
|
239 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
|
239 |
$tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']);
|
240 |
unset($this->resultat_json['type_bio']);
|
240 |
unset($this->resultat_json['type_bio']);
|
241 |
$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
|
241 |
$this->resultat_json= array_merge($this->resultat_json,$tab_ontologie);
|
242 |
}
|
242 |
}
|
243 |
}
|
243 |
}
|
244 |
|
244 |
|
245 |
public function ajouterLiensGraphique() {
|
245 |
public function ajouterLiensGraphique() {
|
246 |
$this->resultat_json['graphique_climat']['libelle'] = 'climat';
|
246 |
$this->resultat_json['graphique_climat']['libelle'] = 'climat';
|
247 |
$this->resultat_json['graphique_climat']['href'] =
|
247 |
$this->resultat_json['graphique_climat']['href'] =
|
248 |
$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
248 |
$this->ajouterHref('graphiques/climat', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
249 |
$this->resultat_json['graphique_sol']['libelle'] = 'sol';
|
249 |
$this->resultat_json['graphique_sol']['libelle'] = 'sol';
|
250 |
$this->resultat_json['graphique_sol']['href'] =
|
250 |
$this->resultat_json['graphique_sol']['href'] =
|
251 |
$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
251 |
$this->ajouterHref('graphiques/sol', strtolower($this->resultat_json['BDNT']).'.nn:'.$this->resultat_json['num_nomen']);
|
252 |
}
|
252 |
}
|
253 |
|
253 |
|
254 |
|
254 |
|
255 |
//+--------------------------traitement ontologies -------------------------------------------+
|
255 |
//+--------------------------traitement ontologies -------------------------------------------+
|
256 |
|
256 |
|
257 |
public function recupererOntologies($valeur, $champs){
|
257 |
public function recupererOntologies($valeur, $champs){
|
258 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
258 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
259 |
'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
|
259 |
'/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur));
|
260 |
$val = $this->consulterHref($url);
|
260 |
$val = $this->consulterHref($url);
|
261 |
$this->resultat_json[$champs.'.libelle'] = $val->nom;
|
261 |
$this->resultat_json[$champs.'.libelle'] = $val->nom;
|
262 |
$this->resultat_json[$champs.'.code'] = $valeur;
|
262 |
$this->resultat_json[$champs.'.code'] = $valeur;
|
263 |
$this->resultat_json[$champs.'.href'] = $url;
|
263 |
$this->resultat_json[$champs.'.href'] = $url;
|
264 |
}
|
264 |
}
|
265 |
|
265 |
|
266 |
//+-------------ontologie pour le champs type biologique (lire le .txt)---+
|
266 |
//+-------------ontologie pour le champs type biologique (lire le .txt)---+
|
267 |
|
267 |
|
268 |
public function recupererOntologiePrTypeBio($type_a_traiter){
|
268 |
public function recupererOntologiePrTypeBio($type_a_traiter){
|
269 |
$resultat_typeBio = "";
|
269 |
$resultat_typeBio = "";
|
270 |
if ($type_a_traiter != "") {
|
270 |
if ($type_a_traiter != "") {
|
271 |
$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
|
271 |
$types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter);
|
272 |
$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
|
272 |
$types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec);
|
273 |
$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
|
273 |
$resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter );
|
274 |
}
|
274 |
}
|
275 |
return $resultat_typeBio;
|
275 |
return $resultat_typeBio;
|
276 |
}
|
276 |
}
|
277 |
|
277 |
|
278 |
public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
|
278 |
public function classerPrimSecEnTypesSsTypes($types_prim_sec) {
|
279 |
$types_sstypes = '';
|
279 |
$types_sstypes = '';
|
280 |
foreach ($types_prim_sec as $cle => $tb) {
|
280 |
foreach ($types_prim_sec as $cle => $tb) {
|
281 |
$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
|
281 |
$types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle);
|
282 |
}
|
282 |
}
|
283 |
switch (count($types_sstypes)) {
|
283 |
switch (count($types_sstypes)) {
|
284 |
case 1 :
|
284 |
case 1 :
|
285 |
$types_sstypes = $types_sstypes['principal'];
|
285 |
$types_sstypes = $types_sstypes['principal'];
|
286 |
break;
|
286 |
break;
|
287 |
case 2 :
|
287 |
case 2 :
|
288 |
$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
|
288 |
$types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']);
|
289 |
break;
|
289 |
break;
|
290 |
}
|
290 |
}
|
291 |
return $types_sstypes;
|
291 |
return $types_sstypes;
|
292 |
}
|
292 |
}
|
293 |
|
293 |
|
294 |
|
294 |
|
295 |
public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
|
295 |
public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) {
|
296 |
$resultat_typeBio['type_bio.code'] = $type_a_traiter;
|
296 |
$resultat_typeBio['type_bio.code'] = $type_a_traiter;
|
297 |
foreach ($types_sstypes as $cle => $tb) {
|
297 |
foreach ($types_sstypes as $cle => $tb) {
|
298 |
if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
|
298 |
if (($cle == 'type.principal') || ($cle == 'type.secondaire')) {
|
299 |
$i = 0;
|
299 |
$i = 0;
|
300 |
foreach ($tb as $types) {
|
300 |
foreach ($tb as $types) {
|
301 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
301 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
302 |
'/ontologies/TB:'.urlencode(urlencode($types));
|
302 |
'/ontologies/TB:'.urlencode(urlencode($types));
|
303 |
$val = $this->consulterHref($url);
|
303 |
$val = $this->consulterHref($url);
|
304 |
$libelle[$cle][$i]= $val->nom;
|
304 |
$libelle[$cle][$i]= $val->nom;
|
305 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
305 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
306 |
$detail[$cle][$i]['code'] = $val->code;
|
306 |
$detail[$cle][$i]['code'] = $val->code;
|
307 |
$detail[$cle][$i]['href'] = $url;
|
307 |
$detail[$cle][$i]['href'] = $url;
|
308 |
$i++;
|
308 |
$i++;
|
309 |
}
|
309 |
}
|
310 |
}
|
310 |
}
|
311 |
if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
|
311 |
if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) {
|
312 |
$i = 0;
|
312 |
$i = 0;
|
313 |
foreach ($tb as $sstypes) {
|
313 |
foreach ($tb as $sstypes) {
|
314 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
314 |
$url = Config::get('url_service_base').Config::get('nom_projet').
|
315 |
'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
|
315 |
'/ontologies/ssTT:'.urlencode(urlencode($sstypes));
|
316 |
$val = $this->consulterHref($url);
|
316 |
$val = $this->consulterHref($url);
|
317 |
$libelle[$cle][$i]=$val->nom;
|
317 |
$libelle[$cle][$i]=$val->nom;
|
318 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
318 |
$detail[$cle][$i]['libelle'] = $val->nom;
|
319 |
$detail[$cle][$i]['code'] = $val->code;
|
319 |
$detail[$cle][$i]['code'] = $val->code;
|
320 |
$detail[$cle][$i]['href'] = $url;
|
320 |
$detail[$cle][$i]['href'] = $url;
|
321 |
$i++;
|
321 |
$i++;
|
322 |
}
|
322 |
}
|
323 |
}
|
323 |
}
|
324 |
}
|
324 |
}
|
325 |
//var_dump($libelle); exit;
|
325 |
//var_dump($libelle); exit;
|
326 |
$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
|
326 |
$resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle);
|
327 |
$resultat_typeBio['type_bio.detail'] = $detail;
|
327 |
$resultat_typeBio['type_bio.detail'] = $detail;
|
328 |
return $resultat_typeBio;
|
328 |
return $resultat_typeBio;
|
329 |
}
|
329 |
}
|
330 |
|
330 |
|
331 |
|
331 |
|
332 |
|
332 |
|
333 |
public function formaterTypeBioPrLibelle($info) {
|
333 |
public function formaterTypeBioPrLibelle($info) {
|
334 |
$libelle = implode(',',$info['type.principal'])." ";
|
334 |
$libelle = implode(', ',$info['type.principal'])." ";
|
335 |
$libelle .= isset($info['sous_type.principal']) ? " (".implode(',',$info['sous_type.principal']).") " : "";
|
335 |
$libelle .= isset($info['sous_type.principal']) ? " (".implode(', ',$info['sous_type.principal']).") " : "";
|
336 |
$libelle .= isset($info['type.secondaire']) ? ", ".implode(',',$info['type.secondaire'])." " : "";
|
336 |
$libelle .= isset($info['type.secondaire']) ? ", ".implode(', ',$info['type.secondaire'])." " : "";
|
337 |
$libelle .= isset($info['sous_type.secondaire']) ? "(".implode(',',$info['sous_type.secondaire']).") " : "";
|
337 |
$libelle .= isset($info['sous_type.secondaire']) ? "(".implode(', ',$info['sous_type.secondaire']).") " : "";
|
338 |
return $libelle;
|
338 |
return $libelle;
|
339 |
}
|
339 |
}
|
340 |
|
340 |
|
341 |
//séparation des principaux et des secondaires
|
341 |
//séparation des principaux et des secondaires
|
342 |
public function separerTypesPrimairesSecondaires($type) {
|
342 |
public function separerTypesPrimairesSecondaires($type) {
|
343 |
$types = array();
|
343 |
$types = array();
|
344 |
if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
|
344 |
if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) {
|
345 |
$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
|
345 |
$types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ;
|
346 |
$types['secondaire'] = $retour[2];
|
346 |
$types['secondaire'] = $retour[2];
|
347 |
} else {
|
347 |
} else {
|
348 |
$types['principal'] = $type;
|
348 |
$types['principal'] = $type;
|
349 |
}
|
349 |
}
|
350 |
return $types;
|
350 |
return $types;
|
351 |
}
|
351 |
}
|
352 |
|
352 |
|
353 |
|
353 |
|
354 |
public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
|
354 |
public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) {
|
355 |
$types = array();
|
355 |
$types = array();
|
356 |
if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
|
356 |
if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) {
|
357 |
//type
|
357 |
//type
|
358 |
$type = array();
|
358 |
$type = array();
|
359 |
$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
|
359 |
$type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ;
|
360 |
$type = explode(",", $type[0]);
|
360 |
$type = explode(",", $type[0]);
|
361 |
for ($i = 0 ; $i < count($type); $i++) {
|
361 |
for ($i = 0 ; $i < count($type); $i++) {
|
362 |
$types['type.'.$typePrimOuSec][$i] = $type[$i];
|
362 |
$types['type.'.$typePrimOuSec][$i] = $type[$i];
|
363 |
}
|
363 |
}
|
364 |
//sous types
|
364 |
//sous types
|
365 |
$ss_types = array();
|
365 |
$ss_types = array();
|
366 |
if (isset($retour[2]) && $retour[2] != '') {
|
366 |
if (isset($retour[2]) && $retour[2] != '') {
|
367 |
$ss_types[0] = $retour[2] ;
|
367 |
$ss_types[0] = $retour[2] ;
|
368 |
$ss_types = explode("-", $ss_types[0]);
|
368 |
$ss_types = explode("-", $ss_types[0]);
|
369 |
for ($i = 0 ; $i < count($ss_types); $i++) {
|
369 |
for ($i = 0 ; $i < count($ss_types); $i++) {
|
370 |
$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
|
370 |
$types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i];
|
371 |
}
|
371 |
}
|
372 |
}
|
372 |
}
|
373 |
}
|
373 |
}
|
374 |
return $types;
|
374 |
return $types;
|
375 |
}
|
375 |
}
|
376 |
|
376 |
|
377 |
|
377 |
|
378 |
|
378 |
|
379 |
|
379 |
|
380 |
|
380 |
|
381 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
381 |
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
|
382 |
|
382 |
|
383 |
public function assemblerLaRequete() {
|
383 |
public function assemblerLaRequete() {
|
384 |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
|
384 |
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
|
385 |
.$this->retournerRequeteCondition();
|
385 |
.$this->retournerRequeteCondition();
|
386 |
return $requete;
|
386 |
return $requete;
|
387 |
}
|
387 |
}
|
388 |
|
388 |
|
389 |
|
389 |
|
390 |
|
390 |
|
391 |
public function retournerRequeteCondition() {
|
391 |
public function retournerRequeteCondition() {
|
392 |
$condition = '';
|
392 |
$condition = '';
|
393 |
if (empty($this->requete_condition) == false) {
|
393 |
if (empty($this->requete_condition) == false) {
|
394 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
394 |
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
|
395 |
}
|
395 |
}
|
396 |
return $condition;
|
396 |
return $condition;
|
397 |
}
|
397 |
}
|
398 |
|
398 |
|
399 |
|
399 |
|
400 |
|
400 |
|
401 |
}
|
401 |
}
|
402 |
?>
|
402 |
?>
|