Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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