Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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