Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 77 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 77 Rev 85
Line 1... Line 1...
1
<?php
1
<?php
2
class Recherche extends aControleur {
2
class Recherche extends aControleur {
Line 3... Line 3...
3
	
3
	
4
	//+----------------------------------------------------------------------------------------------------------------+
4
	//+----------------------------------------------------------------------------------------------------------------+
-
 
5
	// Méthodes
-
 
6
	protected $nom = null;
-
 
7
	protected $type_nom = 'nom_scientifique';
-
 
8
	protected $submit = '';
-
 
9
	public function initialiser() {
-
 
10
		$this->capturerParametres();
5
	// Méthodes
11
	}
6
	/**
12
	/**
7
	 * Fonction d'affichage par défaut
13
	 * Fonction d'affichage par défaut
8
	 */
14
	 */
9
	public function executerActionParDefaut() {
15
	public function executerActionParDefaut() {
Line 10... Line 16...
10
		$this->executerAction('RechercheSimple', 'executerAccueil');
16
		$this->executerAction('RechercheSimple', 'executerAccueil');
Line 11... Line 17...
11
		
17
		
12
	}
18
	}
13
 
19
 
14
	public function executerRechercheSimple() {
20
	public function executerRechercheSimple() {
15
		$donnees['type_nom'] = $_GET['type_nom'];
21
		$donnees['type_nom'] = $this->type_nom;
16
		$donnees['nom'] = $_GET['nom'];
22
		$donnees['nom'] = $this->nom;
17
		if (strlen($donnees['nom']) < 3) {
23
		if (strlen($donnees['nom']) < 3) {
18
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
24
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
19
		} else {
25
		} else {
20
			$noms = ($donnees['type_nom'] == 'nom_vernaculaire') 
26
			$noms = ($donnees['type_nom'] == 'nom_vernaculaire') 
21
				? new NomsVernaculaires(Config::get('referentielVerna')) 
27
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')) 
22
				: new Noms(Registre::get('parametres.referentiel'));
28
				: new Noms(Registre::get('parametres.referentiel'));
23
			$presence = $this->rechercherNom($noms);
29
			$presence = $this->rechercherNom($noms);
Line 36... Line 42...
36
	}
42
	}
Line 37... Line 43...
37
	
43
	
38
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
44
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
39
	private function rechercherNom($noms) {
45
	private function rechercherNom($noms) {
40
		$approche = '';
46
		$approche = '';
41
		$res = $noms->getRechercheEtendue($_GET['nom']);
47
		$res = $noms->getRechercheEtendue($this->nom);
42
		$form = I18n::get('Recherche-form-nom');
48
		$form = I18n::get('Recherche-form-nom');
43
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
49
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
44
			$res = $noms->getRechercheFloue($_GET['nom']);
50
			$res = $noms->getRechercheFloue($this->nom);
45
			if (!($res == false || $res['entete']['total'] == 0)) {
51
			if (!($res == false || $res['entete']['total'] == 0)) {
46
				$nom_proche = array_shift($res['resultat']);
52
				$nom_proche = array_shift($res['resultat']);
47
				$approche = ($_GET['type_nom'] == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
53
				$approche = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
48
			}
54
			}
49
		} elseif ($res['entete']['total'] == 1 || urldecode($_GET['submit']) == $form['fiche']) { // renvoie à la fiche
55
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
50
			$ids = array_keys($res['resultat']);
56
			$ids = array_keys($res['resultat']);
51
			$url = $this->obtenirUrlFiche($ids[0]);
57
			$url = $this->obtenirUrlFiche($ids[0]);
52
			$this->redirigerVers($url);
58
			$this->redirigerVers($url);
53
		} else { // affiche les résultats
59
		} else { // affiche les résultats
54
			$res['type'] = $_GET['type_nom'];
60
			$res['type'] = $this->type_nom;
55
			Registre::set('resultats', $res);
61
			Registre::set('resultats', $res);
56
			$approche = 'ok';
62
			$approche = 'ok';
57
		}
63
		}
58
		return $approche;
64
		return $approche;
Line -... Line 65...
-
 
65
	}
-
 
66
	
-
 
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
		}
59
	}
78
	}
60
	
79
	
61
}
80
}