Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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