Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 720 Rev 729
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
	private $recherche_avancee;
-
 
11
	private $param;
-
 
12
	private $i18n =  array();
-
 
13
	
10
	public function initialiser() {
14
	public function initialiser() {
11
		$this->capturerParametres();
15
		$this->capturerParametres();
-
 
16
		$this->capturerParametresAvances();	
-
 
17
		$this->i18n = I18n::get('Recherche-form-avancee');
12
	}
18
	}
-
 
19
	
13
	/**
20
	/**
14
	 * Fonction d'affichage par défaut
21
	 * Fonction d'affichage par défaut
15
	 */
22
	 */
16
	public function executerActionParDefaut() {
23
	public function executerActionParDefaut() {
17
		$this->executerAccueil();
24
		$this->executerAccueil();
18
	}
25
	}
19
	
26
	
20
	public function executerAccueil($donneesMoteur = array()) {
27
	public function executerAccueil($donneesMoteur = array()) {
21
		$niveau = new Niveau();
28
		$niveau = new Niveau();
22
		$donnees['form_niveau'] = $niveau->afficherNiveau();
29
		$donnees['form_niveau'] = $niveau->afficherNiveau();
23
		$recherchesimple = new RechercheSimple();
30
		$recherchesimple = new RechercheSimple();
24
		$donnees['form_nom'] = $recherchesimple->executerFormulaireNom($donneesMoteur);
31
		$donnees['form_nom'] = $recherchesimple->executerFormulaireNom($donneesMoteur);
-
 
32
		if (Registre::get('parametres.niveau') != 1) {
-
 
33
			$recherche_avancee = new RechercheAvancee();
-
 
34
			$donnees['form_recherche_av'] = $recherche_avancee->executerFormulaireRechercheAv($donneesMoteur);
-
 
35
		}
25
		$this->afficherAccueil($donnees);
36
		$this->afficherAccueil($donnees);
26
	}
37
	}
27
	
38
	
28
	private function afficherAccueil($donnees) {
39
	private function afficherAccueil($donnees) {
29
		$donnees['i18n'] = I18n::get('Recherche-accueil');
40
		$donnees['i18n'] = I18n::get('Recherche-accueil');
30
		$this->setSortie(self::RENDU_CORPS, $this->getVue('recherche_accueil', $donnees), true);
41
		$this->setSortie(self::RENDU_CORPS, $this->getVue('recherche_accueil', $donnees), true);
31
	}
42
	}
-
 
43
 
-
 
44
	
-
 
45
	//+---------------------------------------------recherche avancee-------------------------------------+	
-
 
46
	public function executerRechercheAvancee() {
-
 
47
		$donnees['param'] = $this->param;
-
 
48
		$presence = $this->rechercherCriteresDemandes();
-
 
49
			if (empty($presence) && !empty($this->param)) {
-
 
50
				$donnees['message_av']['attention'] = 'info_res_vide';
-
 
51
				} 
-
 
52
		$this->executerAccueil($donnees);
-
 
53
		if (Registre::get('resultats')) {
-
 
54
			$_GET['resultat'] = $this->type_resultat;
-
 
55
			$this->executerAction('Resultat', 'executerResultat');
-
 
56
		}
-
 
57
	}
-
 
58
	
-
 
59
	public function rechercherCriteresDemandes() {
-
 
60
		$noms = new Noms(Registre::get('parametres.referentiel'));
-
 
61
		$res = $noms->getRechercheAvancee($this->param);
-
 
62
		if ($res != false || $res['entete']['total'] != 0) {
-
 
63
			if ($res['entete']['total'] == 1 ) {
-
 
64
				$ids = array_keys($res['resultat']);
-
 
65
				$nom = $res['resultat'][$ids[0]]['nom_sci'];
-
 
66
				$url = $this->urls->obtenirUrlFiche($ids[0], 'nom_scientifique', $nom);
-
 
67
				$this->redirigerVers($url);
-
 
68
			} else {
-
 
69
			$res['type'] = $this->type_nom;
-
 
70
			Registre::set('resultats', $res);
-
 
71
			}
-
 
72
		} else {
-
 
73
			$res = '';
-
 
74
		}
-
 
75
		return $res;
-
 
76
	}
-
 
77
	
32
 
78
	//+---------------------------------------------recherche simple-------------------------------------+
33
	public function executerRechercheSimple() {
79
	public function executerRechercheSimple() {
34
		$donnees['type_nom'] = $this->type_nom;
80
		$donnees['type_nom'] = $this->type_nom;
35
		$donnees['nom'] = $this->nom;
81
		$donnees['nom'] = $this->nom;
36
		if (strlen($donnees['nom']) < 3) {
82
		if (strlen($donnees['nom']) < 3) {
37
			$donnees['message']['attention'] = 'info_nb_lettres';
83
			$donnees['message']['attention'] = 'info_nb_lettres';
38
		} else {
84
		} else {
39
			$presence = $this->rechercherNom();
85
			$presence = $this->rechercherNom();
40
			if ($presence == '') { // s'il n'y a pas de nom
86
			if ($presence == '') { // s'il n'y a pas de nom
41
				$donnees['message']['attention'] = 'info_sp_abs';
87
				$donnees['message']['attention'] = 'info_sp_abs';
42
			} elseif ($presence == 'sans_correspondance') {
88
			} elseif ($presence == 'sans_correspondance') {
43
				$res = Registre::get('resultats');
89
				$res = Registre::get('resultats');
44
				$id = array_keys($res['resultat']);
90
				$id = array_keys($res['resultat']);
45
				$donnees['message']['nom_ss_corresp']['id'] = $id[0];
91
				$donnees['message']['nom_ss_corresp']['id'] = $id[0];
46
				$nom = array_shift($res['resultat']);
92
				$nom = array_shift($res['resultat']);
47
				$donnees['message']['nom_ss_corresp']['nom'] = $nom['nom_sci'];
93
				$donnees['message']['nom_ss_corresp']['nom'] = $nom['nom_sci'];
48
			} elseif ($presence != 'ok') { // s'il y a des noms approchés
94
			} elseif ($presence != 'ok') { // s'il y a des noms approchés
49
				if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
95
				if (!Registre::get('resultats')) { // s'il n'y a aucun nom exact
50
					$donnees['message']['attention'] = 'info_sp_abs';
96
					$donnees['message']['attention'] = 'info_sp_abs';
51
				}
97
				}
52
				$donnees['message']['nom_approche'] = $presence;
98
				$donnees['message']['nom_approche'] = $presence;
53
			}
99
			}
54
		}
100
		}
55
		$this->executerAccueil($donnees);
101
		$this->executerAccueil($donnees);
56
		if (Registre::get('resultats')) {
102
		if (Registre::get('resultats')) {
57
			$_GET['resultat'] = $this->type_resultat;
103
			$_GET['resultat'] = $this->type_resultat;
58
			$this->executerAction('Resultat', 'executerResultat');
104
			$this->executerAction('Resultat', 'executerResultat');
59
		}
105
		}
60
	}
106
	}
-
 
107
	
61
	
108
	
62
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
109
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
63
	// $noms classe métier nom ou nom
110
	// $noms classe métier nom ou nom
64
	private function rechercherNom() {
111
	private function rechercherNom() {
65
		$noms = ($this->type_nom == 'nom_vernaculaire') 
112
		$noms = ($this->type_nom == 'nom_vernaculaire') 
66
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')) 
113
				? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')) 
67
				: new Noms(Registre::get('parametres.referentiel'));
114
				: new Noms(Registre::get('parametres.referentiel'));
68
		$approche = '';
115
		$approche = '';
69
		$res = $noms->getRechercheEtendue($this->nom, $this->type_resultat);
116
		$res = $noms->getRechercheEtendue($this->nom, $this->type_resultat);
70
		$form = I18n::get('Recherche-form-nom');
117
		$form = I18n::get('Recherche-form-nom');
71
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
118
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
72
			$approche = $this->rechercherNomApproche($noms);
119
			$approche = $this->rechercherNomApproche($noms);
73
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
120
		} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche
74
			$approche = $this->traiterAccesFiche($res);
121
			$approche = $this->traiterAccesFiche($res);
75
		} else { // affiche les résultats
122
		} else { // affiche les résultats
76
			$res['type'] = $this->type_nom;
123
			$res['type'] = $this->type_nom;
77
			Registre::set('resultats', $res);
124
			Registre::set('resultats', $res);
78
			$approche = 'ok';
125
			$approche = 'ok';
79
			if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
126
			if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché
80
				$approche = $this->rechercherNomApproche($noms);
127
				$approche = $this->rechercherNomApproche($noms);
81
			}
128
			}
82
		}
129
		}
83
		return $approche;
130
		return $approche;
84
	}
131
	}
85
	
132
	
86
	private function traiterAccesFiche($res) {
133
	private function traiterAccesFiche($res) {
87
		$ids = array_keys($res['resultat']);
134
		$ids = array_keys($res['resultat']);
88
		if ($this->type_nom == 'nom_vernaculaire') {
135
		if ($this->type_nom == 'nom_vernaculaire') {
89
			$id = explode(':',$res['resultat'][$ids[0]]['nom_retenu.code']);
136
			$id = explode(':',$res['resultat'][$ids[0]]['nom_retenu.code']);
90
			$id = $id[1];
137
			$id = $id[1];
91
		} else {
138
		} else {
92
			if ($res['resultat'][$ids[0]]['retenu'] == 'absent') { // dans le cas d'un nom sans correspondance
139
			if ($res['resultat'][$ids[0]]['retenu'] == 'absent') { // dans le cas d'un nom sans correspondance
93
				$res['type'] = $this->type_nom;
140
				$res['type'] = $this->type_nom;
94
				Registre::set('resultats', $res);
141
				Registre::set('resultats', $res);
95
				$approche = 'sans_correspondance';
142
				$approche = 'sans_correspondance';
96
				return $approche;
143
				return $approche;
97
			} else {
144
			} else {
98
				$id = $ids[0];
145
				$id = $ids[0];
99
			}
146
			}
100
		}
147
		}
101
		$url = $this->urls->obtenirUrlFiche($id, $this->type_nom, $this->nom);
148
		$url = $this->urls->obtenirUrlFiche($id, $this->type_nom, $this->nom);
102
		$this->redirigerVers($url);
149
		$this->redirigerVers($url);
103
	}
150
	}
104
	
151
	
105
	private function rechercherNomApproche($noms) {
152
	private function rechercherNomApproche($noms) {
106
		$approche = '';
153
		$approche = '';
107
		$res = $noms->getRechercheFloue($this->nom);
154
		$res = $noms->getRechercheFloue($this->nom);
108
		if (!($res == false || $res['entete']['total'] == 0)) {
155
		if (!($res == false || $res['entete']['total'] == 0)) {
109
			for ($i = 0; $i < 3; $i++) {
156
			for ($i = 0; $i < 3; $i++) {
110
				$nom_proche = array_shift($res['resultat']);
157
				$nom_proche = array_shift($res['resultat']);
111
				$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
158
				$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
112
				$approche[$i]['url_nom_approche'] = $this->urls->obtenirUrlRechercheSimple($approche[$i]['nom'], $this->type_nom);
159
				$approche[$i]['url_nom_approche'] = $this->urls->obtenirUrlRechercheSimple($approche[$i]['nom'], $this->type_nom);
113
			}
160
			}
114
		}
161
		}
115
		return $approche;
162
		return $approche;
116
	}
163
	}
-
 
164
	
117
	
165
	//+-----------------------------------------------méthodes utiles---------------------------------+
118
	
166
	
119
	private function capturerParametres() {
167
	private function capturerParametres() {
120
		if (isset($_REQUEST['nom'])) {
168
		if (isset($_REQUEST['nom'])) {
121
			$this->nom = $_REQUEST['nom'];
169
			$this->nom = $_REQUEST['nom'];
122
		}
170
		}
123
		if (isset($_GET['type_nom'])) {
171
		if (isset($_GET['type_nom'])) {
124
			$this->type_nom = $_GET['type_nom'];
172
			$this->type_nom = $_GET['type_nom'];
125
		}
173
		}
126
		
-
 
127
		if (isset($_GET['submit'])) {
174
		if (isset($_GET['submit'])) {
128
			$this->submit = urldecode($_GET['submit']);
175
			$this->submit = urldecode($_GET['submit']);
129
		}
176
		}
130
		
-
 
131
		if (isset($_GET['niveau'])) {
177
		if (isset($_GET['niveau'])) {
132
			Registre::set('parametres.niveau', $_GET['niveau']);
178
			Registre::set('parametres.niveau', $_GET['niveau']);
133
		}
179
		}
134
		
-
 
135
		if (isset($_GET['resultat'])) {
180
		if (isset($_GET['resultat'])) {
136
			$this->type_resultat = urldecode($_GET['resultat']);
181
			$this->type_resultat = urldecode($_GET['resultat']);
137
		} else {
182
		} else {
138
			$onglet_resultat = $this->recupererTableauConfig('affich_resultats');
183
			$onglet_resultat = $this->recupererTableauConfig('affich_resultats');
139
			$this->type_resultat = $onglet_resultat[Registre::get('parametres.niveau').'_'.$this->type_nom];
184
			$this->type_resultat = $onglet_resultat[Registre::get('parametres.niveau').'_'.$this->type_nom];
140
		}
185
		}
-
 
186
	}
-
 
187
	
-
 
188
	private function capturerParametresAvances() {
-
 
189
		if (isset($_GET['gen']) && $_GET['gen'] != '') {
-
 
190
			$this->param['gen'] = urldecode($_GET['gen']);
-
 
191
		}
-
 
192
		if (isset($_GET['fam']) && $_GET['fam'] != '') {
-
 
193
			$this->param['fam'] = urldecode($_GET['fam']);
-
 
194
		}
-
 
195
		if (isset($_GET['au']) && $_GET['au'] != '' 
-
 
196
			&& $_GET['au'] != urlencode($this->i18n['valeur-form-auteur'])) {
-
 
197
			$this->param['au'] = urldecode($_GET['au']);
-
 
198
		}
-
 
199
		if (isset($_GET['bib']) && $_GET['bib'] != ''
-
 
200
			&& $_GET['bib'] != urlencode($this->i18n['valeur-form-bib'])) {
-
 
201
			$this->param['bib'] = urldecode($_GET['bib']);
-
 
202
		}
-
 
203
		if (isset($_GET['nn']) && $_GET['nn'] != '') {
-
 
204
			$this->param['nn'] = urldecode($_GET['nn']);
-
 
205
		}
-
 
206
		if (isset($_GET['nt']) && $_GET['nt'] != '') {
-
 
207
			$this->param['nt'] = urldecode($_GET['nt']);
-
 
208
		}
-
 
209
		if (isset($_GET['sp']) && $_GET['sp'] != '') {
-
 
210
			$this->param['sp'] = urldecode($_GET['sp']);
-
 
211
		}
-
 
212
		if (isset($_GET['ssp']) && $_GET['ssp'] != '') {
-
 
213
			$this->param['ssp'] = urldecode($_GET['ssp']);
-
 
214
		}
-
 
215
		if (isset($_GET['type']) && $_GET['type'] != '') {
-
 
216
			$this->param['type'] = urldecode($_GET['type']);
-
 
217
		}
-
 
218
		if (isset($_GET['and']) && $_GET['and'] != ''
-
 
219
			&& $_GET['and'] != urlencode($this->i18n['valeur-form-date'])) {
-
 
220
			$this->param['and'] = urldecode($_GET['and']);
-
 
221
		}
-
 
222
		if (isset($_GET['anf']) && $_GET['anf'] != ''
-
 
223
			&& $_GET['anf'] != urlencode($this->i18n['valeur-form-date'])) {
-
 
224
			$this->param['anf'] = urldecode($_GET['anf']);
-
 
225
		}
-
 
226
		if (isset($_GET['prga']) && $_GET['prga'] != '') {
-
 
227
			$this->param['prga'] = urldecode($_GET['prga']);
-
 
228
		}
-
 
229
		if (isset($_GET['prco']) && $_GET['prco'] != '') {
-
 
230
			$this->param['prco'] = urldecode($_GET['prco']);
-
 
231
		}
-
 
232
		if (isset($_GET['sto']) && $_GET['sto'] != '') {
-
 
233
			$this->param['sto'] = urldecode($_GET['sto']);
-
 
234
		}
-
 
235
		if (isset($_GET['sti']) && $_GET['sti'] != '') {
-
 
236
			$this->param['sti'] = urldecode($_GET['sti']);
-
 
237
		}
-
 
238
		if (isset($_GET['stc']) && $_GET['stc'] != '') {
-
 
239
			$this->param['stc'] = urldecode($_GET['stc']);
-
 
240
		}
141
	}
241
	}
142
	
242
	
143
	protected function recupererTableauConfig($param) {
243
	protected function recupererTableauConfig($param) {
144
		$tableau = array();
244
		$tableau = array();
145
		$tableauPartiel = explode(',', Config::get($param));
245
		$tableauPartiel = explode(',', Config::get($param));
146
		$tableauPartiel = array_map('trim', $tableauPartiel);
246
		$tableauPartiel = array_map('trim', $tableauPartiel);
147
		foreach ($tableauPartiel as $champ) {
247
		foreach ($tableauPartiel as $champ) {
148
			if (strpos($champ, '=') === false) {
248
			if (strpos($champ, '=') === false) {
149
				$tableau[] = $champ;
249
				$tableau[] = $champ;
150
			} else {
250
			} else {
151
				list($cle, $val) = explode('=', $champ);
251
				list($cle, $val) = explode('=', $champ);
152
				$tableau[$cle] = $val;
252
				$tableau[$cle] = $val;
153
			}
253
			}
154
		}
254
		}
155
		return $tableau;
255
		return $tableau;
156
	}
256
	}
157
	
257
	
158
}
258
}
159
?>
259
?>