Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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