Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1213 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
76 delphine 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe mère du module Liste.
5
 *
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
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
13
 * @version		$Id$
14
 */
15
class Resultat extends aControleur {
106 jpm 16
 
146 jpm 17
	private $parametres = null;
18
	private $resultats = null;
151 jpm 19
	private $donneesTpl = array();
725 mathilde 20
	private $i18n =  array();
996 aurelien 21
 
22
	private $parametresAvancesGeneriques = array('gen','fam','nn','nt','sp','ssp','type','sto','sti','stc');
106 jpm 23
 
84 jpm 24
	public function initialiser() {
146 jpm 25
		spl_autoload_register(array($this, 'chargerClassesResultat'));
26
		$this->parametres = new ParametresResultats();
84 jpm 27
		$this->capturerParametres();
725 mathilde 28
		$this->capturerParametresAvances();
1455 delphine 29
		if (Registre::get('parametres.referentiel') == "bdtfxr") Registre::set('parametres.referentiel', 'bdtfx') ;
30
		$this->parametres->referentielCourant = Registre::get('parametres.referentiel') ;
931 delphine 31
		$this->parametres->projetImg = Config::get($this->parametres->referentielCourant.'.baseImages');
146 jpm 32
		$this->resultats = Registre::get('resultats');
725 mathilde 33
		$this->i18n = I18n::get('Recherche-form-avancee');
84 jpm 34
	}
106 jpm 35
 
146 jpm 36
	private function chargerClassesResultat($classe) {
154 jpm 37
		$base = dirname(__FILE__).DS;
163 jpm 38
		$cheminFormateurs = $base.'formateurs'.DS;
39
		$cheminFormateursNs = $cheminFormateurs.'nom_scientifique'.DS;
40
		$cheminFormateursNv = $cheminFormateurs.'nom_vernaculaire'.DS;
41
		$dossiers = array($base, $cheminFormateurs, $cheminFormateursNs, $cheminFormateursNv);
146 jpm 42
		foreach ($dossiers as $chemin) {
43
			$fichierATester = $chemin.$classe.'.php';
44
			if (file_exists($fichierATester)) {
45
				include_once $fichierATester;
46
				return null;
47
			}
48
		}
49
	}
50
 
84 jpm 51
	private function capturerParametres() {
967 delphine 52
		$this->parametres->masqueRecherche = "";
84 jpm 53
		if (isset($_GET['resultat'])) {
162 jpm 54
			$this->parametres->typeResultat = $_GET['resultat'];
84 jpm 55
		}
135 jpm 56
		if (isset($_GET['nom'])) {
819 mathilde 57
			$this->parametres->masqueRecherche = trim($_GET['nom']);
135 jpm 58
		}
967 delphine 59
		//recherche avancee type
60
		if (isset($_GET['fam'])) {
61
			$this->parametres->masqueRecherche .= trim($_GET['fam']);
62
		}
63
		if (isset($_GET['gen'])) {
64
			$this->parametres->masqueRecherche .= trim($_GET['gen']);
65
		}
66
		if (isset($_GET['sp'])) {
67
			$this->parametres->masqueRecherche .= trim($_GET['sp']);
68
		}
69
		if (isset($_GET['ssp'])) {
70
			$this->parametres->masqueRecherche .= trim($_GET['ssp']);
71
		}
72
		if (isset($_GET['and'])) {
73
			$this->parametres->masqueRecherche .= trim($_GET['and']);
74
		}
75
		if (isset($_GET['anf'])) {
76
			$this->parametres->masqueRecherche .= trim($_GET['anf']);
77
		}
78
		if (isset($_GET['au'])) {
79
			$this->parametres->masqueRecherche .= trim($_GET['au']);
80
		}
81
		if (isset($_GET['bib'])) {
82
			$this->parametres->masqueRecherche .= trim($_GET['bib']);
83
		}
1210 mathias 84
 
85
		// Si spécifié, seuls les résultats du niveau spécifié sont affichés.
86
		// Passer "*" pour annuler le filtre par rang (le paramètre est mis à "null").
87
		// Par défaut, seules les espèces sont affichées (paramètre par défaut).
88
		if (isset($_GET['rang'])) {
89
			$this->parametres->rang = ($_GET['rang'] == '*' ? null : $_GET['rang']);
90
		}
91
 
162 jpm 92
		if (isset($_GET['type_nom'])) {
93
			$this->parametres->typeNom = $_GET['type_nom'];
94
		}
197 delphine 95
 
96
		if (isset($_GET['niveau'])) {
97
			Registre::set('parametres.niveau', $_GET['niveau']);
98
		}
84 jpm 99
	}
725 mathilde 100
 
101
	private function capturerParametresAvances() {
996 aurelien 102
		$this->capturerParametresAvancesGeneriques();
103
		$this->capturerParametresAvancesDependantsLangage();
104
		$this->capturerParametresAvancesPresenceSpecifiques();
1210 mathias 105
		$this->capturerParametresAvancesRang();
996 aurelien 106
	}
1210 mathias 107
 
108
	private function capturerParametresAvancesRang() {
109
		// rang à afficher
110
		$this->param['rang'] = $this->parametres->rang;
111
		if ($this->param['rang'] === null) {
112
			$this->param['rang'] = '*';
113
		}
114
	}
115
 
996 aurelien 116
	private function capturerParametresAvancesGeneriques() {
117
		foreach($this->parametresAvancesGeneriques as $param) {
118
			if (isset($_GET[$param]) && $_GET[$param] != '') {
119
				$this->param[$param] = urldecode($_GET[$param]);
120
			}
725 mathilde 121
		}
996 aurelien 122
	}
123
 
124
	private function capturerParametresAvancesDependantsLangage() {
125
		if (isset($_GET['au']) && $_GET['au'] != ''
126
		&& $_GET['au'] != urlencode($this->i18n['valeur-form-auteur'])) {
725 mathilde 127
			$this->param['au'] = urldecode($_GET['au']);
128
		}
129
		if (isset($_GET['bib']) && $_GET['bib'] != ''
996 aurelien 130
		&& $_GET['bib'] != urlencode($this->i18n['valeur-form-bib'])) {
725 mathilde 131
			$this->param['bib'] = urldecode($_GET['bib']);
132
		}
133
		if (isset($_GET['and']) && $_GET['and'] != ''
996 aurelien 134
		&& $_GET['and'] != urlencode($this->i18n['valeur-form-date'])) {
725 mathilde 135
			$this->param['and'] = urldecode($_GET['and']);
136
		}
137
		if (isset($_GET['anf']) && $_GET['anf'] != ''
996 aurelien 138
		&& $_GET['anf'] != urlencode($this->i18n['valeur-form-date'])) {
725 mathilde 139
			$this->param['anf'] = urldecode($_GET['anf']);
140
		}
996 aurelien 141
	}
142
 
143
	private function capturerParametresAvancesPresenceSpecifiques()  {
144
		$champs_presence = $this->obtenirChampsPresence();
145
		foreach($champs_presence as $champ) {
146
			$param = $champ['param'];
147
			if (isset($_GET[$param]) && $_GET[$param] != '') {
148
				$this->param[$param] = urldecode($_GET[$param]);
149
			}
725 mathilde 150
		}
996 aurelien 151
	}
152
 
153
	private function obtenirChampsPresence() {
154
		$tableau_champs_presence = array();
155
		$referentiel = Registre::get('parametres.referentiel');
156
		$champs_presence = Config::get($referentiel.'.champsPresence');
157
		$champs_presence_spl = explode('|', $champs_presence);
158
		foreach($champs_presence_spl as $champ) {
159
			$label_param_champ = explode(':', $champ);
1165 aurelien 160
			if(count($label_param_champ) >= 2) {
161
				$tableau_champs_presence[] = array('param' => $label_param_champ[1],
996 aurelien 162
													'label' => $label_param_champ[0]);
1165 aurelien 163
			}
725 mathilde 164
		}
996 aurelien 165
		return $tableau_champs_presence;
725 mathilde 166
	}
167
 
106 jpm 168
 
76 delphine 169
	public function executerActionParDefaut() {
170
		$this->executerResultat();
171
	}
106 jpm 172
 
76 delphine 173
	public function executerResultat() {
162 jpm 174
		$this->chargerOnglets();
151 jpm 175
		$this->chargerNbreDeTaxons();
176
		$this->chargerNomsFormates();
177
		$this->setSortie(self::RENDU_CORPS, $this->getVue('resultat', $this->donneesTpl));
76 delphine 178
	}
106 jpm 179
 
162 jpm 180
	private function chargerOnglets() {
181
		$donnees = array();
182
		$donnees['typeResultat'] = $this->parametres->typeResultat;
183
		$donnees['typeNom'] = $this->parametres->typeNom;
855 mathilde 184
		$donnees['ongletsNs'] = array('determination', 'retenu', 'decompo');
861 mathilde 185
		$donnees['ongletsNv'] = array('determination', 'alphab');
1140 raphael 186
		if (@$_GET['action'] == 'rechercheAvancee') {
725 mathilde 187
			$donnees['urls']['alphab'] = $this->urls->obtenirUrlResultatAvanceOnglets('alphab', $this->param);
188
			$donnees['urls']['retenu'] = $this->urls->obtenirUrlResultatAvanceOnglets('retenu', $this->param);
189
			$donnees['urls']['determination'] = $this->urls->obtenirUrlResultatAvanceOnglets('determination',$this->param);
190
			$donnees['urls']['decompo'] = $this->urls->obtenirUrlResultatAvanceOnglets('decompo',$this->param);
861 mathilde 191
		} else {
1210 mathias 192
			$donnees['urls']['alphab'] = $this->urls->obtenirUrlResultat('alphab', $this->param);
193
			$donnees['urls']['retenu'] = $this->urls->obtenirUrlResultat('retenu', $this->param);
194
			$donnees['urls']['determination'] = $this->urls->obtenirUrlResultat('determination', $this->param);
195
			$donnees['urls']['decompo'] = $this->urls->obtenirUrlResultat('decompo', $this->param);
725 mathilde 196
		}
1210 mathias 197
		// Inversion du critère de filtrage de rang : espèces seulement VS tout (pas d'autre choix pour l'instant)
198
		//echo "PARAMS: <pre>" . print_r($this->param, true) . "</pre><br/>";
199
		$paramsAvecRangInverse = $this->param;
200
		if (array_key_exists('rang', $paramsAvecRangInverse)) {
201
			if ($paramsAvecRangInverse['rang'] == '*') {
1213 mathias 202
				$paramsAvecRangInverse['rang'] = 290;
203
			} else {
1210 mathias 204
				unset ($paramsAvecRangInverse['rang']);
205
			}
206
		}
207
		//echo "PARAMS INV: <pre>" . print_r($paramsAvecRangInverse, true) . "</pre><br/>";
208
		$this->donneesTpl['urlInverse'] = $this->urls->obtenirUrlResultat($donnees['typeResultat'], $paramsAvecRangInverse);
209
		//echo "URL INV: " . $this->donneesTpl['urlInverse'] . "<br/>";
210
 
855 mathilde 211
		$donnees['i18n']['nv'] = I18n::get('Resultat-onglets-nv');
212
		$donnees['i18n']['ns'] = I18n::get('Resultat-onglets-ns');
162 jpm 213
		$this->donneesTpl['ongletsHtml'] = $this->getVue('onglets', $donnees);
84 jpm 214
	}
151 jpm 215
 
216
	private function chargerNbreDeTaxons() {
217
		$this->donneesTpl['nbreTaxons'] = $this->resultats['entete']['total'];
218
	}
219
 
1210 mathias 220
	// Filtre selon le rang à afficher (espèce, genre... tout)
221
	// et renvoie le nombre de taxons réellement affichés
222
	private function filtrer() {
223
		$nbTaxAff = 0;
224
		if ($this->parametres->rang != null) {
225
			foreach ($this->resultats['resultat'] as $c => $v) {
226
				$numRang = substr($v['rang.code'], strrpos($v['rang.code'], ':') +1);
227
				if ($numRang != $this->parametres->rang) {
228
					unset($this->resultats['resultat'][$c]);
229
				} else {
230
					$nbTaxAff++;
231
				}
232
			}
233
		} else {
234
			$nbTaxAff = $this->resultats['entete']['total'];
235
		}
236
		return $nbTaxAff;
237
	}
238
 
151 jpm 239
	private function chargerNomsFormates() {
240
		if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt mise en forme des noms");
1210 mathias 241
 
242
		// Filtre selon $this->parametres['rang'] pour afficher seulement un rang, ou bien tous
243
		// Valable uniquement pour la recherche par nom scientifique
244
		//echo "<pre>".print_r($this->parametres, true)."</pre>";
245
		if ($this->parametres->typeNom == 'nom_scientifique') {
246
			$this->donneesTpl['nombreTaxonsAffiches'] = $this->filtrer();
247
			$this->donneesTpl['rang'] = $this->parametres->rang;
248
		} else {
249
			$this->donneesTpl['nombreTaxonsAffiches'] = $this->donneesTpl['nbreTaxons'];
250
		}
251
		$this->donneesTpl['typeNom'] = $this->parametres->typeNom;
252
 
151 jpm 253
		$formateur = ResultatFormateurFabrique::creer($this->parametres, $this->resultats);
254
		if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt formatage des noms");
255
		$formateur->formater();
256
		if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt triage des noms");
257
		$formateur->trier();
258
		if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt surlignage des noms");
259
		$formateur->surligner();
260
		if (Config::get('benchmark_chrono')) Chronometre::chrono("Avt création de la vue");
261
		$this->donneesTpl['nomsHtml'] = $this->getVue($formateur->getTplNom(), $formateur->getTplInfos());
262
		if (Config::get('benchmark_chrono')) Chronometre::chrono("Après mise en forme des noms");
263
	}
76 delphine 264
}
265
?>