Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 88 | 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';
8
	protected $submit = '';
9
	public function initialiser() {
10
		$this->capturerParametres();
11
	}
74 delphine 12
	/**
13
	 * Fonction d'affichage par défaut
14
	 */
15
	public function executerActionParDefaut() {
76 delphine 16
		$this->executerAction('RechercheSimple', 'executerAccueil');
17
 
74 delphine 18
	}
19
 
20
	public function executerRechercheSimple() {
85 delphine 21
		$donnees['type_nom'] = $this->type_nom;
22
		$donnees['nom'] = $this->nom;
74 delphine 23
		if (strlen($donnees['nom']) < 3) {
123 delphine 24
			$donnees['message']['attention'] = 'info_nb_lettres';
74 delphine 25
		} else {
88 delphine 26
			$presence = $this->rechercherNom();
123 delphine 27
			if ($presence == '') { // s'il n'y a pas de nom
28
				$donnees['message']['attention'] = 'info_sp_abs';
29
			} elseif ($presence != 'ok') { // s'il y a des noms approchés
30
				if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
31
					$donnees['message']['attention'] = 'info_sp_abs';
32
				}
33
				$donnees['message']['nom_approche'] = $presence;
74 delphine 34
			}
35
		}
76 delphine 36
		Registre::set('donneesMoteur', $donnees);
37
		$this->executerAction('RechercheSimple', 'executerForm');
88 delphine 38
		if (Registre::get('resultats')) {
76 delphine 39
			$this->executerAction('Resultat', 'executerResultat');
40
		}
74 delphine 41
	}
42
 
43
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
88 delphine 44
	// $noms classe métier nom ou nom
45
	private function rechercherNom() {
46
		$noms = ($this->type_nom == 'nom_vernaculaire')
47
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna'))
48
				: new Noms(Registre::get('parametres.referentiel'));
74 delphine 49
		$approche = '';
85 delphine 50
		$res = $noms->getRechercheEtendue($this->nom);
74 delphine 51
		$form = I18n::get('Recherche-form-nom');
52
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
88 delphine 53
			$approche = $this->rechercherNomApproche($noms);
85 delphine 54
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
74 delphine 55
			$ids = array_keys($res['resultat']);
56
			$url = $this->obtenirUrlFiche($ids[0]);
57
			$this->redirigerVers($url);
58
		} else { // affiche les résultats
85 delphine 59
			$res['type'] = $this->type_nom;
76 delphine 60
			Registre::set('resultats', $res);
74 delphine 61
			$approche = 'ok';
123 delphine 62
			if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
88 delphine 63
				$approche = $this->rechercherNomApproche($noms);
64
			}
74 delphine 65
		}
66
		return $approche;
67
	}
68
 
88 delphine 69
	private function rechercherNomApproche($noms) {
70
		$approche = '';
71
		$res = $noms->getRechercheFloue($this->nom);
72
		if (!($res == false || $res['entete']['total'] == 0)) {
123 delphine 73
			for ($i = 0; $i < 3; $i++) {
74
				$nom_proche = array_shift($res['resultat']);
75
				$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
76
				$approche[$i]['url_nom_approche'] = $this->obtenirUrlRechercheSimple($approche, $this->type_nom);
77
			}
88 delphine 78
		}
79
		return $approche;
80
	}
81
 
85 delphine 82
	private function capturerParametres() {
83
		if (isset($_GET['nom'])) {
84
			$this->nom = $_GET['nom'];
85
		}
86
		if (isset($_GET['type_nom'])) {
87
			$this->type_nom = $_GET['type_nom'];
88
		}
89
 
90
		if (isset($_GET['submit'])) {
91
			$this->submit = urldecode($_GET['submit']);
92
		}
93
	}
94
 
74 delphine 95
}
96
?>