Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 85 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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