/branches/v5.7-duchartre/modules/resultat/formateurs/nom_vernaculaire/DeterminationVernaFormateur.php |
---|
New file |
0,0 → 1,229 |
<?php |
class DeterminationVernaFormateur implements Formateur { |
const TPL_VUE = 'determination_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(); |
private $conteneur = null; |
private $apiCartes = null; |
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; |
$this->conteneur = new Conteneur(); |
$this->apiCartes = $this->conteneur->getApiCartes(); |
} |
public function getTplInfos() { |
return $this->infosPourTpl; |
} |
public function getTplNom() { |
return self::TPL_VUE; |
} |
public function formater() { |
$this->obtenirUrlsDessins(); |
$this->obtenirUrlsPhotos(); |
$this->chargerRepartition(); |
$this->extraireInfosNomsPourTplDetermination(); |
$this->infosPourTpl['urlWidget'] = Config::get('base_url_widget_saisie')."?referentiel=".Registre::get('parametres.referentiel'); |
} |
private function obtenirUrlsDessins() { |
if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") { |
$this->extraireInfosTaxons(); |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins')); |
$tax = implode(',', $this->infosPourTpl['taxons']); |
$this->imagesService->setNnTaxon($tax); |
$costeImg = $this->imagesService->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons(); |
if (!empty($costeImg)) { |
foreach ($costeImg as $infos) { |
$num_taxon = $infos['num_taxonomique']; |
$images[$num_taxon][] = $infos['binaire.href']; |
$this->infosPourTpl['imagesCoste'] = $images; |
} |
} |
} |
} |
private function extraireInfosTaxons() { |
foreach ($this->noms as $id => $nom ) { |
if (array_key_exists('num_taxon', $nom) |
&& array_key_exists('taxon', $nom)) { |
$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon']; |
} |
} |
} |
private function obtenirUrlsPhotos() { |
if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") { |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages')); |
$nns = $this->extraireNnDesNoms(); |
$urls = $this->imagesService->setApi(Eflore::API_EFLORE)->getUrlsImagesParIdsNoms($nns); |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesUrls($urls); |
} |
} |
private function extraireNnDesNoms() { |
$nns = array(); |
foreach ($this->noms as $id => $nom) { |
if (array_key_exists('nom_retenu.code', $nom)) { |
if (in_array($nom['nom_retenu.code'], $nns) == false) { |
$idAAjouter = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']); |
if (is_numeric($idAAjouter)) { |
$nns[] = $idAAjouter; |
} |
} |
} |
} |
return $nns; |
} |
private function supprimerCodeReferentielDesUrls($urls) { |
$urlsNettoyees = array(); |
foreach ($urls as $id => $url) { |
$id = $this->supprimerCodeReferentiel($id); |
$urlsNettoyees[$id] = $url; |
} |
return $urlsNettoyees; |
} |
private function supprimerCodeReferentiel($chaine) { |
$codeReferentiel = $this->parametres->referentielCourant.'.'; |
$chaine = str_replace($codeReferentiel, '', $chaine); |
return $chaine; |
} |
private function chargerRepartition() { |
// $numsNomsASynonymes = $this->extraireNumerosNomSynonymes(); |
if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') == "") { |
return; |
} |
$this->apiCartes->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition')); |
$this->apiCartes->setLargeur('108x101'); |
$urls = array(); |
foreach ($this->noms as $nom) { |
if (array_key_exists('nom_retenu.code', $nom)) { |
$id = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']); |
$this->apiCartes->setId("nn:" . $id); // . ',' . implode(',', array_keys($numsNomsASynonymes[$id]))); |
if (array_key_exists($id, $urls) == false) { |
$urls[$id] = $this->apiCartes->getUrlPng(); |
} |
} |
} |
$this->infosPourTpl['repartition']['urls'] = $urls; |
} |
private function extraireNumerosNomSynonymes() { |
$numNomsASynonyme = array(); |
foreach ($this->noms as $id => $nom) { |
$num_nom_retenu = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']); |
// faux |
$numNomsASynonyme[$num_nom_retenu][$id] = TRUE; |
} |
return $numNomsASynonyme; |
} |
private function extraireInfosNomsPourTplDetermination() { |
$taxons = array(); |
foreach ($this->noms as $idNomCourant => $nom) { |
$nn = intval($this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code'])); |
$nomV = iconv('UTF-8', 'ASCII//TRANSLIT', strtolower($nom['nom_vernaculaire'])); |
if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).'(?: |$)/', $nomV)) { |
// au moins un debute par la requête |
if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) { |
$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn); |
} |
$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom); |
} else { |
// contient |
if (isset($taxons) && (!isset($taxons[1]) || array_key_exists($nn, $taxons[1]) == false)) { |
$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn); |
} |
$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom); |
} |
} |
$this->infosPourTpl['noms'] = isset($taxons) ? $taxons : false; |
} |
private function renvoyerInfosNomVerna($valeurs) { |
$nom_verna = array(); |
$nom_verna['nn'] = $valeurs['id']; |
$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire']; |
return $nom_verna; |
} |
private function renvoyerInfosTaxon($nomSci, $nn) { |
$taxon = array(); |
$taxon['nomSci'] = $nomSci; |
$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche); |
$this->chargerRepartition($nn); |
$taxon['repartition_vignette'] = $this->infosPourTpl['repartition']['urls']; |
return $taxon; |
} |
private function supprimerCodeReferentielAvecNn($nn) { |
return str_replace($this->parametres->referentielCourant.'.nn:', '', $nn); |
} |
//tri alphabétique des noms scientifiques par catégorie (débute par , contient ) |
public function trier() { |
$verna = array(); |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) { |
$verna += $this->classerAlphabetiquement('nomSci', $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) { |
foreach ($nom['nomVerna'] as $idVerna => $nomVerna) { |
$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']); |
} |
$this->infosPourTpl['noms'][$idNom] = $nom; |
} |
} |
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; |
} |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/nom_vernaculaire/AlphabVernaFormateur.php |
---|
New file |
0,0 → 1,113 |
<?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 = Registre::get('parametres.referentiel').'.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; |
} |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/Formateur.php |
---|
New file |
0,0 → 1,10 |
<?php |
interface Formateur { |
public function __construct(ParametresResultats $parametres, Array $resultats, Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null); |
public function getTplInfos(); |
public function getTplNom(); |
public function formater(); |
public function trier(); |
public function surligner(); |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/ResultatFormateurFabrique.php |
---|
New file |
0,0 → 1,16 |
<?php |
class ResultatFormateurFabrique { |
public static function creer(ParametresResultats $parametres, Array $resultats){ |
$typeResultat = ucwords($parametres->typeResultat); |
$typeNom = ($parametres->typeNom == 'nom_vernaculaire') ? 'Verna' : ''; |
$Classe = $typeResultat.$typeNom.'Formateur'; |
$ResultatFormateur = null; |
if (class_exists($Classe)) { |
return new $Classe($parametres, $resultats); |
} else { |
throw new Exception("La classe '$Classe' est introuvable."); |
} |
} |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/nom_scientifique/DeterminationFormateur.php |
---|
New file |
0,0 → 1,274 |
<?php |
class DeterminationFormateur implements Formateur { |
const TPL_VUE = 'determination'; |
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; |
} |
public function formater() { |
$this->obtenirUrlsDessins(); |
$this->obtenirUrlsPhotos(); |
$this->chargerRepartition(); |
$this->extraireInfosNomsPourTplDetermination(); |
$this->infosPourTpl['urlWidget'] = Config::get('base_url_widget_saisie')."?referentiel=".Registre::get('parametres.referentiel'); |
} |
private function obtenirUrlsDessins() { |
if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") { |
$this->extraireInfosTaxons(); |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins')); |
$tax = implode(',', $this->infosPourTpl['taxons']); |
$this->imagesService->setNnTaxon($tax); |
$costeImg = $this->imagesService->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons(); |
if (!empty($costeImg)) { |
foreach ($costeImg as $infos) { |
$num_taxon = $infos['num_taxonomique']; |
$images[$num_taxon][] = $infos['binaire.href']; |
$this->infosPourTpl['dessins'] = $images; |
} |
} |
} |
} |
private function extraireInfosTaxons() { |
foreach ($this->noms as $id => $nom ) { |
if (array_key_exists('num_taxonomique', $nom)) { |
$this->infosPourTpl['taxons'][$id] = $nom['num_taxonomique']; |
} |
} |
} |
private function obtenirUrlsPhotos() { |
if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") { |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages')); |
$ids = $this->extraireIdDesNoms(); |
$urls = $this->imagesService->setApi(Eflore::API_EFLORE)->getUrlsImagesParIdsNoms($ids); |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesIds($urls); |
} |
} |
private function extraireIdDesNoms() { |
$ids = array(); |
foreach ($this->noms as $id => $nom) { |
$idAAjouter = $id; |
if (is_numeric($idAAjouter)) { |
$ids[] = $idAAjouter; |
} |
if (array_key_exists('nom_retenu.id', $nom)) { |
if (in_array($nom['nom_retenu.id'], $ids) == false) { |
$idAAjouter = $nom['nom_retenu.id']; |
if (is_numeric($idAAjouter)) { |
$ids[] = $idAAjouter; |
} |
} |
} |
} |
return $ids; |
} |
private function extraireNumerosNomSynonymes() { |
$numNomsASynonyme = array(); |
foreach ($this->noms as $id => $nom) { |
// certains taxons requêtés via /bdtfx/noms?masque= n'ont pas de num_tax ni de num_nom_retenu |
if(!isset($nom['nom_retenu.id'])) continue; |
$num_nom_retenu = $nom['nom_retenu.id']; |
if(!isset($numNomsASynonyme[$num_nom_retenu])) { |
$numNomsASynonyme[$num_nom_retenu] = array(); |
} |
$numNomsASynonyme[$num_nom_retenu][] = $id; |
if($num_nom_retenu != $id) { |
$numNomsASynonyme[$id] = $numNomsASynonyme[$num_nom_retenu]; |
} |
} |
return $numNomsASynonyme; |
} |
private function supprimerCodeReferentielDesIds($urls) { |
$urlsNettoyees = array(); |
foreach ($urls as $id => $url) { |
$id = $this->supprimerCodeReferentiel($id); |
$urlsNettoyees[$id] = $url; |
} |
return $urlsNettoyees; |
} |
private function supprimerCodeReferentiel($chaine) { |
$codeReferentiel = Registre::get('parametres.referentiel').'.'; |
$chaine = str_replace($codeReferentiel, '', $chaine); |
return $chaine; |
} |
// TODO : utiliser le conteneur pour charger tous les objets de cette classe |
private function chargerRepartition() { |
if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') != "") { |
$conteneur = new Conteneur(); |
$cartesWs = $conteneur->getApiCartes(); |
$cartesWs->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition')); |
$cartesWs->setLargeur('108x101'); |
$urls = array(); |
$numsNomsASynonymes = $this->extraireNumerosNomSynonymes(); |
foreach ($this->noms as $id => $nom) { |
if (array_key_exists('nom_retenu.id', $nom)) { |
$id = $nom['nom_retenu.id']; |
$idsNoms = $numsNomsASynonymes[$id]; |
$cartesWs->setId("nn:".implode(',',$idsNoms).""); |
if (array_key_exists($id, $urls) == false) { |
$urls[$id] = $cartesWs->getUrlPng(); |
} |
} |
} |
$this->infosPourTpl['repartition']['urls'] = $urls; |
} |
} |
private function extraireInfosNomsPourTplDetermination() { |
$tri = $this->diviserResultats(); |
$this->infosPourTpl['nomsSansCorrespondance'] = isset($tri['sansCorres']) ? $tri['sansCorres'] : false; |
$this->infosPourTpl['noms'] = isset($tri['retenus']) ? $tri['retenus'] : false; |
$this->infosPourTpl['synonymes'] = isset($tri['synonymes'] ) ? $tri['synonymes'] : false; |
} |
/** |
* division ordonnée par |
* 1 - noms retenus qui commencent par la requete |
* 2 - requete contenue dans un synonyme dont le nom retenu ne contient pas la requete |
* 3 - requete contenue dans un hybride retenu |
* 4 - requete contenue dans un nom retenu mais pas au début |
* 5 - requete contenue dans un nom sans correspondance |
* |
*/ |
private function diviserResultats() { |
$tri = array(); |
$sansCorres = array(); |
$synonymes = array(); |
$retenus = array(); |
foreach ($this->noms as $cle => $valeurs) { |
if ($valeurs['nom_retenu.libelle'] == null) {//sans correspondances |
$sansCorres[$cle] = $valeurs['nom_sci_complet']; |
} elseif ($valeurs['retenu'] == 'true') { // retenus |
if (preg_match('/ x |^x /',$valeurs['nom_sci'] ) ) { |
//hybrides |
$retenus[2][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']); |
} elseif (strripos($valeurs['nom_sci_complet'], $this->parametres->masqueRecherche) === 0) {//preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', strtolower($valeurs['nom_sci']) ) ) { |
//commence par |
$retenus[0][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']); |
} else { |
//contient |
$retenus[3][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']); |
} |
} else {//synonymes |
$idNomRetenu = $valeurs['nom_retenu.id']; |
if (in_array($valeurs['nom_retenu.id'], array_keys($this->noms)) == false) { |
//synonymes dont le nom retenu n'est pas un résultat de recherche |
$retenus[1][$idNomRetenu] = $this->retournerInfosNomRetenu($idNomRetenu,$valeurs['nom_retenu.libelle'], $valeurs['rang.libelle']); |
$this->infosPourTpl['taxons'][$idNomRetenu] = $valeurs['num_taxonomique']; //num taxon pour images coste |
} |
$synonymes[$idNomRetenu][] = $this->retournerInfosSynonyme($cle, $valeurs); |
} |
} |
ksort($retenus); |
$tri['retenus'] = $retenus; |
$tri['synonymes'] = $synonymes; |
$tri['sansCorres'] = $sansCorres; |
return $tri; |
} |
private function retournerInfosNomRetenu($cle, $nom_sci, $rang) { |
$infos = array(); |
$infos['nomSciRetenu'] = $nom_sci; |
$infos['urlFiche'] = $this->urls->obtenirUrlFiche($cle, $this->parametres->typeNom, strtolower($this->parametres->masqueRecherche), $nom_sci); |
$infos['rang'] = $rang; |
return $infos; |
} |
private function retournerInfosSynonyme($cle, $valeurs) { |
$infos = array(); |
$infos['nn'] = $cle; |
$infos['nomSci'] = $valeurs['nom_sci_complet']; |
$infos['urlFiche'] = $this->urls->obtenirUrlFiche($cle, $this->parametres->typeNom, $this->parametres->masqueRecherche, $valeurs['nom_retenu.libelle']); |
return $infos; |
} |
public function trier() { |
$nomsRetenus = array(); |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs ) { //classement alpha par groupes |
$nomsRetenus += $this->classerAlphabetiquement('nomSciRetenu', $valeurs); |
} |
$this->infosPourTpl['noms'] = $nomsRetenus; |
$this->infosPourTpl['nomsSansCorrespondance'] = |
$this->classerAlphabetiquement('nomSciRetenu', $this->infosPourTpl['nomsSansCorrespondance'] ); |
} |
private function ajouterAuxNomsScoreSimilariteAvec($masque) { |
$nom_demande_ss = strtolower($this->manipulateurDeChaine->supprimerAccents($masque)); |
foreach ($this->infosPourTpl['noms'] as $id => $nom) { |
$nom_flou_ss = strtolower($this->manipulateurDeChaine->supprimerAccents($nom['nomSciRetenu'])); |
$stat = array(); |
// Prime pour la ressemblance globale : |
$score = 500 - levenshtein($nom_flou_ss, $nom_demande_ss); |
// On affine |
$score = $score + (similar_text($nom_demande_ss, $nom_flou_ss) * 3); |
$nom['score'] = $score; |
$this->infosPourTpl['noms'][$id] = $nom; |
} |
} |
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]['nomSciRetenu'] = $this->surlignerMotsMasqueRecherche($nom['nomSciRetenu']); |
if (isset($this->infosPourTpl['synonymes'][$idNom])) { |
foreach ($this->infosPourTpl['synonymes'][$idNom] as $idSyn => $synonyme) { |
$this->infosPourTpl['synonymes'][$idNom][$idSyn]['nomSci'] = $this->surlignerMotsMasqueRecherche($synonyme['nomSci']); |
} |
} |
} |
} |
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; |
} |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/nom_scientifique/RetenuFormateur.php |
---|
New file |
0,0 → 1,88 |
<?php |
class RetenuFormateur implements Formateur { |
const TPL_VUE = 'liste_noms'; |
private $parametres = null; |
private $surligneur = null; |
private $trieur = null; |
private $urls = null; |
private $fusioneur = 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, TableauManipulateur $tableau = 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->fusioneur = (is_null($tableau)) ? new TableauManipulateur() : $tableau; |
} |
public function getTplInfos() { |
return $this->infosPourTpl; |
} |
public function getTplNom() { |
return self::TPL_VUE; |
} |
public function formater() { |
foreach ($this->noms as $id => $nom) { |
$infosDuNom = array(); |
$infosDuNom['nomSci'] = $nom['nom_sci_complet']; |
$infosDuNom['retenu'] = $nom['retenu']; |
$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : ''; |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche); |
$this->infosPourTpl['noms'][$id] = $infosDuNom; |
} |
} |
public function trier() { |
$nomsRetenus = array(); |
$nomsSynonymes = array(); |
foreach ($this->infosPourTpl['noms'] as $id => $nom) { |
if ($nom['retenu'] == 'true') { |
$nomsRetenus[$id] = $nom; |
} else { |
$nomsSynonymes[$id] = $nom; |
} |
} |
$this->trieur->setTableau($nomsRetenus); |
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC)); |
$nomsRetenus = $this->trieur->trier(); |
$this->trieur->setTableau($nomsSynonymes); |
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC)); |
$nomsSynonymes = $this->trieur->trier(); |
$this->fusioneur->setTableau($nomsRetenus); |
$this->fusioneur->etendreAvec($nomsSynonymes); |
$this->infosPourTpl['noms'] = $this->fusioneur->getTableau(); |
} |
public function surligner() { |
$this->definirMotsASurligner(); |
foreach ($this->infosPourTpl['noms'] as $id => $nom) { |
$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']); |
} |
} |
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; |
} |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/nom_scientifique/DecompoFormateur.php |
---|
New file |
0,0 → 1,72 |
<?php |
class DecompoFormateur implements Formateur { |
const TPL_VUE = 'decomposition'; |
private $parametres = null; |
private $surligneur = null; |
private $trieur = null; |
private $urls = 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) { |
$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; |
} |
public function getTplInfos() { |
return $this->infosPourTpl; |
} |
public function getTplNom() { |
return self::TPL_VUE; |
} |
public function formater() { |
$this->infosPourTpl['masqueRecherche'] = rawurlencode($this->parametres->masqueRecherche); |
$this->infosPourTpl['baseUrlIco'] = $this->urls->obtenirUrlBaseDossier(); |
foreach ($this->noms as $id => $nom) { |
$infosDuNom = array(); |
$infosDuNom['nomSci'] = $nom['nom_sci']; |
$infosDuNom['retenu'] = $nom['retenu']; |
$infosDuNom['auteur'] = is_null($nom['auteur']) ? '' : $nom['auteur']; |
$infosDuNom['annee'] = is_null($nom['annee']) ? '' : $nom['annee']; |
$infosDuNom['biblio'] = is_null($nom['biblio_origine']) ? '' : $nom['biblio_origine']; |
$infosDuNom['addendum'] = is_null($nom['nom_addendum']) ? '' : $nom['nom_addendum']; |
$infosDuNom['nn'] = $id; |
$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : ''; |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche); |
$this->infosPourTpl['noms'][$id] = $infosDuNom; |
} |
} |
public function trier() { |
$this->trieur->setTableau($this->infosPourTpl['noms']); |
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC)); |
$this->infosPourTpl['noms'] = $this->trieur->trier(); |
} |
public function surligner() { |
$this->definirMotsASurligner(); |
foreach ($this->infosPourTpl['noms'] as $id => $nom) { |
$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']); |
} |
} |
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; |
} |
} |
?> |
/branches/v5.7-duchartre/modules/resultat/formateurs/nom_scientifique/AlphabFormateur.php |
---|
New file |
0,0 → 1,65 |
<?php |
class AlphabFormateur implements Formateur { |
const TPL_VUE = 'liste_noms'; |
private $parametres = null; |
private $surligneur = null; |
private $trieur = null; |
private $urls = 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) { |
$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; |
} |
public function getTplInfos() { |
return $this->infosPourTpl; |
} |
public function getTplNom() { |
return self::TPL_VUE; |
} |
public function formater() { |
foreach ($this->noms as $id => $nom) { |
$infosDuNom = array(); |
$infosDuNom['nomSci'] = $nom['nom_sci_complet']; |
$infosDuNom['retenu'] = $nom['retenu']; |
$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : ''; |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche); |
$this->infosPourTpl['noms'][$id] = $infosDuNom; |
} |
} |
public function trier() { |
$this->trieur->setTableau($this->infosPourTpl['noms']); |
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC)); |
$this->infosPourTpl['noms'] = $this->trieur->trier(); |
} |
public function surligner() { |
$this->definirMotsASurligner(); |
foreach ($this->infosPourTpl['noms'] as $id => $nom) { |
$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']); |
} |
} |
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; |
} |
} |
?> |