Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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