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'])) {
|
|
|
84 |
$this->donnees['titre'] = "Description de ".ucfirst($base);
|
|
|
85 |
$this->donnees['description'] = $this->donnees[$base]['description'];
|
979 |
delphine |
86 |
unset($this->donnees[$base]);
|
957 |
aurelien |
87 |
break;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
if (empty($this->donnees['description'])) {
|
|
|
94 |
$description = $this->getWikini();
|
|
|
95 |
$this->donnees['description'] = $description['description'];
|
|
|
96 |
$this->donnees['titre'] = "Description collaborative";
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
return $this->donnees;
|
|
|
100 |
}
|
625 |
jpm |
101 |
|
541 |
mathilde |
102 |
private function getBaseflor() {
|
|
|
103 |
$baseflor = array();
|
|
|
104 |
$this->informations ->setProjet('baseflor');
|
|
|
105 |
$this->informations ->setBdnt($this->conteneur->getParametre('referentiel'));
|
987 |
delphine |
106 |
$this->informations ->setNum_nom($this->nomCourant->getNnr());
|
600 |
mathilde |
107 |
$informations = $this->informations->getInformationsDescription();
|
560 |
mathilde |
108 |
if ($informations){
|
954 |
aurelien |
109 |
$baseflor['chorologie'] = isset($informations['chorologie']) ? $informations['chorologie'] : '';
|
|
|
110 |
$baseflor['inflorescence'] = isset($informations['inflorescence']) ? $informations['inflorescence'] : '';
|
|
|
111 |
$baseflor['sexualite'] = isset($informations['sexualite']) ? $informations['sexualite'] : '';
|
|
|
112 |
$baseflor['ordre_maturation'] = isset($informations['ordre_maturation']) ? $informations['ordre_maturation'] : '';
|
|
|
113 |
$baseflor['pollinisation'] = isset($informations['pollinisation']) ? $informations['pollinisation'] : '';
|
|
|
114 |
$baseflor['dissemination'] = isset($informations['dissemination']) ? $informations['dissemination'] : '';
|
|
|
115 |
$baseflor['fruit'] = isset($informations['fruit']) ? $informations['fruit'] : '';
|
|
|
116 |
$baseflor['couleur_fleur'] = isset($informations['couleur_fleur']) ? $informations['couleur_fleur'] : '';
|
|
|
117 |
$baseflor['macule'] = isset($informations['macule']) ? $informations['macule'] : '';
|
|
|
118 |
$baseflor['floraison'] = isset($informations['floraison']) ? $this->changerFloraisonEnChaine($informations['floraison']) : '';
|
560 |
mathilde |
119 |
//récupérer dans ontologies
|
954 |
aurelien |
120 |
$baseflor['type_bio'] = isset($informations['type_bio']) ? $informations['type_bio'] : '';
|
|
|
121 |
$baseflor['form_vegetale'] = isset($informations['form_vegetale']) ? $informations['form_vegetale'] : '';
|
560 |
mathilde |
122 |
$baseflor['description']=$baseflor;
|
|
|
123 |
$this->meta->setProjet('baseflor');
|
|
|
124 |
$meta = $this->meta->getMetaDonnees();
|
|
|
125 |
$citation = $meta[0]['citation'];
|
|
|
126 |
$baseflor['meta']['citation'] = $citation;
|
|
|
127 |
$baseflor['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('baseflor');
|
|
|
128 |
}
|
954 |
aurelien |
129 |
$this->donnees['baseflor'] = $baseflor;
|
541 |
mathilde |
130 |
}
|
625 |
jpm |
131 |
|
541 |
mathilde |
132 |
public function changerFloraisonEnChaine($floraison){
|
|
|
133 |
$chaine = "";
|
|
|
134 |
if ($floraison != ""){
|
|
|
135 |
$mois_fleurs=preg_match('/-/',$floraison) ? preg_split('/-/',$floraison) : $floraison;
|
|
|
136 |
if (is_array($mois_fleurs)){
|
|
|
137 |
$chaine = "de ".$this->mois[(int)$mois_fleurs[0]]." à ".$this->mois[(int)$mois_fleurs[1]];
|
625 |
jpm |
138 |
|
541 |
mathilde |
139 |
}else { $chaine = "en ".$this->mois[(int)$mois_fleurs];
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
return $chaine;
|
|
|
143 |
}
|
965 |
aurelien |
144 |
|
|
|
145 |
public function getUrlWikipedia() {
|
|
|
146 |
if(!isset($this->donnees['wp'])) {
|
|
|
147 |
$this->getWikipedia();
|
|
|
148 |
}
|
|
|
149 |
return $this->donnees['wp'];
|
|
|
150 |
}
|
291 |
jpm |
151 |
|
709 |
aurelien |
152 |
public function getWikipedia() {
|
291 |
jpm |
153 |
$wp = array();
|
|
|
154 |
$this->textes->setProjet('wikipedia');
|
|
|
155 |
$this->textes->setId($this->getIdWp());
|
756 |
aurelien |
156 |
$wp['titre'] = $donnees['titre'] = "Description de wikipedia";
|
435 |
aurelien |
157 |
$wp['lien'] = $this->textes->getPageUrl();
|
291 |
jpm |
158 |
$wp['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('wikipedia');
|
954 |
aurelien |
159 |
$this->donnees['wp'] = $wp;
|
291 |
jpm |
160 |
}
|
|
|
161 |
|
|
|
162 |
private function getIdWp() {
|
294 |
delphine |
163 |
$nomSci = $this->nomCourant->getNomRetenu()->get('nom_sci');
|
291 |
jpm |
164 |
$idWp = str_replace(' ', '_', $nomSci);
|
295 |
jpm |
165 |
$idWp = urlencode($idWp);
|
291 |
jpm |
166 |
return $idWp;
|
|
|
167 |
}
|
625 |
jpm |
168 |
|
|
|
169 |
private function getWikini() {
|
394 |
aurelien |
170 |
$wikini = array();
|
|
|
171 |
$wikini['titre'] = 'Wikini';
|
|
|
172 |
$referentiel = $this->conteneur->getParametre('referentiel');
|
|
|
173 |
$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
|
|
|
174 |
$page_wiki = $this->wikini->getPageWikiPourRefEtNumTax($referentiel, $num_tax);
|
|
|
175 |
$wikini['description'] = $this->wikini->getTexteFormate($page_wiki, 'description');
|
954 |
aurelien |
176 |
$this->donnees['wikini'] = $wikini;
|
394 |
aurelien |
177 |
}
|
709 |
aurelien |
178 |
|
|
|
179 |
public function getLienWikini() {
|
|
|
180 |
$referentiel = $this->conteneur->getParametre('referentiel');
|
|
|
181 |
$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
|
|
|
182 |
return $this->wikini->getUrlPageWiki($referentiel, $num_tax);
|
|
|
183 |
}
|
625 |
jpm |
184 |
|
322 |
delphine |
185 |
private function getCoste() {
|
|
|
186 |
$coste = array();
|
|
|
187 |
$this->textes->setProjet('coste');
|
448 |
delphine |
188 |
$this->textes->setId('bdtfx.nn:'.$this->nomCourant->getNnr());
|
322 |
delphine |
189 |
$texte = $this->textes->getTexte();
|
570 |
mathilde |
190 |
if ($texte) {
|
|
|
191 |
$coste['titre'] = $texte['titre'];
|
625 |
jpm |
192 |
$coste['description'] = $this->mettreEnFormeCoste($texte['texte']);
|
570 |
mathilde |
193 |
}
|
322 |
delphine |
194 |
$this->meta->setProjet('coste');
|
444 |
delphine |
195 |
$meta = $this->meta->getMetaDonnees();
|
|
|
196 |
$citation = $meta[0]['citation'];
|
|
|
197 |
$coste['meta']['citation'] = $citation;
|
448 |
delphine |
198 |
$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
|
954 |
aurelien |
199 |
$this->donnees['coste'] = $coste;
|
322 |
delphine |
200 |
}
|
625 |
jpm |
201 |
|
|
|
202 |
public function mettreEnFormeCoste($texte){
|
580 |
mathilde |
203 |
$this->CosteFormate = array();
|
|
|
204 |
$this->CosteTexte = $texte;
|
|
|
205 |
//decouper elements remarquables avant le texte
|
|
|
206 |
$this->separerNomScientifique_a_NomCommun();
|
|
|
207 |
$this->CosteTexte = preg_replace('/\//','',$this->CosteTexte);
|
|
|
208 |
//decouper elements remarquables après le texte
|
|
|
209 |
$this-> separerEcologie_a_Usages();
|
|
|
210 |
//le morceau qui reste est le gros de la description
|
|
|
211 |
$this->CosteTexte = str_replace(';','</br> -','- '.$this->CosteTexte);
|
|
|
212 |
$this->CosteTexte = str_replace('–','',$this->CosteTexte);
|
|
|
213 |
$this->CosteFormate['texte'] = $this->CosteTexte;
|
|
|
214 |
return $this->CosteFormate;
|
|
|
215 |
}
|
625 |
jpm |
216 |
|
|
|
217 |
|
580 |
mathilde |
218 |
public function separerNomScientifique_a_NomCommun(){
|
|
|
219 |
if ( preg_match('/\*\*(.+)\*\*([^–]*)–/', $this->CosteTexte, $retour)){
|
570 |
mathilde |
220 |
/* !! attention on enlève un tiret cadratin – pas un trait d'union - !! */
|
580 |
mathilde |
221 |
$a_enlever = array('/–/','/\./' );
|
|
|
222 |
$this->CosteFormate['nom_scientifique'] = preg_replace($a_enlever,'',$retour[1]);
|
|
|
223 |
if(preg_match('/\((.+)\)/',$retour[2],$synonymes)){
|
|
|
224 |
$this->CosteFormate['synonymes'] = $synonymes[1];
|
|
|
225 |
} else {
|
|
|
226 |
$this->CosteFormate['nom_scientifique'] .= $retour[2];
|
|
|
227 |
}
|
|
|
228 |
$this->CosteTexte = str_replace($retour[0],'',$this->CosteTexte);
|
570 |
mathilde |
229 |
}
|
|
|
230 |
/* !! attention il y a un espace avant les // du début !! */
|
580 |
mathilde |
231 |
if ( preg_match('/^ \/\/([^\/\/]+)\/\//', $this->CosteTexte, $retour)){
|
570 |
mathilde |
232 |
$a_enlever = array('/–/','/\./' );
|
580 |
mathilde |
233 |
$this->CosteFormate['nom_commun'] = preg_replace($a_enlever,'',$retour[1]);
|
|
|
234 |
$this->CosteTexte = str_replace($retour[0],'',$this->CosteTexte);
|
570 |
mathilde |
235 |
}
|
580 |
mathilde |
236 |
}
|
625 |
jpm |
237 |
|
|
|
238 |
|
580 |
mathilde |
239 |
public function separerEcologie_a_Usages(){
|
|
|
240 |
if ( preg_match('/\.[ ]*([A-ZÉÀÈ].+)$/',$this->CosteTexte, $retour)){
|
|
|
241 |
$this->CosteFormate['ecologie'] = $retour[1];
|
|
|
242 |
$this->CosteTexte = str_replace($retour[0],'.',$this->CosteTexte);
|
954 |
aurelien |
243 |
if (isset($this->CosteFormate['ecologie']) && preg_match('/–(.+)/', $this->CosteFormate['ecologie'] , $retour)){
|
580 |
mathilde |
244 |
$this->CosteFormate['repartition'] = $retour[1];
|
|
|
245 |
$this->CosteFormate['ecologie'] = str_replace($retour[0],'',$this->CosteFormate['ecologie']);
|
570 |
mathilde |
246 |
}
|
954 |
aurelien |
247 |
if (isset($this->CosteFormate['repartition']) && preg_match('/=(.+)$/', $this->CosteFormate['repartition'], $retour)){
|
580 |
mathilde |
248 |
$this->CosteFormate['floraison'] = $retour[1];
|
|
|
249 |
$this->CosteFormate['repartition'] = str_replace($retour[0],'',$this->CosteFormate['repartition']);
|
570 |
mathilde |
250 |
}
|
954 |
aurelien |
251 |
if (isset($this->CosteFormate['floraison']) && preg_match('/–(.+)$|\n(.+)$/',$this->CosteFormate['floraison'], $retour)){
|
580 |
mathilde |
252 |
$this->CosteFormate['usages'] = isset($retour[1]) ? $retour[1] : $retour[2];
|
|
|
253 |
$this->CosteFormate['floraison'] = str_replace($retour[0],'.',$this->CosteFormate['floraison']);
|
570 |
mathilde |
254 |
}
|
954 |
aurelien |
255 |
if (isset($this->CosteFormate['floraison']) && preg_match('/([Ff]l\.) (.+)/',$this->CosteFormate['floraison'], $retour)){
|
580 |
mathilde |
256 |
$this->CosteFormate['floraison'] = $retour[2];
|
|
|
257 |
$this->CosteFormate['floraison'] = str_replace($retour[1],'',$this->CosteFormate['floraison']);
|
|
|
258 |
}
|
954 |
aurelien |
259 |
if (isset($this->CosteFormate['floraison']) && preg_match('/([Ff]r\.) (.+)/',$this->CosteFormate['floraison'], $retour)){
|
580 |
mathilde |
260 |
$this->CosteFormate['fructification'] = $retour[2];
|
|
|
261 |
$this->CosteFormate['floraison'] = str_replace($retour[0],'',$this->CosteFormate['floraison']);
|
|
|
262 |
$this->CosteFormate['floraison'] = str_replace(',','',$this->CosteFormate['floraison']);
|
|
|
263 |
$this->CosteFormate['fructification'] = str_replace($retour[1],'',$this->CosteFormate['fructification']);
|
|
|
264 |
$this->CosteFormate['fructification'] = str_replace('.','',$this->CosteFormate['fructification']);
|
|
|
265 |
}
|
625 |
jpm |
266 |
}
|
570 |
mathilde |
267 |
}
|
272 |
delphine |
268 |
}
|
|
|
269 |
?>
|