Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 156 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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