Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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