Rev 798 | Rev 1002 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class AlphabVernaFormateur implements Formateur {
const TPL_VUE = 'liste_noms_verna';
private $parametres = null;
private $surligneur = null;
private $trieur = null;
private $urls = null;
private $fusioneur = null;
private $manipulateurDeChaine = null;
private $imagesService = null;
private $motsASurligner = array();
private $noms = array();
private $infosPourTpl = array();
public function __construct(ParametresResultats $parametres, Array $resultats,
Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
$this->parametres = $parametres;
$this->noms = $resultats['resultat'];
$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
}
public function getTplInfos() {
return $this->infosPourTpl;
}
public function getTplNom() {
return self::TPL_VUE;
}
private function supprimerCodeReftaxAvecNn($nn) {
$codeReftax = $this->parametres->reftaxCourant.'.nn:';
return str_replace($codeReftax, '', $nn);
}
private function renvoyerInfoVerna($nn, $valeurs) {
$infosDuNom = array();
$infosDuNom['nomSci'] = $valeurs['taxon'];
$infosDuNom['nomVerna'] = $valeurs['nom_vernaculaire'];
$infosDuNom['langue'] = $valeurs['code_langue'];
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
return $infosDuNom ;
}
function supprimerAccents($chaine){
return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
'ç' => 'c',
'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
'ñ' => 'n',
'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o',
'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u',
'ý' => 'y', 'ÿ' => 'y'));
}
public function formater() {
$nomVerna = array();
foreach ($this->noms as $id => $nom) {
$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
$nom_min = strtolower($nom['nom_vernaculaire']);
$nom_ss_accent = $this->supprimerAccents($nom_min);
if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', $nom_ss_accent)) {
$nomVerna[0][$id] = $this->renvoyerInfoVerna($nn, $nom);
} else {
$nomVerna[1][$id] = $this->renvoyerInfoVerna($nn, $nom);
}
}
ksort($nomVerna);
$this->infosPourTpl['noms'] = isset($nomVerna) ? $nomVerna : false;
}
public function trier() {
$verna = array();
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
$verna += $this->classerAlphabetiquement('nomVerna', $valeurs);
}
$this->infosPourTpl['noms'] = $verna;
}
private function classerAlphabetiquement($champs, $valeurs) {
$this->trieur->setTableau($valeurs);
$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
return $this->trieur->trier();
}
public function surligner() {
$this->definirMotsASurligner();
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
$this->infosPourTpl['noms'][$idNom]['nomVerna'] = $this->surlignerMotsMasqueRecherche($nom['nomVerna']);
}
}
private function definirMotsASurligner() {
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
}
private function surlignerMotsMasqueRecherche($nom) {
$this->surligneur->setTexte($nom);
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
return $nom;
}
}
?>