Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 85 | 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) {
24
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
25
		} else {
88 delphine 26
			$presence = $this->rechercherNom();
74 delphine 27
			if ($presence == '') {
28
				$donnees['information'] = 'Nom inconnu';
29
			} elseif ($presence != 'ok') {
30
				$donnees['nom_approche'] = $presence;
31
				$donnees['url_nom_approche'] = $this->obtenirUrlRechercheSimple($presence, $donnees['type_nom']);
32
			}
33
		}
76 delphine 34
		Registre::set('donneesMoteur', $donnees);
35
		$this->executerAction('RechercheSimple', 'executerForm');
88 delphine 36
		if (Registre::get('resultats')) {
76 delphine 37
			$this->executerAction('Resultat', 'executerResultat');
38
		}
74 delphine 39
	}
40
 
41
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
88 delphine 42
	// $noms classe métier nom ou nom
43
	private function rechercherNom() {
44
		$noms = ($this->type_nom == 'nom_vernaculaire')
45
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna'))
46
				: new Noms(Registre::get('parametres.referentiel'));
74 delphine 47
		$approche = '';
85 delphine 48
		$res = $noms->getRechercheEtendue($this->nom);
74 delphine 49
		$form = I18n::get('Recherche-form-nom');
50
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
88 delphine 51
			$approche = $this->rechercherNomApproche($noms);
85 delphine 52
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
74 delphine 53
			$ids = array_keys($res['resultat']);
54
			$url = $this->obtenirUrlFiche($ids[0]);
55
			$this->redirigerVers($url);
56
		} else { // affiche les résultats
85 delphine 57
			$res['type'] = $this->type_nom;
76 delphine 58
			Registre::set('resultats', $res);
74 delphine 59
			$approche = 'ok';
88 delphine 60
			if ($res['entete']['total'] < 16) { // si moins de 16 noms affiche en plus un nom approché
61
				$approche = $this->rechercherNomApproche($noms);
62
			}
74 delphine 63
		}
64
		return $approche;
65
	}
66
 
88 delphine 67
	private function rechercherNomApproche($noms) {
68
		$approche = '';
69
		$res = $noms->getRechercheFloue($this->nom);
70
		if (!($res == false || $res['entete']['total'] == 0)) {
71
			$nom_proche = array_shift($res['resultat']);
72
			$approche = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
73
		}
74
		return $approche;
75
	}
76
 
85 delphine 77
	private function capturerParametres() {
78
		if (isset($_GET['nom'])) {
79
			$this->nom = $_GET['nom'];
80
		}
81
		if (isset($_GET['type_nom'])) {
82
			$this->type_nom = $_GET['type_nom'];
83
		}
84
 
85
		if (isset($_GET['submit'])) {
86
			$this->submit = urldecode($_GET['submit']);
87
		}
88
	}
89
 
74 delphine 90
}
91
?>