/trunk/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(); |
} |
?> |
/trunk/modules/resultat/formateurs/DeterminationFormateur.php |
---|
New file |
0,0 → 1,159 |
<?php |
class DeterminationFormateur implements Formateur { |
const TPL_VUE = 'resultat_determination_noms'; |
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->obtenirUrlsPhotos(); |
$this->extraireInfosNomsPourTplDetermination(); |
} |
private function obtenirUrlsPhotos() { |
$ids = $this->extraireIdDesNoms(); |
$urls = $this->imagesService->getUrlsImagesParIdsNoms($ids); |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesIds($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 supprimerCodeReftaxDesIds($urls) { |
$codeReftax = $this->parametres->reftaxCourant.'.'; |
$urlsNettoyees = array(); |
foreach ($urls as $id => $url) { |
$id = str_replace($codeReftax, '', $id); |
$urlsNettoyees[$id] = $url; |
} |
return $urlsNettoyees; |
} |
private function extraireInfosNomsPourTplDetermination() { |
$nomsSansCorrespondance = array(); |
$nomsAvecCorrespondance = array(); |
foreach ($this->noms as $idNomCourant => $nom) { |
if ($nom['retenu'] == 'true') { |
$nomRetenu = array(); |
$nomRetenu['nomSciRetenu'] = $nom['nom_sci']; |
$nomRetenu['urlFiche'] = $this->urls->obtenirUrlFiche($idNomCourant); |
$nomsAvecCorrespondance[$idNomCourant] = $nomRetenu; |
} else { |
if ($nom['nom_retenu'] == null) { |
$nomsSansCorrespondance[$idNomCourant] = $nom['nom_sci']; |
} else { |
$idNomRetenu = $nom['nom_retenu.id']; |
if (array_key_exists($nom['nom_retenu.id'], $nomsAvecCorrespondance) == false) { |
$nomRetenu = array(); |
$nomRetenu['nomSciRetenu'] = $nom['nom_retenu']; |
$nomRetenu['urlFiche'] = $this->urls->obtenirUrlFiche($idNomRetenu); |
$nomsAvecCorrespondance[$idNomRetenu] = $nomRetenu; |
} |
$synonyme = array(); |
$synonyme['nn'] = $idNomCourant; |
$synonyme['nomSci'] = $nom['nom_sci']; |
$synonyme['urlFiche'] = $this->urls->obtenirUrlFiche($idNomCourant); |
$nomsAvecCorrespondance[$idNomRetenu]['synonymes'][] = $synonyme; |
} |
} |
} |
$this->infosPourTpl['nomsSansCorrespondance'] = (count($nomsSansCorrespondance) > 0) ? $nomsSansCorrespondance : false; |
$this->infosPourTpl['noms'] = (count($nomsAvecCorrespondance) > 0) ? $nomsAvecCorrespondance : false; |
} |
public function trier() { |
$this->ajouterAuxNomsScoreSimilariteAvec($this->parametres->masqueRecherche); |
$this->trieur->setTableau($this->infosPourTpl['noms']); |
$this->trieur->setChampsEtOrdres(array('score' => SORT_DESC)); |
$this->infosPourTpl['noms'] = $this->trieur->trier(); |
} |
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; |
} |
} |
public function surligner() { |
$this->definirMotsASurligner(); |
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) { |
$nom['nomSciRetenu'] = $this->surlignerMotsMasqueRecherche($nom['nomSciRetenu']); |
if (isset($nom['synonymes'])) { |
foreach ($nom['synonymes'] as $idSyn => $synonyme) { |
$nom['synonymes'][$idSyn]['nomSci'] = $this->surlignerMotsMasqueRecherche($synonyme['nomSci']); |
} |
} |
$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; |
} |
} |
?> |
/trunk/modules/resultat/formateurs/ResultatFormateurFabrique.php |
---|
New file |
0,0 → 1,15 |
<?php |
class ResultatFormateurFabrique { |
public static function creer(ParametresResultats $parametres, Array $resultats){ |
$type = ucwords($parametres->type); |
$ResultatFormateurClasse = $type.'Formateur'; |
$chemin = dirname(__FILE__).DS.$ResultatFormateurClasse.'.php'; |
$ResultatFormateur = null; |
if (file_exists($chemin)) { |
$ResultatFormateur = new $ResultatFormateurClasse($parametres, $resultats); |
} |
return $ResultatFormateur; |
} |
} |
?> |
/trunk/modules/resultat/formateurs/RetenuFormateur.php |
---|
New file |
0,0 → 1,87 |
<?php |
class RetenuFormateur implements Formateur { |
const TPL_VUE = 'resultat_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']; |
$infosDuNom['retenu'] = $nom['retenu']; |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id); |
$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; |
} |
} |
?> |
/trunk/modules/resultat/formateurs/DecompoFormateur.php |
---|
New file |
0,0 → 1,69 |
<?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() { |
foreach ($this->noms as $id => $nom) { |
$infosDuNom = array(); |
$infosDuNom['nomSci'] = $nom['nom_sci']; |
$infosDuNom['retenu'] = $nom['retenu'] == 'true' ? true : false; |
$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; |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id); |
$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; |
} |
} |
?> |
/trunk/modules/resultat/formateurs/AlphabFormateur.php |
---|
New file |
0,0 → 1,64 |
<?php |
class AlphabFormateur implements Formateur { |
const TPL_VUE = 'resultat_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']; |
$infosDuNom['retenu'] = $nom['retenu']; |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id); |
$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; |
} |
} |
?> |