Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 74 | 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
6
	/**
7
	 * Fonction d'affichage par défaut
8
	 */
9
	public function executerActionParDefaut() {
76 delphine 10
		$this->executerAction('RechercheSimple', 'executerAccueil');
11
 
74 delphine 12
	}
13
 
14
	public function executerRechercheSimple() {
15
		$donnees['type_nom'] = $_GET['type_nom'];
16
		$donnees['nom'] = $_GET['nom'];
17
		if (strlen($donnees['nom']) < 3) {
18
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
19
		} else {
20
			$noms = ($donnees['type_nom'] == 'nom_vernaculaire')
21
				? new NomsVernaculaires(Config::get('referentielVerna'))
22
				: new Noms(Registre::get('parametres.referentiel'));
23
			$presence = $this->rechercherNom($noms);
24
			if ($presence == '') {
25
				$donnees['information'] = 'Nom inconnu';
26
			} elseif ($presence != 'ok') {
27
				$donnees['nom_approche'] = $presence;
28
				$donnees['url_nom_approche'] = $this->obtenirUrlRechercheSimple($presence, $donnees['type_nom']);
29
			}
30
		}
76 delphine 31
		Registre::set('donneesMoteur', $donnees);
32
		$this->executerAction('RechercheSimple', 'executerForm');
33
		if ($presence == 'ok') {
34
			$this->executerAction('Resultat', 'executerResultat');
35
		}
74 delphine 36
	}
37
 
38
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
39
	private function rechercherNom($noms) {
40
		$approche = '';
41
		$res = $noms->getRechercheEtendue($_GET['nom']);
42
		$form = I18n::get('Recherche-form-nom');
43
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
44
			$res = $noms->getRechercheFloue($_GET['nom']);
45
			if (!($res == false || $res['entete']['total'] == 0)) {
46
				$nom_proche = array_shift($res['resultat']);
47
				$approche = ($_GET['type_nom'] == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
48
			}
49
		} elseif ($res['entete']['total'] == 1 || urldecode($_GET['submit']) == $form['fiche']) { // renvoie à la fiche
50
			$ids = array_keys($res['resultat']);
51
			$url = $this->obtenirUrlFiche($ids[0]);
52
			$this->redirigerVers($url);
53
		} else { // affiche les résultats
76 delphine 54
			Registre::set('resultats', $res);
74 delphine 55
			$approche = 'ok';
56
		}
57
		return $approche;
58
	}
59
 
60
}
61
?>