Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 165 Rev 174
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 $type_resultat = '';
8
	protected $type_resultat = '';
9
	protected $submit = '';
9
	protected $submit = '';
10
	public function initialiser() {
10
	public function initialiser() {
11
		$this->capturerParametres();
11
		$this->capturerParametres();
12
	}
12
	}
13
	/**
13
	/**
14
	 * Fonction d'affichage par défaut
14
	 * Fonction d'affichage par défaut
15
	 */
15
	 */
16
	public function executerActionParDefaut() {
16
	public function executerActionParDefaut() {
17
		$this->executerAction('RechercheSimple', 'executerAccueil');
17
		$this->executerAction('RechercheSimple', 'executerAccueil');
18
		
18
		
19
	}
19
	}
20
 
20
 
21
	public function executerRechercheSimple() {
21
	public function executerRechercheSimple() {
22
		$donnees['type_nom'] = $this->type_nom;
22
		$donnees['type_nom'] = $this->type_nom;
23
		$donnees['nom'] = $this->nom;
23
		$donnees['nom'] = $this->nom;
24
		if (strlen($donnees['nom']) < 3) {
24
		if (strlen($donnees['nom']) < 3) {
25
			$donnees['message']['attention'] = 'info_nb_lettres';
25
			$donnees['message']['attention'] = 'info_nb_lettres';
26
		} else {
26
		} else {
27
			$presence = $this->rechercherNom();
27
			$presence = $this->rechercherNom();
28
			if ($presence == '') { // s'il n'y a pas de nom
28
			if ($presence == '') { // s'il n'y a pas de nom
29
				$donnees['message']['attention'] = 'info_sp_abs';
29
				$donnees['message']['attention'] = 'info_sp_abs';
30
			} elseif ($presence != 'ok') { // s'il y a des noms approchés
30
			} elseif ($presence != 'ok') { // s'il y a des noms approchés
31
				if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
31
				if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
32
					$donnees['message']['attention'] = 'info_sp_abs';
32
					$donnees['message']['attention'] = 'info_sp_abs';
33
				}
33
				}
34
				$donnees['message']['nom_approche'] = $presence;
34
				$donnees['message']['nom_approche'] = $presence;
35
			}
35
			}
36
		}
36
		}
37
		Registre::set('donneesMoteur', $donnees);
37
		Registre::set('donneesMoteur', $donnees);
38
		$this->executerAction('RechercheSimple', 'executerForm');
38
		$this->executerAction('RechercheSimple', 'executerForm');
39
		if (Registre::get('resultats')) {
39
		if (Registre::get('resultats')) {
40
			$this->executerAction('Resultat', 'executerResultat');
40
			$this->executerAction('Resultat', 'executerResultat');
41
		}
41
		}
42
	}
42
	}
43
	
43
	
44
	// 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é
45
	// $noms classe métier nom ou nom
45
	// $noms classe métier nom ou nom
46
	private function rechercherNom() {
46
	private function rechercherNom() {
47
		$noms = ($this->type_nom == 'nom_vernaculaire') 
47
		$noms = ($this->type_nom == 'nom_vernaculaire') 
48
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')) 
48
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')) 
49
				: new Noms(Registre::get('parametres.referentiel'));
49
				: new Noms(Registre::get('parametres.referentiel'));
50
		$approche = '';
50
		$approche = '';
51
		$res = $noms->getRechercheEtendue($this->nom, $this->type_resultat);
51
		$res = $noms->getRechercheEtendue($this->nom, $this->type_resultat);
52
		$form = I18n::get('Recherche-form-nom');
52
		$form = I18n::get('Recherche-form-nom');
53
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
53
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
54
			$approche = $this->rechercherNomApproche($noms);
54
			$approche = $this->rechercherNomApproche($noms);
55
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
55
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
56
			$ids = array_keys($res['resultat']);
56
			$ids = array_keys($res['resultat']);
57
			$url = $this->urls->obtenirUrlFiche($ids[0]);
57
			$url = $this->urls->obtenirUrlFiche($ids[0]);
58
			$this->redirigerVers($url);
58
			$this->redirigerVers($url);
59
		} else { // affiche les résultats
59
		} else { // affiche les résultats
60
			$res['type'] = $this->type_nom;
60
			$res['type'] = $this->type_nom;
61
			Registre::set('resultats', $res);
61
			Registre::set('resultats', $res);
62
			$approche = 'ok';
62
			$approche = 'ok';
63
			if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
63
			if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
64
				$approche = $this->rechercherNomApproche($noms);
64
				$approche = $this->rechercherNomApproche($noms);
65
			}
65
			}
66
		}
66
		}
67
		return $approche;
67
		return $approche;
68
	}
68
	}
69
	
69
	
70
	private function rechercherNomApproche($noms) {
70
	private function rechercherNomApproche($noms) {
71
		$approche = '';
71
		$approche = '';
72
		$res = $noms->getRechercheFloue($this->nom);
72
		$res = $noms->getRechercheFloue($this->nom);
73
		if (!($res == false || $res['entete']['total'] == 0)) {
73
		if (!($res == false || $res['entete']['total'] == 0)) {
74
			for ($i = 0; $i < 3; $i++) {
74
			for ($i = 0; $i < 3; $i++) {
75
				$nom_proche = array_shift($res['resultat']);
75
				$nom_proche = array_shift($res['resultat']);
76
				$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
76
				$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
77
				$approche[$i]['url_nom_approche'] = $this->urls->obtenirUrlRechercheSimple($approche[$i]['nom'], $this->type_nom);
77
				$approche[$i]['url_nom_approche'] = $this->urls->obtenirUrlRechercheSimple($approche[$i]['nom'], $this->type_nom);
78
			}
78
			}
79
		}
79
		}
80
		return $approche;
80
		return $approche;
81
	}
81
	}
82
	
82
	
83
	private function capturerParametres() {
83
	private function capturerParametres() {
84
		if (isset($_GET['nom'])) {
84
		if (isset($_GET['nom'])) {
85
			$this->nom = $_GET['nom'];
85
			$this->nom = $_GET['nom'];
86
		}
86
		}
87
		if (isset($_GET['type_nom'])) {
87
		if (isset($_GET['type_nom'])) {
88
			$this->type_nom = $_GET['type_nom'];
88
			$this->type_nom = $_GET['type_nom'];
89
		}
89
		}
90
		
90
		
91
		if (isset($_GET['submit'])) {
91
		if (isset($_GET['submit'])) {
92
			$this->submit = urldecode($_GET['submit']);
92
			$this->submit = urldecode($_GET['submit']);
93
		}
93
		}
-
 
94
		
-
 
95
		if (isset($_GET['niveau'])) {
-
 
96
			Registre::set('parametres.niveau', $_GET['niveau']);
-
 
97
		}
94
		
98
		
95
		if (isset($_GET['resultat'])) {
99
		if (isset($_GET['resultat'])) {
96
			$this->type_resultat = urldecode($_GET['resultat']);
100
			$this->type_resultat = urldecode($_GET['resultat']);
97
		} else {
101
		} else {
98
			$onglet_resultat = $this->recupererTableauConfig('affich_resultats');
102
			$onglet_resultat = $this->recupererTableauConfig('affich_resultats');
99
			$this->type_resultat = $onglet_resultat[Registre::get('parametres.niveau').'_'.$this->type_nom];
103
			$this->type_resultat = $onglet_resultat[Registre::get('parametres.niveau').'_'.$this->type_nom];
100
		}
104
		}
101
	}
105
	}
102
	
106
	
103
	protected function recupererTableauConfig($param) {
107
	protected function recupererTableauConfig($param) {
104
		$tableau = array();
108
		$tableau = array();
105
		$tableauPartiel = explode(',', Config::get($param));
109
		$tableauPartiel = explode(',', Config::get($param));
106
		$tableauPartiel = array_map('trim', $tableauPartiel);
110
		$tableauPartiel = array_map('trim', $tableauPartiel);
107
		foreach ($tableauPartiel as $champ) {
111
		foreach ($tableauPartiel as $champ) {
108
			if (strpos($champ, '=') === false) {
112
			if (strpos($champ, '=') === false) {
109
				$tableau[] = $champ;
113
				$tableau[] = $champ;
110
			} else {
114
			} else {
111
				list($cle, $val) = explode('=', $champ);
115
				list($cle, $val) = explode('=', $champ);
112
				$tableau[$cle] = $val;
116
				$tableau[$cle] = $val;
113
			}
117
			}
114
		}
118
		}
115
		return $tableau;
119
		return $tableau;
116
	}
120
	}
117
	
121
	
118
}
122
}
119
?>
123
?>