Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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