Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 560 Rev 570
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
	
25
	
26
	public function __construct(Conteneur $conteneur) {
26
	public function __construct(Conteneur $conteneur) {
27
		$this->conteneur = $conteneur;
27
		$this->conteneur = $conteneur;
28
		$this->nomCourant = $this->conteneur->getNomCourant();
28
		$this->nomCourant = $this->conteneur->getNomCourant();
29
		$this->textes = $this->conteneur->getApiTextes();
29
		$this->textes = $this->conteneur->getApiTextes();
30
		$this->wikini = $this->conteneur->getApiWikini();
30
		$this->wikini = $this->conteneur->getApiWikini();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
32
		$this->informations = $this->conteneur->getApiInformations();
32
		$this->informations = $this->conteneur->getApiInformations();
33
		$this->appUrls = $this->conteneur->getAppUrls();
33
		$this->appUrls = $this->conteneur->getAppUrls();
34
	}
34
	}
35
 
35
 
36
	public function obtenirDonnees() {
36
	public function obtenirDonnees() {
37
		$donnees = array();
37
		$donnees = array();
38
		$donnees['wikipedia'] = $this->getWikipedia();
38
		$donnees['wikipedia'] = $this->getWikipedia();
39
		$donnees['coste'] = $this->getCoste();
39
		$donnees['coste'] = $this->getCoste();
40
		$donnees['wikini'] = $this->getWikini();
40
		$donnees['wikini'] = $this->getWikini();
41
		$donnees['baseflor'] = $this->getBaseflor();
41
		$donnees['baseflor'] = $this->getBaseflor();
42
		return $donnees;
42
		return $donnees;
43
	}
43
	}
44
	
44
	
45
	private function getBaseflor() {
45
	private function getBaseflor() {
46
		$baseflor = array();
46
		$baseflor = array();
47
		$this->informations ->setProjet('baseflor');
47
		$this->informations ->setProjet('baseflor');
48
		$this->informations ->setBdnt($this->conteneur->getParametre('referentiel'));
48
		$this->informations ->setBdnt($this->conteneur->getParametre('referentiel'));
49
		$this->informations ->setNum_nom($this->conteneur->getParametre('num_nom'));
49
		$this->informations ->setNum_nom($this->conteneur->getParametre('num_nom'));
50
		$informations = $this->informations->getInformations();
50
		$informations = $this->informations->getInformations();
51
		if ($informations){
51
		if ($informations){
52
			$baseflor['chorologie'] = $informations['chorologie'];
52
			$baseflor['chorologie'] = $informations['chorologie'];
53
			$baseflor['inflorescence'] = $informations['inflorescence'];
53
			$baseflor['inflorescence'] = $informations['inflorescence'];
54
			$baseflor['sexualite'] = $informations['sexualite'];
54
			$baseflor['sexualite'] = $informations['sexualite'];
55
			$baseflor['ordre_maturation'] = $informations['ordre_maturation'];
55
			$baseflor['ordre_maturation'] = $informations['ordre_maturation'];
56
			$baseflor['pollinisation'] = $informations['pollinisation'];
56
			$baseflor['pollinisation'] = $informations['pollinisation'];
57
			$baseflor['dissemination'] = $informations['dissemination'];
57
			$baseflor['dissemination'] = $informations['dissemination'];
58
			$baseflor['fruit'] = $informations['fruit'];
58
			$baseflor['fruit'] = $informations['fruit'];
59
			$baseflor['couleur_fleur'] = $informations['couleur_fleur'];
59
			$baseflor['couleur_fleur'] = $informations['couleur_fleur'];
60
			$baseflor['macule'] = $informations['macule'];
60
			$baseflor['macule'] = $informations['macule'];
61
			$baseflor['floraison'] = $this->changerFloraisonEnChaine($informations['floraison']);
61
			$baseflor['floraison'] = $this->changerFloraisonEnChaine($informations['floraison']);
62
			//récupérer dans ontologies
62
			//récupérer dans ontologies
63
			$baseflor['type_bio'] = $informations['type_bio.libelle'];
63
			$baseflor['type_bio'] = $informations['type_bio.libelle'];
64
			$baseflor['form_vegetale'] = $informations['form_vegetale'];
64
			$baseflor['form_vegetale'] = $informations['form_vegetale'];
65
			$baseflor['description']=$baseflor;
65
			$baseflor['description']=$baseflor;
66
			$this->meta->setProjet('baseflor');
66
			$this->meta->setProjet('baseflor');
67
			$meta = $this->meta->getMetaDonnees();
67
			$meta = $this->meta->getMetaDonnees();
68
			$citation = $meta[0]['citation'];
68
			$citation = $meta[0]['citation'];
69
			$baseflor['meta']['citation'] = $citation;
69
			$baseflor['meta']['citation'] = $citation;
70
			$baseflor['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('baseflor');
70
			$baseflor['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('baseflor');
71
			
71
			
72
		}
72
		}
73
		return $baseflor;
73
		return $baseflor;
74
	}
74
	}
75
	
75
	
76
	public function changerFloraisonEnChaine($floraison){
76
	public function changerFloraisonEnChaine($floraison){
77
		$chaine = "";
77
		$chaine = "";
78
		if ($floraison != ""){
78
		if ($floraison != ""){
79
			$mois_fleurs=preg_match('/-/',$floraison) ? preg_split('/-/',$floraison) : $floraison;
79
			$mois_fleurs=preg_match('/-/',$floraison) ? preg_split('/-/',$floraison) : $floraison;
80
			if (is_array($mois_fleurs)){
80
			if (is_array($mois_fleurs)){
81
				$chaine = "de ".$this->mois[(int)$mois_fleurs[0]]." à ".$this->mois[(int)$mois_fleurs[1]];
81
				$chaine = "de ".$this->mois[(int)$mois_fleurs[0]]." à ".$this->mois[(int)$mois_fleurs[1]];
82
					
82
					
83
			}else { $chaine = "en ".$this->mois[(int)$mois_fleurs];
83
			}else { $chaine = "en ".$this->mois[(int)$mois_fleurs];
84
			}
84
			}
85
		}
85
		}
86
		return $chaine;
86
		return $chaine;
87
	}
87
	}
88
 
88
 
89
 
89
 
90
	public function getBloc() {
90
	public function getBloc() {
91
		
-
 
92
		$donnees['titre'] = "Description de Coste";
91
		$donnees['titre'] = "Description de Coste";
93
		$description = $this->getCoste();
92
		$description = $this->getCoste();
94
		if ($description['description'] == '') {
93
		if ($description['description'] == '') {
95
			$donnees['titre'] = "Description Baseflor";
94
			$donnees['titre'] = "Description Baseflor";
96
			$description = $this->getBaseflor();
95
			$description = $this->getBaseflor();
97
		}
96
		}
98
		if (empty($description['description'])) {
97
		if (empty($description['description'])) {
99
			$donnees['titre'] = "Description collaborative";
98
			$donnees['titre'] = "Description collaborative";
100
			$description = $this->getWikini();
99
			$description = $this->getWikini();
101
		}
100
		}
102
		$donnees['description'] = $description['description'];
101
		$donnees['description'] = $description['description'];
103
		return $donnees;
102
		return $donnees;
104
	}
103
	}
105
 
104
 
106
	private function getWikipedia() {
105
	private function getWikipedia() {
107
		$wp = array();
106
		$wp = array();
108
		$this->textes->setProjet('wikipedia');
107
		$this->textes->setProjet('wikipedia');
109
		$this->textes->setId($this->getIdWp());
108
		$this->textes->setId($this->getIdWp());
110
		$wp['titre'] = $texte['titre'];
109
		$wp['titre'] = $texte['titre'];
111
		$wp['lien'] = $this->textes->getPageUrl();
110
		$wp['lien'] = $this->textes->getPageUrl();
112
		$wp['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('wikipedia');
111
		$wp['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('wikipedia');
113
		
112
		
114
		return $wp;
113
		return $wp;
115
	}
114
	}
116
 
115
 
117
	private function getIdWp() {
116
	private function getIdWp() {
118
		$nomSci = $this->nomCourant->getNomRetenu()->get('nom_sci');
117
		$nomSci = $this->nomCourant->getNomRetenu()->get('nom_sci');
119
		$idWp = str_replace(' ', '_', $nomSci);
118
		$idWp = str_replace(' ', '_', $nomSci);
120
		$idWp = urlencode($idWp);
119
		$idWp = urlencode($idWp);
121
		return $idWp;
120
		return $idWp;
122
	}
121
	}
123
	
122
	
124
	private function getWikini() {	
123
	private function getWikini() {	
125
		$wikini = array();
124
		$wikini = array();
126
		$wikini['titre'] = 'Wikini';
125
		$wikini['titre'] = 'Wikini';
127
		$referentiel = $this->conteneur->getParametre('referentiel');
126
		$referentiel = $this->conteneur->getParametre('referentiel');
128
		$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
127
		$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
129
		$page_wiki = $this->wikini->getPageWikiPourRefEtNumTax($referentiel, $num_tax);
128
		$page_wiki = $this->wikini->getPageWikiPourRefEtNumTax($referentiel, $num_tax);
130
		$wikini['description'] = $this->wikini->getTexteFormate($page_wiki, 'description');
129
		$wikini['description'] = $this->wikini->getTexteFormate($page_wiki, 'description');
131
		return $wikini;
130
		return $wikini;
132
	}
131
	}
133
	
132
	
134
	private function getCoste() {
133
	private function getCoste() {
135
		$coste = array();
134
		$coste = array();
136
		$this->textes->setProjet('coste');
135
		$this->textes->setProjet('coste');
137
		$this->textes->setId('bdtfx.nn:'.$this->nomCourant->getNnr());
136
		$this->textes->setId('bdtfx.nn:'.$this->nomCourant->getNnr());
138
		$texte = $this->textes->getTexte();
137
		$texte = $this->textes->getTexte();
-
 
138
		if ($texte) {
139
		$coste['titre'] = $texte['titre'];
139
			$coste['titre'] = $texte['titre'];
-
 
140
			$texte = $this->MettreEnFormeCoste($texte['texte']);
140
		$coste['description'] = $texte['texte'];
141
			$coste['description'] = $texte ;
-
 
142
		}
141
		$this->meta->setProjet('coste');
143
		$this->meta->setProjet('coste');
142
		$meta = $this->meta->getMetaDonnees();
144
		$meta = $this->meta->getMetaDonnees();
143
		$citation = $meta[0]['citation'];
145
		$citation = $meta[0]['citation'];
144
		$coste['meta']['citation'] = $citation;
146
		$coste['meta']['citation'] = $citation;
145
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
147
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
146
		return $coste;
148
		return $coste;
147
	}
149
	}
-
 
150
	
-
 
151
	public function MettreEnFormeCoste($texte){
-
 
152
		$resultat = array();
-
 
153
		if ( preg_match('/\*\*(.+)\*\*([^–]*)–/', $texte, $retour)){
-
 
154
		
-
 
155
			/* !! attention on enlève un tiret cadratin – pas un trait d'union - !! */
-
 
156
			$a_enlever  = array('/–/','/[0-9]+/','/\./' );
-
 
157
			$resultat['nom_scientifique'] = preg_replace($a_enlever,'',$retour[1]);
-
 
158
			$resultat['nom_scientifique'] .= $retour[2];
-
 
159
			$texte = str_replace($retour[0],'',$texte);
-
 
160
		}
-
 
161
		/* !! attention il y a un espace avant les // du début !! */
-
 
162
		if ( preg_match('/^ \/\/([^\/\/]+)\/\//', $texte, $retour)){
-
 
163
			$a_enlever = array('/–/','/\./' );
-
 
164
			$resultat['nom_commun'] = preg_replace($a_enlever,'',$retour[1]);
-
 
165
			$texte = str_replace($retour[0],'',$texte);
-
 
166
		}
-
 
167
		$texte = preg_replace('/\//','',$texte);
-
 
168
		if ( preg_match('/\.[ ]*([A-ZÉÀÈ].+)$/', $texte, $retour)){
-
 
169
			$resultat['ecologie'] = $retour[1];
-
 
170
			$texte = str_replace($retour[0],'.',$texte);
-
 
171
			if ( preg_match('/–(.+)/', $resultat['ecologie'] , $retour)){
-
 
172
				$resultat['repartition'] = $retour[1];
-
 
173
				$resultat['ecologie'] = str_replace($retour[0],'',$resultat['ecologie']);
-
 
174
			}
-
 
175
			if ( preg_match('/=(.+)$/', $resultat['repartition'], $retour)){
-
 
176
				$resultat['floraison'] = $retour[1];
-
 
177
				$resultat['repartition'] = str_replace($retour[0],'',$resultat['repartition']);
-
 
178
			}
-
 
179
			if ( preg_match('/–(.+)$/',$resultat['floraison'], $retour)){
-
 
180
				$resultat['consommation'] = $retour[1];
-
 
181
				$resultat['floraison'] = str_replace($retour[0],'.',$resultat['floraison']);
-
 
182
			}
-
 
183
		}
-
 
184
		$texte = str_replace(';','</br> -','- '.$texte);
-
 
185
		$texte = str_replace('–','',$texte);
-
 
186
		$resultat['texte'] = $texte;
-
 
187
		return $resultat;
-
 
188
	}
-
 
189
	
-
 
190
	
148
}
191
}
149
?>
192
?>