Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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