Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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