Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 74 Rev 76
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
	/**
6
	/**
7
	 * Fonction d'affichage par défaut
7
	 * Fonction d'affichage par défaut
8
	 */
8
	 */
9
	public function executerActionParDefaut() {
9
	public function executerActionParDefaut() {
10
		$rechercheAccueil = $this->executerAction('recherche-simple', 'accueil');
10
		$this->executerAction('RechercheSimple', 'executerAccueil');
11
		$this->setSortie(self::RENDU_CORPS, $rechercheAccueil);
-
 
-
 
11
		
12
	}
12
	}
13
 
13
 
14
	public function executerRechercheSimple() {
14
	public function executerRechercheSimple() {
15
		$donnees['type_nom'] = $_GET['type_nom'];
15
		$donnees['type_nom'] = $_GET['type_nom'];
16
		$donnees['nom'] = $_GET['nom'];
16
		$donnees['nom'] = $_GET['nom'];
17
		if (strlen($donnees['nom']) < 3) {
17
		if (strlen($donnees['nom']) < 3) {
18
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
18
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
19
		} else {
19
		} else {
20
			$noms = ($donnees['type_nom'] == 'nom_vernaculaire') 
20
			$noms = ($donnees['type_nom'] == 'nom_vernaculaire') 
21
				? new NomsVernaculaires(Config::get('referentielVerna')) 
21
				? new NomsVernaculaires(Config::get('referentielVerna')) 
22
				: new Noms(Registre::get('parametres.referentiel'));
22
				: new Noms(Registre::get('parametres.referentiel'));
23
			$presence = $this->rechercherNom($noms);
23
			$presence = $this->rechercherNom($noms);
24
			if ($presence == '') {
24
			if ($presence == '') {
25
				$donnees['information'] = 'Nom inconnu';
25
				$donnees['information'] = 'Nom inconnu';
26
			} elseif ($presence != 'ok') {
26
			} elseif ($presence != 'ok') {
27
				$donnees['nom_approche'] = $presence;
27
				$donnees['nom_approche'] = $presence;
28
				$donnees['url_nom_approche'] = $this->obtenirUrlRechercheSimple($presence, $donnees['type_nom']);
28
				$donnees['url_nom_approche'] = $this->obtenirUrlRechercheSimple($presence, $donnees['type_nom']);
29
			}
29
			}
30
		}
30
		}
31
		Registre::set('donnees', $donnees);
31
		Registre::set('donneesMoteur', $donnees);
32
		$this->executerAction('recherche_simple', 'executerForm');
32
		$this->executerAction('RechercheSimple', 'executerForm');
-
 
33
		if ($presence == 'ok') {
-
 
34
			$this->executerAction('Resultat', 'executerResultat');
-
 
35
		}
33
	}
36
	}
34
	
37
	
35
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
38
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
36
	private function rechercherNom($noms) {
39
	private function rechercherNom($noms) {
37
		$approche = '';
40
		$approche = '';
38
		$res = $noms->getRechercheEtendue($_GET['nom']);
41
		$res = $noms->getRechercheEtendue($_GET['nom']);
39
		$form = I18n::get('Recherche-form-nom');
42
		$form = I18n::get('Recherche-form-nom');
40
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
43
		if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché
41
			$res = $noms->getRechercheFloue($_GET['nom']);
44
			$res = $noms->getRechercheFloue($_GET['nom']);
42
			if (!($res == false || $res['entete']['total'] == 0)) {
45
			if (!($res == false || $res['entete']['total'] == 0)) {
43
				$nom_proche = array_shift($res['resultat']);
46
				$nom_proche = array_shift($res['resultat']);
44
				$approche = ($_GET['type_nom'] == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
47
				$approche = ($_GET['type_nom'] == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
45
			}
48
			}
46
		} elseif ($res['entete']['total'] == 1 || urldecode($_GET['submit']) == $form['fiche']) { // renvoie à la fiche
49
		} elseif ($res['entete']['total'] == 1 || urldecode($_GET['submit']) == $form['fiche']) { // renvoie à la fiche
47
			$ids = array_keys($res['resultat']);
50
			$ids = array_keys($res['resultat']);
48
			$url = $this->obtenirUrlFiche($ids[0]);
51
			$url = $this->obtenirUrlFiche($ids[0]);
49
			$this->redirigerVers($url);
52
			$this->redirigerVers($url);
50
		} else { // affiche les résultats
53
		} else { // affiche les résultats
-
 
54
			Registre::set('resultats', $res);
51
			$approche = 'ok';
55
			$approche = 'ok';
52
		}
56
		}
53
		return $approche;
57
		return $approche;
54
	}
58
	}
55
	
59
	
56
}
60
}
57
?>
61
?>