Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1130 | Rev 1165 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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