Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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