Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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