Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 1439 Rev 1552
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 Ethnobotanique extends aControleur {
15
class Ethnobotanique extends aControleur {
16
 
16
 
17
	private $conteneur = null;
17
	private $conteneur = null;
18
	private $nomCourant = null;
18
	private $nomCourant = null;
19
	private $nomsVernaculaires = null;
19
	private $nomsVernaculaires = null;
20
	private $wikini;
20
	private $wikini;
21
	private $referentiel = 'bdtfx';
21
	private $referentiel = 'bdtfx';
22
	private $donnees = array();
22
	private $donnees = array();
23
 
23
 
24
	public function __construct(Conteneur $conteneur) {
24
	public function __construct(Conteneur $conteneur) {
25
		$this->conteneur = $conteneur;
25
		$this->conteneur = $conteneur;
26
		$this->nomCourant = $this->conteneur->getNomCourant();
26
		$this->nomCourant = $this->conteneur->getNomCourant();
27
		$this->nomsVernaculaires = $this->conteneur->getApiNomsVernaculaires();
27
		$this->nomsVernaculaires = $this->conteneur->getApiNomsVernaculaires();
28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
29
		$this->wikini = $this->conteneur->getApiWikini();
29
		$this->wikini = $this->conteneur->getApiWikini();
-
 
30
		$this->textes = $this->conteneur->getApiTextes ();
30
		$this->meta = $this->conteneur->getApiMetaDonnees();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
31
		$this->appUrls = $this->conteneur->getAppUrls();
32
		$this->appUrls = $this->conteneur->getAppUrls();
32
	}
33
	}
33
 
34
 
34
	public function obtenirDonnees() {
35
	public function obtenirDonnees() {
35
		$this->getNomsVernaculaires('.referentielVerna');
36
		$this->getNomsVernaculaires('.referentielVerna');
36
		$this->getNomsVernaculaires('.referentielVernaGrec');
37
		$this->getNomsVernaculaires('.referentielVernaGrec');
37
		$this->getChorologie();
38
		$this->getChorologie();
-
 
39
		if ($this->referentiel == 'bdtfx') {
-
 
40
		  $this->getPlantUse();
-
 
41
		}
38
		$this->donnees['wikini'] = $this->getWikini();
42
		$this->donnees['wikini'] = $this->getWikini();
39
		return $this->donnees;
43
		return $this->donnees;
40
	}
44
	}
41
 
45
 
42
	private function getNomsVernaculaires($projet) {
46
	private function getNomsVernaculaires($projet) {
43
		$projet = Config::get($this->referentiel.$projet);
47
		$projet = Config::get($this->referentiel.$projet);
44
		if ($projet != "") {
48
		if ($projet != "") {
45
			$nt = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
49
			$nt = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
46
			$nomsVerna = $this->nomsVernaculaires->getRechercheComplete($projet, $nt);
50
			$nomsVerna = $this->nomsVernaculaires->getRechercheComplete($projet, $nt);
47
			$this->donnees[$projet]['noms'] = $nomsVerna['resultat'];
51
			$this->donnees[$projet]['noms'] = $nomsVerna['resultat'];
48
			$this->meta->setProjet($projet);
52
			$this->meta->setProjet($projet);
49
			$meta = $this->meta->getMetaDonnees();
53
			$meta = $this->meta->getMetaDonnees();
50
			$this->donnees[$projet]['meta'] = $meta[0];
54
			$this->donnees[$projet]['meta'] = $meta[0];
51
			$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
55
			$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
52
		}
56
		}
53
	}
57
	}
-
 
58
	
-
 
59
	private function getPlantUse() {
-
 
60
	    $plantuse = array ();
-
 
61
	    $this->textes->setProjet('plantuse');
-
 
62
	    $this->textes->setId ($this->nomCourant->getNomRetenu()->get('nom_sci'));
-
 
63
	    $texte = $this->textes->getUsage();
-
 
64
	    
-
 
65
	    if ($texte['resultats']) {
-
 
66
	        $plantuse ['titre'] = "Résumé des usages de Pl@ntUse";
-
 
67
	        $plantuse ['description'] = $texte['resultats'];
-
 
68
	    }
-
 
69
	    $this->meta->setProjet('plantuse');
-
 
70
	    $meta = $this->meta->getMetaDonnees ();
-
 
71
	    $plantuse ['meta'] = $meta [0];
-
 
72
	    $plantuse ['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('plantuse');
-
 
73
	    $this->donnees['plantuse'] = $plantuse;
-
 
74
	}
54
	
75
	
55
	public function getBloc() {
76
	public function getBloc() {
56
		$nt = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
77
		$nt = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
57
		$projet = Config::get($this->referentiel.'.referentielVerna');
78
		$projet = Config::get($this->referentiel.'.referentielVerna');
58
		if ($projet != "") {
79
		if ($projet != "") {
59
			$nomsVerna = $this->nomsVernaculaires->getRechercheLimitee($projet, $nt);
80
			$nomsVerna = $this->nomsVernaculaires->getRechercheLimitee($projet, $nt);
60
			$this->donnees['nomsVerna'] = (isset($nomsVerna['resultat']) && is_array($nomsVerna['resultat'])) ? array_slice($nomsVerna['resultat'], 0, 3) : array();
81
			$this->donnees['nomsVerna'] = (isset($nomsVerna['resultat']) && is_array($nomsVerna['resultat'])) ? array_slice($nomsVerna['resultat'], 0, 3) : array();
61
			$this->donnees['autresNomsVerna'] = count($nomsVerna['resultat']) - 3;
82
			$this->donnees['autresNomsVerna'] = count($nomsVerna['resultat']) - 3;
62
		}
83
		}
63
		$this->donnees['wikini'] = $this->getWikini();
84
		$this->donnees['wikini'] = $this->getWikini();
64
		return $this->donnees;
85
		return $this->donnees;
65
	}
86
	}
66
		
87
		
67
	private function getChorologie() {
88
	private function getChorologie() {
68
		$infos_choro = $this->nomCourant->getNomRetenu()->getInfos();
89
		$infos_choro = $this->nomCourant->getNomRetenu()->getInfos();
69
		$this->donnees['chorologie'] = $this->traiterTableauChorologie($infos_choro);
90
		$this->donnees['chorologie'] = $this->traiterTableauChorologie($infos_choro);
70
		$this->meta->setProjet($this->referentiel);
91
		$this->meta->setProjet($this->referentiel);
71
		$meta = $this->meta->getMetaDonnees();
92
		$meta = $this->meta->getMetaDonnees();
72
		$this->donnees['chorologie']['meta'] = $meta[0];
93
		$this->donnees['chorologie']['meta'] = $meta[0];
73
		$this->donnees['chorologie']['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($this->referentiel);
94
		$this->donnees['chorologie']['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($this->referentiel);
74
	}
95
	}
75
	
96
	
76
	private function traiterTableauChorologie($infos_choro) {
97
	private function traiterTableauChorologie($infos_choro) {
77
		$donnees_choro = array();
98
		$donnees_choro = array();
78
		$colonnes = array();
99
		$colonnes = array();
79
		foreach ($infos_choro as $param => $valeur) {
100
		foreach ($infos_choro as $param => $valeur) {
80
			if(strncmp($param, 'presence', 8) == 0) {
101
			if(strncmp($param, 'presence', 8) == 0) {
81
				$lieu = self::obtenirLieuPourCodePresence($this->referentiel, $param);
102
				$lieu = self::obtenirLieuPourCodePresence($this->referentiel, $param);
82
				if($lieu) {
103
				if($lieu) {
83
					$donnees_choro['Présence'][$lieu] = $valeur;
104
					$donnees_choro['Présence'][$lieu] = $valeur;
84
					$colonnes[] = $lieu;
105
					$colonnes[] = $lieu;
85
				}
106
				}
86
			} else {
107
			} else {
87
				$donnees_choro = self::traiterChampsStatuts($this->referentiel, $donnees_choro, $param, $valeur);
108
				$donnees_choro = self::traiterChampsStatuts($this->referentiel, $donnees_choro, $param, $valeur);
88
			}
109
			}
89
		}
110
		}
90
 
111
 
91
		ksort($donnees_choro);
112
		ksort($donnees_choro);
92
		$donnees = array('colonnes' => array_unique($colonnes), 'donnees' => $donnees_choro);
113
		$donnees = array('colonnes' => array_unique($colonnes), 'donnees' => $donnees_choro);
93
		
114
		
94
		return $donnees;
115
		return $donnees;
95
	}
116
	}
96
	
117
	
97
	static function traiterChampsStatuts($ref, $tableau_donnees, $code, $valeur) {
118
	static function traiterChampsStatuts($ref, $tableau_donnees, $code, $valeur) {
98
		if ($code == 'statut_origine.libelle') {
119
		if ($code == 'statut_origine.libelle') {
99
			$tableau_donnees['Statut d\'origine'][self::obtenirIntituleLieuPourReferentiel($ref)] = $valeur;
120
			$tableau_donnees['Statut d\'origine'][self::obtenirIntituleLieuPourReferentiel($ref)] = $valeur;
100
		} elseif ($code == 'statut_introduction.libelle') {
121
		} elseif ($code == 'statut_introduction.libelle') {
101
			$tableau_donnees['Statut d\'introduction'][self::obtenirIntituleLieuPourReferentiel($ref)] = $valeur;
122
			$tableau_donnees['Statut d\'introduction'][self::obtenirIntituleLieuPourReferentiel($ref)] = $valeur;
102
		} elseif ($code == 'statut_culture.libelle') {
123
		} elseif ($code == 'statut_culture.libelle') {
103
			$tableau_donnees['Statut de culture'][self::obtenirIntituleLieuPourReferentiel($ref)] = $valeur;
124
			$tableau_donnees['Statut de culture'][self::obtenirIntituleLieuPourReferentiel($ref)] = $valeur;
104
		}
125
		}
105
		
126
		
106
		return $tableau_donnees;
127
		return $tableau_donnees;
107
	}
128
	}
108
 
129
 
109
	/* eg:
130
	/* eg:
110
	 * - presence.libelle
131
	 * - presence.libelle
111
	 * - presence_Guadeloupe.code */
132
	 * - presence_Guadeloupe.code */
112
	static function obtenirLieuPourCodePresence($ref, $str) {
133
	static function obtenirLieuPourCodePresence($ref, $str) {
113
		// ignore les paramètres JSON de présence qui ne contiennent pas le libellé
134
		// ignore les paramètres JSON de présence qui ne contiennent pas le libellé
114
		// (= présence en toutes lettres)
135
		// (= présence en toutes lettres)
115
		if(substr($str, -7) != 'libelle') return NULL;
136
		if(substr($str, -7) != 'libelle') return NULL;
116
		@list($prefixe, $lieu) = explode('_', $str, 2);
137
		@list($prefixe, $lieu) = explode('_', $str, 2);
117
 
138
 
118
		if($str == 'presence.libelle') {
139
		if($str == 'presence.libelle') {
119
			return self::obtenirIntituleLieuPourReferentiel($ref);
140
			return self::obtenirIntituleLieuPourReferentiel($ref);
120
		}
141
		}
121
 
142
 
122
		list($lieu, $param) = explode('.', $lieu, 2);
143
		list($lieu, $param) = explode('.', $lieu, 2);
123
		if (strtolower($lieu) == 'ga') {
144
		if (strtolower($lieu) == 'ga') {
124
			return 'France (Hors Corse)';
145
			return 'France (Hors Corse)';
125
		} elseif (strtolower($lieu) == 'co') {
146
		} elseif (strtolower($lieu) == 'co') {
126
			return 'France (Corse)';
147
			return 'France (Corse)';
127
		} elseif($lieu) {
148
		} elseif($lieu) {
128
			return $lieu;
149
			return $lieu;
129
		}
150
		}
130
		return NULL;
151
		return NULL;
131
	}
152
	}
132
	
153
	
133
	private static function obtenirIntituleLieuPourReferentiel($ref) {
154
	private static function obtenirIntituleLieuPourReferentiel($ref) {
134
		$lieu = '';
155
		$lieu = '';
135
		switch($ref) {
156
		switch($ref) {
136
			case 'bdtfx':
157
			case 'bdtfx':
137
				$lieu = 'France';
158
				$lieu = 'France';
138
				break;
159
				break;
139
			case 'bdtxa':
160
			case 'bdtxa':
140
				$lieu = 'Antilles';
161
				$lieu = 'Antilles';
141
				break;
162
				break;
142
			case 'isfan':
163
			case 'isfan':
143
				$lieu = 'Afrique du Nord';
164
				$lieu = 'Afrique du Nord';
144
				break;
165
				break;
145
		}
166
		}
146
		return $lieu;
167
		return $lieu;
147
	}
168
	}
148
	
169
	
149
	private function getWikini() {
170
	private function getWikini() {
150
		$wikini = array();
171
		$wikini = array();
151
		$wikini['titre'] = 'Wikini';
172
		$wikini['titre'] = 'Wikini';
152
		$referentiel = $this->conteneur->getParametre('referentiel');
173
		$referentiel = $this->conteneur->getParametre('referentiel');
153
		$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
174
		$num_tax = $this->nomCourant->getNomSelectionne()->get('num_taxonomique');
154
		$page_wiki = $this->wikini->getPageWikiPourRefEtNumTax($referentiel, $num_tax);
175
		$page_wiki = $this->wikini->getPageWikiPourRefEtNumTax($referentiel, $num_tax);
155
		$wikini['noms_communs'] = $this->wikini->getTexteFormate($page_wiki, 'noms communs');
176
		$wikini['noms_communs'] = $this->wikini->getTexteFormate($page_wiki, 'noms communs');
156
		$wikini['culture_et_arts'] = $this->wikini->getTexteFormate($page_wiki, 'culture et arts');
177
		$wikini['culture_et_arts'] = $this->wikini->getTexteFormate($page_wiki, 'culture et arts');
157
		$wikini['usage'] = $this->wikini->getTexteFormate($page_wiki, 'usage');
178
		$wikini['usage'] = $this->wikini->getTexteFormate($page_wiki, 'usage');
158
		return $wikini;
179
		return $wikini;
159
	}
180
	}
160
}
181
}
161
?>
182
?>