Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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