Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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