Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev Author Line No. Line
74 delphine 1
<?php
2
class Recherche extends aControleur {
3
 
4
	//+----------------------------------------------------------------------------------------------------------------+
5
	// Méthodes
85 delphine 6
	protected $nom = null;
7
	protected $type_nom = 'nom_scientifique';
165 delphine 8
	protected $type_resultat = '';
85 delphine 9
	protected $submit = '';
729 mathilde 10
	private $recherche_avancee;
11
	private $param;
12
	private $i18n =  array();
13
 
85 delphine 14
	public function initialiser() {
15
		$this->capturerParametres();
729 mathilde 16
		$this->capturerParametresAvances();
17
		$this->i18n = I18n::get('Recherche-form-avancee');
85 delphine 18
	}
729 mathilde 19
 
74 delphine 20
	/**
21
	 * Fonction d'affichage par défaut
22
	 */
23
	public function executerActionParDefaut() {
179 delphine 24
		$this->executerAccueil();
74 delphine 25
	}
179 delphine 26
 
182 delphine 27
	public function executerAccueil($donneesMoteur = array()) {
179 delphine 28
		$niveau = new Niveau();
29
		$donnees['form_niveau'] = $niveau->afficherNiveau();
30
		$recherchesimple = new RechercheSimple();
182 delphine 31
		$donnees['form_nom'] = $recherchesimple->executerFormulaireNom($donneesMoteur);
729 mathilde 32
		if (Registre::get('parametres.niveau') != 1) {
33
			$recherche_avancee = new RechercheAvancee();
34
			$donnees['form_recherche_av'] = $recherche_avancee->executerFormulaireRechercheAv($donneesMoteur);
35
		}
179 delphine 36
		$this->afficherAccueil($donnees);
37
	}
38
 
39
	private function afficherAccueil($donnees) {
40
		$donnees['i18n'] = I18n::get('Recherche-accueil');
216 delphine 41
		$this->setSortie(self::RENDU_CORPS, $this->getVue('recherche_accueil', $donnees), true);
179 delphine 42
	}
74 delphine 43
 
729 mathilde 44
 
45
	//+---------------------------------------------recherche avancee-------------------------------------+
46
	public function executerRechercheAvancee() {
47
		$donnees['param'] = $this->param;
48
		$presence = $this->rechercherCriteresDemandes();
49
			if (empty($presence) && !empty($this->param)) {
50
				$donnees['message_av']['attention'] = 'info_res_vide';
51
				}
52
		$this->executerAccueil($donnees);
53
		if (Registre::get('resultats')) {
54
			$_GET['resultat'] = $this->type_resultat;
55
			$this->executerAction('Resultat', 'executerResultat');
56
		}
57
	}
58
 
59
	public function rechercherCriteresDemandes() {
60
		$noms = new Noms(Registre::get('parametres.referentiel'));
61
		$res = $noms->getRechercheAvancee($this->param);
62
		if ($res != false || $res['entete']['total'] != 0) {
63
			if ($res['entete']['total'] == 1 ) {
64
				$ids = array_keys($res['resultat']);
65
				$nom = $res['resultat'][$ids[0]]['nom_sci'];
66
				$url = $this->urls->obtenirUrlFiche($ids[0], 'nom_scientifique', $nom);
67
				$this->redirigerVers($url);
68
			} else {
69
			$res['type'] = $this->type_nom;
70
			Registre::set('resultats', $res);
71
			}
72
		} else {
73
			$res = '';
74
		}
75
		return $res;
76
	}
77
 
78
	//+---------------------------------------------recherche simple-------------------------------------+
74 delphine 79
	public function executerRechercheSimple() {
85 delphine 80
		$donnees['type_nom'] = $this->type_nom;
81
		$donnees['nom'] = $this->nom;
74 delphine 82
		if (strlen($donnees['nom']) < 3) {
123 delphine 83
			$donnees['message']['attention'] = 'info_nb_lettres';
74 delphine 84
		} else {
88 delphine 85
			$presence = $this->rechercherNom();
123 delphine 86
			if ($presence == '') { // s'il n'y a pas de nom
87
				$donnees['message']['attention'] = 'info_sp_abs';
720 delphine 88
			} elseif ($presence == 'sans_correspondance') {
89
				$res = Registre::get('resultats');
90
				$id = array_keys($res['resultat']);
91
				$donnees['message']['nom_ss_corresp']['id'] = $id[0];
92
				$nom = array_shift($res['resultat']);
93
				$donnees['message']['nom_ss_corresp']['nom'] = $nom['nom_sci'];
123 delphine 94
			} elseif ($presence != 'ok') { // s'il y a des noms approchés
95
				if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
96
					$donnees['message']['attention'] = 'info_sp_abs';
97
				}
98
				$donnees['message']['nom_approche'] = $presence;
74 delphine 99
			}
100
		}
179 delphine 101
		$this->executerAccueil($donnees);
88 delphine 102
		if (Registre::get('resultats')) {
185 delphine 103
			$_GET['resultat'] = $this->type_resultat;
76 delphine 104
			$this->executerAction('Resultat', 'executerResultat');
105
		}
74 delphine 106
	}
107
 
729 mathilde 108
 
74 delphine 109
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
88 delphine 110
	// $noms classe métier nom ou nom
111
	private function rechercherNom() {
112
		$noms = ($this->type_nom == 'nom_vernaculaire')
113
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna'))
114
				: new Noms(Registre::get('parametres.referentiel'));
74 delphine 115
		$approche = '';
165 delphine 116
		$res = $noms->getRechercheEtendue($this->nom, $this->type_resultat);
74 delphine 117
		$form = I18n::get('Recherche-form-nom');
118
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
88 delphine 119
			$approche = $this->rechercherNomApproche($noms);
85 delphine 120
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
720 delphine 121
			$approche = $this->traiterAccesFiche($res);
74 delphine 122
		} else { // affiche les résultats
85 delphine 123
			$res['type'] = $this->type_nom;
76 delphine 124
			Registre::set('resultats', $res);
74 delphine 125
			$approche = 'ok';
123 delphine 126
			if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
88 delphine 127
				$approche = $this->rechercherNomApproche($noms);
128
			}
74 delphine 129
		}
130
		return $approche;
131
	}
132
 
720 delphine 133
	private function traiterAccesFiche($res) {
134
		$ids = array_keys($res['resultat']);
135
		if ($this->type_nom == 'nom_vernaculaire') {
136
			$id = explode(':',$res['resultat'][$ids[0]]['nom_retenu.code']);
137
			$id = $id[1];
138
		} else {
139
			if ($res['resultat'][$ids[0]]['retenu'] == 'absent') { // dans le cas d'un nom sans correspondance
140
				$res['type'] = $this->type_nom;
141
				Registre::set('resultats', $res);
142
				$approche = 'sans_correspondance';
143
				return $approche;
144
			} else {
145
				$id = $ids[0];
146
			}
147
		}
148
		$url = $this->urls->obtenirUrlFiche($id, $this->type_nom, $this->nom);
149
		$this->redirigerVers($url);
150
	}
151
 
88 delphine 152
	private function rechercherNomApproche($noms) {
153
		$approche = '';
154
		$res = $noms->getRechercheFloue($this->nom);
155
		if (!($res == false || $res['entete']['total'] == 0)) {
123 delphine 156
			for ($i = 0; $i < 3; $i++) {
157
				$nom_proche = array_shift($res['resultat']);
158
				$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
156 delphine 159
				$approche[$i]['url_nom_approche'] = $this->urls->obtenirUrlRechercheSimple($approche[$i]['nom'], $this->type_nom);
123 delphine 160
			}
88 delphine 161
		}
162
		return $approche;
163
	}
164
 
729 mathilde 165
	//+-----------------------------------------------méthodes utiles---------------------------------+
179 delphine 166
 
85 delphine 167
	private function capturerParametres() {
720 delphine 168
		if (isset($_REQUEST['nom'])) {
169
			$this->nom = $_REQUEST['nom'];
85 delphine 170
		}
171
		if (isset($_GET['type_nom'])) {
172
			$this->type_nom = $_GET['type_nom'];
173
		}
174
		if (isset($_GET['submit'])) {
175
			$this->submit = urldecode($_GET['submit']);
176
		}
174 delphine 177
		if (isset($_GET['niveau'])) {
178
			Registre::set('parametres.niveau', $_GET['niveau']);
179
		}
165 delphine 180
		if (isset($_GET['resultat'])) {
181
			$this->type_resultat = urldecode($_GET['resultat']);
182
		} else {
183
			$onglet_resultat = $this->recupererTableauConfig('affich_resultats');
184
			$this->type_resultat = $onglet_resultat[Registre::get('parametres.niveau').'_'.$this->type_nom];
185
		}
85 delphine 186
	}
187
 
729 mathilde 188
	private function capturerParametresAvances() {
189
		if (isset($_GET['gen']) && $_GET['gen'] != '') {
190
			$this->param['gen'] = urldecode($_GET['gen']);
191
		}
192
		if (isset($_GET['fam']) && $_GET['fam'] != '') {
193
			$this->param['fam'] = urldecode($_GET['fam']);
194
		}
195
		if (isset($_GET['au']) && $_GET['au'] != ''
196
			&& $_GET['au'] != urlencode($this->i18n['valeur-form-auteur'])) {
197
			$this->param['au'] = urldecode($_GET['au']);
198
		}
199
		if (isset($_GET['bib']) && $_GET['bib'] != ''
200
			&& $_GET['bib'] != urlencode($this->i18n['valeur-form-bib'])) {
201
			$this->param['bib'] = urldecode($_GET['bib']);
202
		}
203
		if (isset($_GET['nn']) && $_GET['nn'] != '') {
204
			$this->param['nn'] = urldecode($_GET['nn']);
205
		}
206
		if (isset($_GET['nt']) && $_GET['nt'] != '') {
207
			$this->param['nt'] = urldecode($_GET['nt']);
208
		}
209
		if (isset($_GET['sp']) && $_GET['sp'] != '') {
210
			$this->param['sp'] = urldecode($_GET['sp']);
211
		}
212
		if (isset($_GET['ssp']) && $_GET['ssp'] != '') {
213
			$this->param['ssp'] = urldecode($_GET['ssp']);
214
		}
215
		if (isset($_GET['type']) && $_GET['type'] != '') {
216
			$this->param['type'] = urldecode($_GET['type']);
217
		}
218
		if (isset($_GET['and']) && $_GET['and'] != ''
219
			&& $_GET['and'] != urlencode($this->i18n['valeur-form-date'])) {
220
			$this->param['and'] = urldecode($_GET['and']);
221
		}
222
		if (isset($_GET['anf']) && $_GET['anf'] != ''
223
			&& $_GET['anf'] != urlencode($this->i18n['valeur-form-date'])) {
224
			$this->param['anf'] = urldecode($_GET['anf']);
225
		}
226
		if (isset($_GET['prga']) && $_GET['prga'] != '') {
227
			$this->param['prga'] = urldecode($_GET['prga']);
228
		}
229
		if (isset($_GET['prco']) && $_GET['prco'] != '') {
230
			$this->param['prco'] = urldecode($_GET['prco']);
231
		}
232
		if (isset($_GET['sto']) && $_GET['sto'] != '') {
233
			$this->param['sto'] = urldecode($_GET['sto']);
234
		}
235
		if (isset($_GET['sti']) && $_GET['sti'] != '') {
236
			$this->param['sti'] = urldecode($_GET['sti']);
237
		}
238
		if (isset($_GET['stc']) && $_GET['stc'] != '') {
239
			$this->param['stc'] = urldecode($_GET['stc']);
240
		}
241
	}
242
 
165 delphine 243
	protected function recupererTableauConfig($param) {
244
		$tableau = array();
245
		$tableauPartiel = explode(',', Config::get($param));
246
		$tableauPartiel = array_map('trim', $tableauPartiel);
247
		foreach ($tableauPartiel as $champ) {
248
			if (strpos($champ, '=') === false) {
249
				$tableau[] = $champ;
250
			} else {
251
				list($cle, $val) = explode('=', $champ);
252
				$tableau[$cle] = $val;
253
			}
254
		}
255
		return $tableau;
256
	}
257
 
74 delphine 258
}
259
?>