Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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