Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 990 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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