Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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