Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1092 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
990 isa 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 Floraison extends aControleur {
16
 
17
	private $conteneur = null;
18
	private $nomCourant = null;
19
	private $textes = null;
20
	private $meta = null;
21
	private $wikini = null;
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
	private $CosteFormate;
26
	private $CosteTexte;
27
 
28
	private $referentiel = 'bdtfx';
29
	private $donnees = array();
30
 
31
	public function __construct(Conteneur $conteneur) {
32
		$this->conteneur = $conteneur;
33
		$this->nomCourant = $this->conteneur->getNomCourant();
34
		$this->referentiel = $this->conteneur->getParametre('referentiel');
35
		$this->textes = $this->conteneur->getApiTextes();
36
		$this->wikini = $this->conteneur->getApiWikini();
37
		$this->meta = $this->conteneur->getApiMetaDonnees();
38
		$this->informations = $this->conteneur->getApiInformations();
39
		$this->appUrls = $this->conteneur->getAppUrls();
40
	}
41
 
42
	public function getDonnees() {
43
		$this->getCoste();
44
		if (isset($this->CosteFormate['floraison'])) {
45
			$this->donnees['floraison'] = $this->getIndiceMois($this->CosteFormate['floraison']);
46
		} else {
47
			$this->getFloraisonBaseflor();
48
		}
49
		if (isset($this->CosteFormate['fructification'])) {
50
			$this->donnees['fructification'] = $this->getIndiceMois($this->CosteFormate['fructification']);
51
		} else {
52
			$this->donnees['fructification'] = -1;
53
		}
54
 
55
		return $this->donnees;
56
	}
57
 
58
	private function getCoste() {
59
		$coste = array();
60
		$this->textes->setProjet('coste');
61
		$this->textes->setId('bdtfx.nn:'.$this->nomCourant->getNnr());
62
		$texte = $this->textes->getTexte();
1092 raphael 63
		$texte = array_pop($texte['resultats']);
990 isa 64
		if ($texte) {
65
			$coste['titre'] = $texte['titre'];
1092 raphael 66
			// TODO: réintroduire les modif' effectuées sur modules/fiche/formateurs/Description.php
67
			// -les joies du code copié/collé-
990 isa 68
			$coste['description'] = $this->mettreEnFormeCoste($texte['texte']);
69
		}
70
 
71
		$this->donnees['coste'] = $coste;
72
	}
73
 
74
	private function getIndiceMois($elt) {
75
		$mois = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août',
76
					  'septembre', 'octobre', 'novembre', 'décembre');
77
		$indice_mois = -1;
78
		$elt = $this->nettoyerTexte($elt);
79
		$arr = preg_split('/-/', $elt, -1, PREG_SPLIT_NO_EMPTY);
80
		if (isset($arr[1])) {
81
			$mois1 = $this->getIndiceMois($arr[0]);
82
			$mois2 = $this->getIndiceMois($arr[1]);
83
			$indice_mois = $mois1.'-'.$mois2;
84
		} else {
85
			for ($i = 0; $i < count($mois); $i++) {
86
		        if ($elt == $mois[$i]) {
87
		        	$indice_mois = $i;
88
		        }
89
		    }
90
		}
91
 
92
		return $indice_mois;
93
	}
94
 
95
	private function nettoyerTexte($texte) {
96
		$texte = trim($texte);
97
 
98
		$a_effacer = array('.', ' ', 'de');
99
		$texte = str_replace($a_effacer, '', $texte);
100
 
101
		$texte = strtolower($texte);
102
		return $texte;
103
	}
104
 
105
	private function getFloraisonBaseflor() {
106
		$baseflor = array();
107
		$this->informations->setProjet('baseflor');
108
		$this->informations->setBdnt($this->conteneur->getParametre('referentiel'));
109
		$this->informations->setNum_nom($this->conteneur->getParametre('num_nom'));
110
		$informations = $this->informations->getInformationsDescription();
111
 
112
		if ($informations){
113
			$baseflor['chorologie'] = isset($informations['chorologie']) ? $informations['chorologie'] : '';
114
			$baseflor['inflorescence'] = isset($informations['inflorescence']) ? $informations['inflorescence'] : '';
115
			$baseflor['sexualite'] = isset($informations['sexualite']) ? $informations['sexualite'] : '';
116
			$baseflor['ordre_maturation'] = isset($informations['ordre_maturation']) ? $informations['ordre_maturation'] : '';
117
			$baseflor['pollinisation'] = isset($informations['pollinisation']) ? $informations['pollinisation'] : '';
118
			$baseflor['dissemination'] = isset($informations['dissemination']) ? $informations['dissemination'] : '';
119
			$baseflor['fruit'] = isset($informations['fruit']) ? $informations['fruit'] : '';
120
			$baseflor['couleur_fleur'] = isset($informations['couleur_fleur']) ? $informations['couleur_fleur'] : '';
121
			$baseflor['macule'] = isset($informations['macule']) ? $informations['macule'] : '';
122
			$baseflor['type_bio'] = isset($informations['type_bio']) ? $informations['type_bio'] : '';
123
			$baseflor['form_vegetale'] = isset($informations['form_vegetale']) ? $informations['form_vegetale'] : '';
124
			$baseflor['floraison'] = isset($informations['floraison']) ? $informations['floraison'] : '';
125
		}
126
		$this->donnees['baseflor'] = $baseflor;
127
		$this->donnees['floraison'] = $baseflor['floraison'];
128
	}
129
 
130
 
131
	public function mettreEnFormeCoste($texte){
132
		$this->CosteFormate = array();
133
		$this->CosteTexte = $texte;
134
		//decouper elements remarquables avant le texte
135
		$this->separerNomScientifique_a_NomCommun();
136
		$this->CosteTexte = preg_replace('/\//','',$this->CosteTexte);
137
		//decouper elements remarquables  après le texte
138
		$this->separerEcologie_a_Usages();
139
		//le morceau qui reste est le gros de la description
140
		$this->CosteTexte = str_replace(';','<br /> -','- '.$this->CosteTexte);
141
		$this->CosteTexte = str_replace('–','',$this->CosteTexte);
142
		$this->CosteFormate['texte'] = htmlspecialchars_decode(htmlentities($this->CosteTexte, ENT_NOQUOTES, 'UTF-8'), ENT_NOQUOTES);
143
		return $this->CosteFormate;
144
	}
145
 
146
	public function separerNomScientifique_a_NomCommun(){
147
		if ( preg_match('/\*\*(.+)\*\*([^–]*)–/', $this->CosteTexte, $retour)){
148
			/* !! attention on enlève un tiret cadratin – pas un trait d'union - !! */
149
			$a_enlever  = array('/–/','/\./' );
150
			$this->CosteFormate['nom_scientifique'] = preg_replace($a_enlever,'',$retour[1]);
151
			if(preg_match('/\((.+)\)/',$retour[2],$synonymes)){
152
				$this->CosteFormate['synonymes'] = $synonymes[1];
153
			} else {
154
				$this->CosteFormate['nom_scientifique'] .=  $retour[2];
155
			}
156
			$this->CosteTexte = str_replace($retour[0],'',$this->CosteTexte);
157
		}
158
		/* !! attention il y a un espace avant les // du début !! */
159
		if ( preg_match('/^ \/\/([^\/\/]+)\/\//', $this->CosteTexte, $retour)){
160
			$a_enlever = array('/–/','/\./' );
161
			$this->CosteFormate['nom_commun'] = preg_replace($a_enlever,'',$retour[1]);
162
			$this->CosteTexte = str_replace($retour[0],'',$this->CosteTexte);
163
		}
164
	}
165
 
166
	public function separerEcologie_a_Usages(){
167
		if ( preg_match('/\.[ ]*([A-ZÉÀÈ].+)$/',$this->CosteTexte, $retour)){
168
			$this->CosteFormate['ecologie'] = $retour[1];
169
			$this->CosteTexte = str_replace($retour[0],'.',$this->CosteTexte);
170
			if (isset($this->CosteFormate['ecologie']) && preg_match('/–(.+)/', $this->CosteFormate['ecologie'] , $retour)){
171
				$this->CosteFormate['repartition'] = $retour[1];
172
				$this->CosteFormate['ecologie'] = str_replace($retour[0],'',$this->CosteFormate['ecologie']);
173
			}
174
			if (isset($this->CosteFormate['repartition']) &&  preg_match('/=(.+)$/', $this->CosteFormate['repartition'], $retour)){
175
				$this->CosteFormate['floraison'] = $retour[1];
176
				$this->CosteFormate['repartition'] = str_replace($retour[0],'',$this->CosteFormate['repartition']);
177
			}
178
			if (isset($this->CosteFormate['floraison']) &&  preg_match('/–(.+)$|\n(.+)$/',$this->CosteFormate['floraison'], $retour)){
179
				$this->CosteFormate['usages'] = isset($retour[1]) ? $retour[1] : $retour[2];
180
				$this->CosteFormate['floraison'] = str_replace($retour[0],'.',$this->CosteFormate['floraison']);
181
			}
182
			if (isset($this->CosteFormate['floraison']) &&  preg_match('/([Ff]l\.) (.+)/',$this->CosteFormate['floraison'], $retour)){
183
				$this->CosteFormate['floraison'] = $retour[2];
184
				$this->CosteFormate['floraison'] = str_replace($retour[1],'',$this->CosteFormate['floraison']);
185
			}
186
			if (isset($this->CosteFormate['floraison']) &&  preg_match('/([Ff]r\.) (.+)/',$this->CosteFormate['floraison'], $retour)){
187
				$this->CosteFormate['fructification'] = $retour[2];
188
				$this->CosteFormate['floraison'] = str_replace($retour[0],'',$this->CosteFormate['floraison']);
189
				$this->CosteFormate['floraison'] = str_replace(',','',$this->CosteFormate['floraison']);
190
				$this->CosteFormate['fructification'] = str_replace($retour[1],'',$this->CosteFormate['fructification']);
191
				$this->CosteFormate['fructification'] = str_replace('.','',$this->CosteFormate['fructification']);
192
			}
193
		}
194
	}
195
}
196
?>