Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Go to most recent revision | Details | 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() {
10
		$rechercheAccueil = $this->executerAction('recherche-simple', 'accueil');
11
		$this->setSortie(self::RENDU_CORPS, $rechercheAccueil);
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
		}
31
		Registre::set('donnees', $donnees);
32
		$this->executerAction('recherche_simple', 'executerForm');
33
	}
34
 
35
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
36
	private function rechercherNom($noms) {
37
		$approche = '';
38
		$res = $noms->getRechercheEtendue($_GET['nom']);
39
		$form = I18n::get('Recherche-form-nom');
40
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
41
			$res = $noms->getRechercheFloue($_GET['nom']);
42
			if (!($res == false || $res['entete']['total'] == 0)) {
43
				$nom_proche = array_shift($res['resultat']);
44
				$approche = ($_GET['type_nom'] == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
45
			}
46
		} elseif ($res['entete']['total'] == 1 || urldecode($_GET['submit']) == $form['fiche']) { // renvoie à la fiche
47
			$ids = array_keys($res['resultat']);
48
			$url = $this->obtenirUrlFiche($ids[0]);
49
			$this->redirigerVers($url);
50
		} else { // affiche les résultats
51
			$approche = 'ok';
52
		}
53
		return $approche;
54
	}
55
 
56
}
57
?>