Subversion Repositories eFlore/Applications.eflore-consultation

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 245

/trunk/modules/recherche/Recherche.php
New file
0,0 → 1,136
<?php
class Recherche extends aControleur {
//+----------------------------------------------------------------------------------------------------------------+
// Méthodes
protected $nom = null;
protected $type_nom = 'nom_scientifique';
protected $type_resultat = '';
protected $submit = '';
public function initialiser() {
$this->capturerParametres();
}
/**
* 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);
$this->afficherAccueil($donnees);
}
private function afficherAccueil($donnees) {
$donnees['i18n'] = I18n::get('Recherche-accueil');
$this->setSortie(self::RENDU_CORPS, $this->getVue('recherche_accueil', $donnees), true);
}
 
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 != 'ok') { // s'il y a des noms approchés
if (!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 nom
private 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
$ids = array_keys($res['resultat']);
$url = $this->urls->obtenirUrlFiche($ids[0], $this->type_nom, $this->nom, $res['resultat'][$ids[0]][nom_sci]);
$this->redirigerVers($url);
} 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 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;
}
private function capturerParametres() {
if (isset($_GET['nom'])) {
$this->nom = $_GET['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];
}
}
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;
}
}
?>