Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev Author Line No. Line
33 jpm 1
<?php
2
class RechercheSimple extends aControleur {
3
 
4
	//+----------------------------------------------------------------------------------------------------------------+
5
	// Méthodes
6
	/**
7
	 * Fonction d'affichage par défaut
8
	 */
53 delphine 9
 
10
 
33 jpm 11
	public function executerActionParDefaut() {
12
		$this->executerAccueil();
13
	}
14
 
15
	public function executerAccueil() {
16
		$donnees = array();
57 delphine 17
		$donnees['form_nom'] = $this->executerFormulaireNom();
18
		$this->afficherAccueil($donnees);
19
	}
20
 
21
	private function afficherAccueil($donnees) {
33 jpm 22
		$donnees['i18n'] = I18n::get('Recherche-accueil');
23
 
24
		$this->setSortie(self::RENDU_CORPS, $this->getVue('recherche_accueil', $donnees));
25
	}
26
 
57 delphine 27
	public function executerFormulaireNom($donnees = array()) {
28
		if (!isset($donnees['type_nom'])) {
29
			$donnees['type_nom'] = (Registre::get('parametres.niveau') == 1) ? 'nom_vernaculaire' : 'nom_scientifique';
30
		}
33 jpm 31
		$donnees['i18n'] = I18n::get('Recherche-form-nom');
32
 
33
		return $this->getVue('form_nom', $donnees);
34
	}
35
 
43 delphine 36
	public function executerRechercheNom() {
57 delphine 37
		$donnees['type_nom'] = $_GET['type_nom'];
38
		$donnees['nom'] = $_GET['nom']; echo $donnees['nom'];
39
		if (strlen($donnees['nom']) < 3) {
43 delphine 40
			$donnees['information'] = 'Veuillez saisir un radical contenant au moins 3 caractères alphabétiques !';
41
		} else {
57 delphine 42
			$noms = ($donnees['type_nom'] == 'nom_vernaculaire')
54 delphine 43
				? new NomsVernaculaires(Config::get('referentielVerna'))
44
				: new Noms(Registre::get('parametres.referentiel'));
45
			$presence = $this->rechercherNom($noms);
46
			if ($presence == '') {
47
				$donnees['information'] = 'Nom inconnu';
48
			} elseif ($presence != 'ok') {
49
				$donnees['nom_approche'] = $presence;
57 delphine 50
				Debug::printr(Registre::get('eflore.urlCourrante')->getUrl()); // revoir à partir de appcontroleur
51
				//$donnees['url_nom_approche'] = str_replace($donnees['nom'], $donnees['nom_approche'], Registre::get('eflore.urlCourrante'));
54 delphine 52
			}
43 delphine 53
		}
54 delphine 54
 
57 delphine 55
		$donnees['form_nom'] = $this->executerFormulaireNom($donnees);
56
		$this->afficherAccueil($donnees);
33 jpm 57
	}
53 delphine 58
 
57 delphine 59
	// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché
54 delphine 60
	private function rechercherNom($noms) {
61
		$approche = '';
57 delphine 62
		$res = $noms->getRechercheEtendue($_GET['nom']);
63
		if ($res == false || $res['entete']['total'] == 0) {
64
			$res = $noms->getRechercheFloue($_GET['nom']);
65
			if (!($res == false || $res['entete']['total'] == 0)) {
66
				$nom_proche = array_shift($res['resultat']);
67
				$approche = ($_GET['type_nom'] == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];
53 delphine 68
			}
57 delphine 69
		} elseif ($res['entete']['total'] == 1) {
70
			$approche = 'ok'; // envoyer à la fiche
54 delphine 71
		} else {
72
			$approche = 'ok';
53 delphine 73
		}
54 delphine 74
		return $approche;
53 delphine 75
	}
54 delphine 76
 
33 jpm 77
}
78
?>