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