272 |
delphine |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe mère du module Liste.
|
|
|
5 |
*
|
|
|
6 |
* @category PHP 5.2
|
|
|
7 |
* @package eflore-consultation
|
|
|
8 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
9 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
|
|
10 |
* @copyright 2011 Tela-Botanica
|
|
|
11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
|
|
|
12 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
|
|
|
13 |
* @version $Id$
|
|
|
14 |
*/
|
|
|
15 |
class Description extends aControleur {
|
291 |
jpm |
16 |
|
|
|
17 |
private $conteneur = null;
|
294 |
delphine |
18 |
private $nomCourant = null;
|
291 |
jpm |
19 |
private $textes = null;
|
|
|
20 |
private $meta = null;
|
394 |
aurelien |
21 |
private $wikini = null;
|
541 |
mathilde |
22 |
private $informations = null;
|
|
|
23 |
private $mois = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août',
|
|
|
24 |
'septembre', 'octobre', 'novembre', 'décembre');
|
580 |
mathilde |
25 |
private $CosteFormate;
|
|
|
26 |
private $CosteTexte;
|
954 |
aurelien |
27 |
|
|
|
28 |
private $referentiel = 'bdtfx';
|
|
|
29 |
private $donnees = array();
|
625 |
jpm |
30 |
|
291 |
jpm |
31 |
public function __construct(Conteneur $conteneur) {
|
|
|
32 |
$this->conteneur = $conteneur;
|
294 |
delphine |
33 |
$this->nomCourant = $this->conteneur->getNomCourant();
|
954 |
aurelien |
34 |
$this->referentiel = $this->conteneur->getParametre('referentiel');
|
291 |
jpm |
35 |
$this->textes = $this->conteneur->getApiTextes();
|
394 |
aurelien |
36 |
$this->wikini = $this->conteneur->getApiWikini();
|
291 |
jpm |
37 |
$this->meta = $this->conteneur->getApiMetaDonnees();
|
541 |
mathilde |
38 |
$this->informations = $this->conteneur->getApiInformations();
|
291 |
jpm |
39 |
$this->appUrls = $this->conteneur->getAppUrls();
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function obtenirDonnees() {
|
|
|
43 |
$donnees = array();
|
954 |
aurelien |
44 |
$this->getWikipedia();
|
|
|
45 |
$this->getWikini();
|
|
|
46 |
$this->getDescriptionsDependantesReferentiel();
|
|
|
47 |
return $this->donnees;
|
272 |
delphine |
48 |
}
|
697 |
mathilde |
49 |
|
|
|
50 |
public function obtenirDonneesExport() {
|
|
|
51 |
$donnees = array();
|
954 |
aurelien |
52 |
$this->getWikini();
|
|
|
53 |
$this->getDescriptionsDependantesReferentiel();
|
|
|
54 |
return $this->donnees;
|
697 |
mathilde |
55 |
}
|
954 |
aurelien |
56 |
|
|
|
57 |
private function getDescriptionsDependantesReferentiel() {
|
|
|
58 |
$bases_descriptions = Config::get($this->referentiel.'.baseDescription');
|
|
|
59 |
$bases_descriptions = explode(',',$bases_descriptions);
|
|
|
60 |
|
|
|
61 |
foreach ($bases_descriptions as $base) {
|
|
|
62 |
if($this->aMethodeDescription($base)) {
|
|
|
63 |
$fonction = 'get'.ucfirst($base);
|
|
|
64 |
$this->$fonction();
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
private function aMethodeDescription($base) {
|
|
|
70 |
return method_exists($this, 'get'.$base);
|
|
|
71 |
}
|
957 |
aurelien |
72 |
|
|
|
73 |
public function getBloc() {
|
|
|
74 |
// prend la première description disponible dans l'ordre indiqué dans le fichier
|
|
|
75 |
// de config, et prend la description wiki sinon
|
|
|
76 |
if(Config::get($this->referentiel.'.baseDescription') != "") {
|
|
|
77 |
$bases_descriptions = Config::get($this->referentiel.'.baseDescription');
|
|
|
78 |
$bases_descriptions = explode(',',$bases_descriptions);
|
979 |
delphine |
79 |
foreach ($bases_descriptions as $base) {
|
|
|
80 |
if ($this->aMethodeDescription($base)) {
|
957 |
aurelien |
81 |
$fonction = 'get'.ucfirst($base);
|
|
|
82 |
$this->$fonction();
|
|
|
83 |
if(!empty($this->donnees[$base]['description'])) {
|
1010 |
raphael |
84 |
$this->donnees['type'] = $base;
|
957 |
aurelien |
85 |
$this->donnees['titre'] = "Description de ".ucfirst($base);
|
|
|
86 |
$this->donnees['description'] = $this->donnees[$base]['description'];
|
979 |
delphine |
87 |
unset($this->donnees[$base]);
|
957 |
aurelien |
88 |
break;
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
if (empty($this->donnees['description'])) {
|
1062 |
aurelien |
95 |
$this->getWikini();
|
|
|
96 |
$this->donnees['description'] = $this->donnees['wikini']['description'];
|
957 |
aurelien |
97 |
$this->donnees['titre'] = "Description collaborative";
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
return $this->donnees;
|
|
|
101 |
}
|
625 |
jpm |
102 |
|
541 |
mathilde |
103 |
private function getBaseflor() {
|
|
|
104 |
$baseflor = array();
|
|
|
105 |
$this->informations ->setProjet('baseflor');
|
|
|
106 |
$this->informations ->setBdnt($this->conteneur->getParametre('referentiel'));
|
987 |
delphine |
107 |
$this->informations ->setNum_nom($this->nomCourant->getNnr());
|
600 |
mathilde |
108 |
$informations = $this->informations->getInformationsDescription();
|
560 |
mathilde |
109 |
if ($informations){
|
954 |
aurelien |
110 |
$baseflor['chorologie'] = isset($informations['chorologie']) ? $informations['chorologie'] : '';
|
|
|
111 |
$baseflor['inflorescence'] = isset($informations['inflorescence']) ? $informations['inflorescence'] : '';
|
|
|
112 |
$baseflor['sexualite'] = isset($informations['sexualite']) ? $informations['sexualite'] : '';
|
|
|
113 |
$baseflor['ordre_maturation'] = isset($informations['ordre_maturation']) ? $informations['ordre_maturation'] : '';
|
|
|
114 |
$baseflor['pollinisation'] = isset($informations['pollinisation']) ? $informations['pollinisation'] : '';
|
|
|
115 |
$baseflor['dissemination'] = isset($informations['dissemination']) ? $informations['dissemination'] : '';
|
|
|
116 |
$baseflor['fruit'] = isset($informations['fruit']) ? $informations['fruit'] : '';
|
|
|
117 |
$baseflor['couleur_fleur'] = isset($informations['couleur_fleur']) ? $informations['couleur_fleur'] : '';
|
|
|
118 |
$baseflor['macule'] = isset($informations['macule']) ? $informations['macule'] : '';
|
|
|
119 |
$baseflor['floraison'] = isset($informations['floraison']) ? $this->changerFloraisonEnChaine($informations['floraison']) : '';
|
560 |
mathilde |
120 |
//récupérer dans ontologies
|
954 |
aurelien |
121 |
$baseflor['type_bio'] = isset($informations['type_bio']) ? $informations['type_bio'] : '';
|
|
|
122 |
$baseflor['form_vegetale'] = isset($informations['form_vegetale']) ? $informations['form_vegetale'] : '';
|
560 |
mathilde |
123 |
$baseflor['description']=$baseflor;
|
|
|
124 |
$this->meta->setProjet('baseflor');
|
|
|
125 |
$meta = $this->meta->getMetaDonnees();
|
|
|
126 |
$citation = $meta[0]['citation'];
|
|
|
127 |
$baseflor['meta']['citation'] = $citation;
|
|
|
128 |
$baseflor['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('baseflor');
|
|
|
129 |
}
|
954 |
aurelien |
130 |
$this->donnees['baseflor'] = $baseflor;
|
541 |
mathilde |
131 |
}
|
625 |
jpm |
132 |
|
541 |
mathilde |
133 |
public function changerFloraisonEnChaine($floraison){
|
|
|
134 |
$chaine = "";
|
|
|
135 |
if ($floraison != ""){
|
|
|
136 |
$mois_fleurs=preg_match('/-/',$floraison) ? preg_split('/-/',$floraison) : $floraison;
|
|
|
137 |
if (is_array($mois_fleurs)){
|
|
|
138 |
$chaine = "de ".$this->mois[(int)$mois_fleurs[0]]." à ".$this->mois[(int)$mois_fleurs[1]];
|
625 |
jpm |
139 |
|
541 |
mathilde |
140 |
}else { $chaine = "en ".$this->mois[(int)$mois_fleurs];
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
return $chaine;
|
|
|
144 |
}
|
965 |
aurelien |
145 |
|
|
|
146 |
public function getUrlWikipedia() {
|
|
|
147 |
if(!isset($this->donnees['wp'])) {
|
|
|
148 |
$this->getWikipedia();
|
|
|
149 |
}
|
|
|
150 |
return $this->donnees['wp'];
|
|
|
151 |
}
|
291 |
jpm |
152 |
|
709 |
aurelien |
153 |
public function getWikipedia() {
|
291 |
jpm |
154 |
$wp = array();
|
|
|
155 |
$this->textes->setProjet('wikipedia');
|
|
|
156 |
$this->textes->setId($this->getIdWp());
|
756 |
aurelien |
157 |
$wp['titre'] = $donnees['titre'] = "Description de wikipedia";
|
435 |
aurelien |
158 |
$wp['lien'] = $this->textes->getPageUrl();
|
291 |
jpm |
159 |
$wp['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('wikipedia');
|
954 |
aurelien |
160 |
$this->donnees['wp'] = $wp;
|
291 |
jpm |
161 |
}
|
|
|
162 |
|
|
|
163 |
private function getIdWp() {
|
294 |
delphine |
164 |
$nomSci = $this->nomCourant->getNomRetenu()->get('nom_sci');
|
291 |
jpm |
165 |
$idWp = str_replace(' ', '_', $nomSci);
|
295 |
jpm |
166 |
$idWp = urlencode($idWp);
|
291 |
jpm |
167 |
return $idWp;
|
|
|
168 |
}
|
625 |
jpm |
169 |
|
|
|
170 |
private function getWikini() {
|
394 |
aurelien |
171 |
$wikini = array();
|
|
|
172 |
$wikini['titre'] = 'Wikini';
|
|
|
173 |
$referentiel = $this->conteneur->getParametre('referentiel');
|
|
|
174 |
$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
|
|
|
175 |
$page_wiki = $this->wikini->getPageWikiPourRefEtNumTax($referentiel, $num_tax);
|
|
|
176 |
$wikini['description'] = $this->wikini->getTexteFormate($page_wiki, 'description');
|
954 |
aurelien |
177 |
$this->donnees['wikini'] = $wikini;
|
394 |
aurelien |
178 |
}
|
709 |
aurelien |
179 |
|
|
|
180 |
public function getLienWikini() {
|
|
|
181 |
$referentiel = $this->conteneur->getParametre('referentiel');
|
|
|
182 |
$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
|
|
|
183 |
return $this->wikini->getUrlPageWiki($referentiel, $num_tax);
|
|
|
184 |
}
|
625 |
jpm |
185 |
|
322 |
delphine |
186 |
private function getCoste() {
|
|
|
187 |
$coste = array();
|
|
|
188 |
$this->textes->setProjet('coste');
|
448 |
delphine |
189 |
$this->textes->setId('bdtfx.nn:'.$this->nomCourant->getNnr());
|
322 |
delphine |
190 |
$texte = $this->textes->getTexte();
|
1092 |
raphael |
191 |
$texte = array_pop($texte['resultats']);
|
570 |
mathilde |
192 |
if ($texte) {
|
|
|
193 |
$coste['titre'] = $texte['titre'];
|
1093 |
raphael |
194 |
$coste['description'] = self::mettreEnFormeCoste($texte['texte']);
|
570 |
mathilde |
195 |
}
|
322 |
delphine |
196 |
$this->meta->setProjet('coste');
|
444 |
delphine |
197 |
$meta = $this->meta->getMetaDonnees();
|
|
|
198 |
$citation = $meta[0]['citation'];
|
|
|
199 |
$coste['meta']['citation'] = $citation;
|
448 |
delphine |
200 |
$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
|
954 |
aurelien |
201 |
$this->donnees['coste'] = $coste;
|
322 |
delphine |
202 |
}
|
625 |
jpm |
203 |
|
1093 |
raphael |
204 |
static function mettreEnFormeCoste($texte) {
|
|
|
205 |
$txt_fmt = array();
|
580 |
mathilde |
206 |
//decouper elements remarquables avant le texte
|
1093 |
raphael |
207 |
self::separerNomScientifique_a_NomCommun($texte, $txt_fmt);
|
|
|
208 |
$texte = preg_replace('/\//','',$texte);
|
580 |
mathilde |
209 |
//decouper elements remarquables après le texte
|
1093 |
raphael |
210 |
self::separerEcologie_a_Usages($texte, $txt_fmt);
|
580 |
mathilde |
211 |
//le morceau qui reste est le gros de la description
|
1093 |
raphael |
212 |
$texte = str_replace(';','</br> -','- '.$texte);
|
|
|
213 |
$texte = str_replace('–','',$texte);
|
|
|
214 |
$txt_fmt['texte'] = $texte;
|
|
|
215 |
return $txt_fmt;
|
580 |
mathilde |
216 |
}
|
625 |
jpm |
217 |
|
|
|
218 |
|
1093 |
raphael |
219 |
static function separerNomScientifique_a_NomCommun(&$txt, &$txt_fmt){
|
|
|
220 |
if ( preg_match('/\*\*(.+)\*\*([^–]*)–/', $txt, $retour)){
|
570 |
mathilde |
221 |
/* !! attention on enlève un tiret cadratin – pas un trait d'union - !! */
|
580 |
mathilde |
222 |
$a_enlever = array('/–/','/\./' );
|
1093 |
raphael |
223 |
$txt_fmt['nom_scientifique'] = preg_replace($a_enlever,'',$retour[1]);
|
580 |
mathilde |
224 |
if(preg_match('/\((.+)\)/',$retour[2],$synonymes)){
|
1093 |
raphael |
225 |
$txt_fmt['synonymes'] = $synonymes[1];
|
580 |
mathilde |
226 |
} else {
|
1093 |
raphael |
227 |
$txt_fmt['nom_scientifique'] .= $retour[2];
|
580 |
mathilde |
228 |
}
|
1093 |
raphael |
229 |
$txt = str_replace($retour[0],'',$txt);
|
570 |
mathilde |
230 |
}
|
|
|
231 |
/* !! attention il y a un espace avant les // du début !! */
|
1093 |
raphael |
232 |
if ( preg_match('/^ \/\/([^\/\/]+)\/\//', $txt, $retour)){
|
570 |
mathilde |
233 |
$a_enlever = array('/–/','/\./' );
|
1093 |
raphael |
234 |
$txt_fmt['nom_commun'] = preg_replace($a_enlever,'',$retour[1]);
|
|
|
235 |
$txt = str_replace($retour[0],'',$txt);
|
570 |
mathilde |
236 |
}
|
580 |
mathilde |
237 |
}
|
625 |
jpm |
238 |
|
|
|
239 |
|
1093 |
raphael |
240 |
static function separerEcologie_a_Usages(&$txt, &$txt_fmt) {
|
|
|
241 |
if (preg_match('/\.\s*([A-ZÉÀÈ].+)$/',$txt, $retour)) {
|
|
|
242 |
$txt_fmt['ecologie'] = $retour[1];
|
|
|
243 |
$txt = str_replace($retour[0],'.',$txt);
|
|
|
244 |
if (isset($txt_fmt['ecologie']) && preg_match('/–(.+)/', $txt_fmt['ecologie'] , $retour)){
|
|
|
245 |
$txt_fmt['repartition'] = $retour[1];
|
|
|
246 |
$txt_fmt['ecologie'] = str_replace($retour[0],'',$txt_fmt['ecologie']);
|
570 |
mathilde |
247 |
}
|
1093 |
raphael |
248 |
if (isset($txt_fmt['repartition']) && preg_match('/=(.+)$/', $txt_fmt['repartition'], $retour)){
|
|
|
249 |
$txt_fmt['floraison'] = $retour[1];
|
|
|
250 |
$txt_fmt['repartition'] = str_replace($retour[0],'',$txt_fmt['repartition']);
|
570 |
mathilde |
251 |
}
|
1093 |
raphael |
252 |
if (isset($txt_fmt['floraison']) && preg_match('/–(.+)$|\n(.+)$/',$txt_fmt['floraison'], $retour)){
|
|
|
253 |
$txt_fmt['usages'] = isset($retour[1]) ? $retour[1] : $retour[2];
|
|
|
254 |
$txt_fmt['floraison'] = str_replace($retour[0],'.',$txt_fmt['floraison']);
|
570 |
mathilde |
255 |
}
|
1093 |
raphael |
256 |
if (isset($txt_fmt['floraison']) && preg_match('/([Ff]l\.) (.+)/',$txt_fmt['floraison'], $retour)){
|
|
|
257 |
$txt_fmt['floraison'] = $retour[2];
|
|
|
258 |
$txt_fmt['floraison'] = str_replace($retour[1],'',$txt_fmt['floraison']);
|
580 |
mathilde |
259 |
}
|
1093 |
raphael |
260 |
if (isset($txt_fmt['floraison']) && preg_match('/([Ff]r\.) (.+)/',$txt_fmt['floraison'], $retour)){
|
|
|
261 |
$txt_fmt['fructification'] = $retour[2];
|
|
|
262 |
$txt_fmt['floraison'] = str_replace($retour[0],'',$txt_fmt['floraison']);
|
|
|
263 |
$txt_fmt['floraison'] = str_replace(',','',$txt_fmt['floraison']);
|
|
|
264 |
$txt_fmt['fructification'] = str_replace($retour[1],'',$txt_fmt['fructification']);
|
|
|
265 |
$txt_fmt['fructification'] = str_replace('.','',$txt_fmt['fructification']);
|
580 |
mathilde |
266 |
}
|
625 |
jpm |
267 |
}
|
570 |
mathilde |
268 |
}
|
272 |
delphine |
269 |
}
|
|
|
270 |
?>
|