Rev 720 | Blame | Last modification | View Log | RSS feed
<?phpclass Recherche extends aControleur {//+----------------------------------------------------------------------------------------------------------------+// Méthodesprotected $nom = null;protected $type_nom = 'nom_scientifique';protected $type_resultat = '';protected $submit = '';private $recherche_avancee;private $param;private $i18n = array();public function initialiser() {$this->capturerParametres();$this->capturerParametresAvances();$this->i18n = I18n::get('Recherche-form-avancee');}/*** Fonction d'affichage par défaut*/public function executerActionParDefaut() {$this->executerAccueil();}public function executerAccueil($donneesMoteur = array()) {$niveau = new Niveau();$donnees['form_niveau'] = $niveau->afficherNiveau();$recherchesimple = new RechercheSimple();$donnees['form_nom'] = $recherchesimple->executerFormulaireNom($donneesMoteur);if (Registre::get('parametres.niveau') != 1) {$recherche_avancee = new RechercheAvancee();$donnees['form_recherche_av'] = $recherche_avancee->executerFormulaireRechercheAv($donneesMoteur);}$this->afficherAccueil($donnees);}private function afficherAccueil($donnees) {$donnees['i18n'] = I18n::get('Recherche-accueil');$this->setSortie(self::RENDU_CORPS, $this->getVue('recherche_accueil', $donnees), true);}//+---------------------------------------------recherche avancee-------------------------------------+public function executerRechercheAvancee() {$donnees['param'] = $this->param;$presence = $this->rechercherCriteresDemandes();if (empty($presence) && !empty($this->param)) {$donnees['message_av']['attention'] = 'info_res_vide';}$this->executerAccueil($donnees);if (Registre::get('resultats')) {$_GET['resultat'] = $this->type_resultat;$this->executerAction('Resultat', 'executerResultat');}}public function rechercherCriteresDemandes() {$noms = new Noms(Registre::get('parametres.referentiel'));$res = $noms->getRechercheAvancee($this->param);if ($res != false || $res['entete']['total'] != 0) {if ($res['entete']['total'] == 1 ) {$ids = array_keys($res['resultat']);$nom = $res['resultat'][$ids[0]]['nom_sci'];$url = $this->urls->obtenirUrlFiche($ids[0], 'nom_scientifique', $nom);$this->redirigerVers($url);} else {$res['type'] = $this->type_nom;Registre::set('resultats', $res);}} else {$res = '';}return $res;}//+---------------------------------------------recherche simple-------------------------------------+public function executerRechercheSimple() {$donnees['type_nom'] = $this->type_nom;$donnees['nom'] = $this->nom;if (strlen($donnees['nom']) < 3) {$donnees['message']['attention'] = 'info_nb_lettres';} else {$presence = $this->rechercherNom();if ($presence == '') { // s'il n'y a pas de nom$donnees['message']['attention'] = 'info_sp_abs';} elseif ($presence == 'sans_correspondance') {$res = Registre::get('resultats');$id = array_keys($res['resultat']);$donnees['message']['nom_ss_corresp']['id'] = $id[0];$nom = array_shift($res['resultat']);$donnees['message']['nom_ss_corresp']['nom'] = $nom['nom_sci'];} elseif ($presence != 'ok') { // s'il y a des noms approchésif (!Registre::get('resultats')) { // s'il n'y a aucun nom exact$donnees['message']['attention'] = 'info_sp_abs';}$donnees['message']['nom_approche'] = $presence;}}$this->executerAccueil($donnees);if (Registre::get('resultats')) {$_GET['resultat'] = $this->type_resultat;$this->executerAction('Resultat', 'executerResultat');}}// regarde si il y a des résultats correspondant au nom recherché sinon recherche un nom approché// $noms classe métier nom ou nomprivate function rechercherNom() {$noms = ($this->type_nom == 'nom_vernaculaire')? new NomsVernaculaires(Config::get(Registre::get('parametres.referentiel').'.referentielVerna')): new Noms(Registre::get('parametres.referentiel'));$approche = '';$res = $noms->getRechercheEtendue($this->nom, $this->type_resultat);$form = I18n::get('Recherche-form-nom');if ($res == false || $res['entete']['total'] == 0) { // recherche nom approché$approche = $this->rechercherNomApproche($noms);} elseif ($res['entete']['total'] == 1 || $this->submit == $form['fiche']) { // renvoie à la fiche$approche = $this->traiterAccesFiche($res);} else { // affiche les résultats$res['type'] = $this->type_nom;Registre::set('resultats', $res);$approche = 'ok';if ($res['entete']['total'] < 3) { // si moins de 16 noms affiche en plus un nom approché$approche = $this->rechercherNomApproche($noms);}}return $approche;}private function traiterAccesFiche($res) {$ids = array_keys($res['resultat']);if ($this->type_nom == 'nom_vernaculaire') {$id = explode(':',$res['resultat'][$ids[0]]['nom_retenu.code']);$id = $id[1];} else {if ($res['resultat'][$ids[0]]['retenu'] == 'absent') { // dans le cas d'un nom sans correspondance$res['type'] = $this->type_nom;Registre::set('resultats', $res);$approche = 'sans_correspondance';return $approche;} else {$id = $ids[0];}}$url = $this->urls->obtenirUrlFiche($id, $this->type_nom, $this->nom);$this->redirigerVers($url);}private function rechercherNomApproche($noms) {$approche = '';$res = $noms->getRechercheFloue($this->nom);if (!($res == false || $res['entete']['total'] == 0)) {for ($i = 0; $i < 3; $i++) {$nom_proche = array_shift($res['resultat']);$approche[$i]['nom'] = ($this->type_nom == 'nom_vernaculaire') ? $nom_proche['nom'] : $nom_proche['nom_sci'];$approche[$i]['url_nom_approche'] = $this->urls->obtenirUrlRechercheSimple($approche[$i]['nom'], $this->type_nom);}}return $approche;}//+-----------------------------------------------méthodes utiles---------------------------------+private function capturerParametres() {if (isset($_REQUEST['nom'])) {$this->nom = $_REQUEST['nom'];}if (isset($_GET['type_nom'])) {$this->type_nom = $_GET['type_nom'];}if (isset($_GET['submit'])) {$this->submit = urldecode($_GET['submit']);}if (isset($_GET['niveau'])) {Registre::set('parametres.niveau', $_GET['niveau']);}if (isset($_GET['resultat'])) {$this->type_resultat = urldecode($_GET['resultat']);} else {$onglet_resultat = $this->recupererTableauConfig('affich_resultats');$this->type_resultat = $onglet_resultat[Registre::get('parametres.niveau').'_'.$this->type_nom];}}private function capturerParametresAvances() {if (isset($_GET['gen']) && $_GET['gen'] != '') {$this->param['gen'] = urldecode($_GET['gen']);}if (isset($_GET['fam']) && $_GET['fam'] != '') {$this->param['fam'] = urldecode($_GET['fam']);}if (isset($_GET['au']) && $_GET['au'] != ''&& $_GET['au'] != urlencode($this->i18n['valeur-form-auteur'])) {$this->param['au'] = urldecode($_GET['au']);}if (isset($_GET['bib']) && $_GET['bib'] != ''&& $_GET['bib'] != urlencode($this->i18n['valeur-form-bib'])) {$this->param['bib'] = urldecode($_GET['bib']);}if (isset($_GET['nn']) && $_GET['nn'] != '') {$this->param['nn'] = urldecode($_GET['nn']);}if (isset($_GET['nt']) && $_GET['nt'] != '') {$this->param['nt'] = urldecode($_GET['nt']);}if (isset($_GET['sp']) && $_GET['sp'] != '') {$this->param['sp'] = urldecode($_GET['sp']);}if (isset($_GET['ssp']) && $_GET['ssp'] != '') {$this->param['ssp'] = urldecode($_GET['ssp']);}if (isset($_GET['type']) && $_GET['type'] != '') {$this->param['type'] = urldecode($_GET['type']);}if (isset($_GET['and']) && $_GET['and'] != ''&& $_GET['and'] != urlencode($this->i18n['valeur-form-date'])) {$this->param['and'] = urldecode($_GET['and']);}if (isset($_GET['anf']) && $_GET['anf'] != ''&& $_GET['anf'] != urlencode($this->i18n['valeur-form-date'])) {$this->param['anf'] = urldecode($_GET['anf']);}if (isset($_GET['prga']) && $_GET['prga'] != '') {$this->param['prga'] = urldecode($_GET['prga']);}if (isset($_GET['prco']) && $_GET['prco'] != '') {$this->param['prco'] = urldecode($_GET['prco']);}if (isset($_GET['sto']) && $_GET['sto'] != '') {$this->param['sto'] = urldecode($_GET['sto']);}if (isset($_GET['sti']) && $_GET['sti'] != '') {$this->param['sti'] = urldecode($_GET['sti']);}if (isset($_GET['stc']) && $_GET['stc'] != '') {$this->param['stc'] = urldecode($_GET['stc']);}}protected function recupererTableauConfig($param) {$tableau = array();$tableauPartiel = explode(',', Config::get($param));$tableauPartiel = array_map('trim', $tableauPartiel);foreach ($tableauPartiel as $champ) {if (strpos($champ, '=') === false) {$tableau[] = $champ;} else {list($cle, $val) = explode('=', $champ);$tableau[$cle] = $val;}}return $tableau;}}?>