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