Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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