Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 205 → Rev 206

/trunk/services/tests/0.2/bdtfx/NomDetailsBdftxTest.php
3,8 → 3,8
 
class NomDetailsBdtfxTest extends ServicePhpUnit {
 
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.1/bdtfx/noms/%s';
private $ontologieHrefTpl = 'http://localhost/service:eflore:0.1/bdnt/ontologies/rangTaxo:%s';
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/bdtfx/noms/%s';
private $ontologieHrefTpl = 'http://localhost/service:eflore:0.2/bdnt/ontologies/rangTaxo:%s';
private $champsProjet = array(
'presence_Ga' => 'presence_Ga.code',
'presence_Co' => 'presence_Co.code'
13,7 → 13,7
public function __construct() {
$this->projet = 'bdtfx';
$this->service = 'noms';
$this->classeTestee = 'NomDetailsBdtfx';
$this->classeTestee = 'NomDetailsGenerique';
}
 
public function initialiserService(NomsListe $service) {
26,7 → 26,7
$ressources = array('85');
$parametres = array();
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertTrue(is_array($retour), 'Retour est un tableau');
$this->assertArrayHasKey('id', $retour, 'Présence champ id');
69,7 → 69,7
$ressources = array('98940');
$parametres = array();
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayNotHasKey('nom_retenu.id', $retour, 'Abscence champ nom_retenu.id');
$this->assertArrayHasKey('nom_retenu', $retour, 'Présence champ nom_retenu');
/trunk/services/tests/0.2/fournier/NomDetailsFournierTest.php
3,8 → 3,8
 
class NomDetailsFournierTest extends ServicePhpUnit {
 
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.1/fournier/noms/%s';
private $ontologieHrefTpl = 'http://localhost/service:eflore:0.1/bdnt/ontologies/rangTaxo:%s';
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/fournier/noms/%s';
private $ontologieHrefTpl = 'http://localhost/service:eflore:0.2/bdnt/ontologies/rangTaxo:%s';
private $champsProjet = array(
'nom_scientifique' => 'nom_scientifique',
'auteur_origine' => 'auteur_origine',
25,7 → 25,7
public function __construct() {
$this->projet = 'fournier';
$this->service = 'noms';
$this->classeTestee = 'NomDetailsFournier';
$this->classeTestee = 'NomDetailsGenerique';
}
 
public function initialiserService(NomsListe $service) {
38,7 → 38,7
$ressources = array('85');
$parametres = array();
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertTrue(is_array($retour), 'Retour est un tableau');
$this->assertArrayHasKey('id', $retour, 'Présence champ id');
/trunk/services/tests/0.2/fournier/NomsListeFournierTest.php
3,14 → 3,14
 
class NomsListeFournierTest extends ServicePhpUnit {
 
private $listeUrl = 'http://localhost/service:eflore:0.1/fournier/noms';
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.1/fournier/noms/%s';
private $listeUrl = 'http://localhost/service:eflore:0.2/fournier/noms';
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/fournier/noms/%s';
private $nbreNom = 168;
 
public function __construct() {
$this->projet = 'fournier';
$this->service = 'noms';
$this->classeTestee = 'NomsListeFournier';
$this->classeTestee = 'NomsListeGenerique';
}
public function initialiserService(NomsListe $service) {
$service->setDetailsHrefTpl($this->nomDetailSqueletteUrl);
21,7 → 21,7
$ressources = array();
$parametres = array();
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
$this->assertArrayHasKey('entete', $retour, 'Présence champ entete');
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEmpty($retour['entete']['masque'], 'Valeur champ entete>masque = vide');
55,7 → 55,7
$ressources = array();
$parametres = array('navigation.depart' => 100);
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('depart', $retour['entete'], 'Présence champ entete>depart');
$this->assertSame(100, $retour['entete']['depart'], 'Valeur champ entete>depart = 100');
72,7 → 72,7
$ressources = array();
$parametres = array('masque' => 'Lycopodium');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Lycopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodium"');
84,7 → 84,7
$ressources = array();
$parametres = array('masque' => 'Lycopodium', 'recherche' => 'stricte');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Lycopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodium"');
96,7 → 96,7
$ressources = array();
$parametres = array('masque' => 'Lycopodium', 'recherche' => 'etendue');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Lycopodium%', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodium%"');
110,7 → 110,7
$ressources = array();
$parametres = array('masque' => 'Licopodium', 'recherche' => 'floue');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Licopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Licopodium"');
122,7 → 122,7
$ressources = array();
$parametres = array('masque.sg' => 'Lycopodiaceae');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_supra_generique=Lycopodiaceae', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodiaceae"');
134,7 → 134,7
$ressources = array();
$parametres = array('masque.gen' => 'Lycopodium');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('genre=Lycopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "genre=Lycopodium"');
148,7 → 148,7
$ressources = array();
$parametres = array('masque.sp' => 'alpinum');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('epithete_sp=alpinum', $retour['entete']['masque'], 'Valeur champ entete>masque = "epithete_sp=alpinum"');
162,7 → 162,7
$ressources = array();
$parametres = array('masque.sg' => 'Lycopodiaceae', 'recherche' => 'etendue');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_supra_generique=Lycopodiaceae%', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodiaceae"');
174,7 → 174,7
$ressources = array();
$parametres = array('masque.gen' => 'Lycopodium', 'recherche' => 'etendue');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('genre=Lycopodium%', $retour['entete']['masque'], 'Valeur champ entete>masque = "genre=Lycopodium"');
188,7 → 188,7
$ressources = array();
$parametres = array('masque.sp' => 'alpinum', 'recherche' => 'etendue');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('epithete_sp=alpinum%', $retour['entete']['masque'], 'Valeur champ entete>masque = "epithete_sp=alpinum"');
202,7 → 202,7
$ressources = array();
$parametres = array('retour.champs' => 'nom_retenu');
 
$retour = $this->consulterBrut($ressources, $parametres);
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('href.suivant', $retour['entete'], "Présence champ entete>href.suivant");
$url = $this->listeUrl.'?retour.champs=nom_retenu&navigation.depart=100&navigation.limite=100';
/trunk/services/tests/0.2/ServicePhpUnit.php
76,7 → 76,7
 
//+------------------------------------------------------------------------------------------------------+
// Refactorisation
protected function consulterJson($ressources, $parametres) {
protected function consulter($ressources, $parametres) {
$retourJson = $this->consulterBrut($ressources, $parametres);
$retour = json_decode($retourJson, true);
$this->assertEquals(JSON_ERROR_NONE, json_last_error(), "Le json contient des erreurs qui bloquent le décodage. Voir : $url");
86,13 → 86,8
protected function consulterBrut($ressources, $parametres) {
array_unshift($ressources, $this->service);
array_unshift($ressources, $this->projet);
$Bdd = new Bdd();
$Ressources = new Ressources($ressources);
$Parametres = new Parametres($parametres, $Bdd);
require_once self::$cheminBase.$this->projet.'/'.$this->classeTestee.'.php';
$objetService = new $this->classeTestee($Ressources, $Parametres, $Bdd);
$this->initialiserService($objetService);
$retourJson = $objetService->consulter();
$projet = new Projets();
$retourJson = $projet->consulter($ressources, $parametres);
return $retourJson;
}
 
/trunk/services/modules/0.2/bdtfx/NomsListeBdtfx.php
File deleted
\ No newline at end of file
/trunk/services/modules/0.2/bdtfx/TaxonsListeBdtfx.php
File deleted
\ No newline at end of file
/trunk/services/modules/0.2/bdtfx/NomDetailsBdtfx.php
File deleted
\ No newline at end of file
/trunk/services/modules/0.2/fournier/NomsListeFournier.php
File deleted
\ No newline at end of file
/trunk/services/modules/0.2/fournier/TaxonsListeFournier.php
File deleted
\ No newline at end of file
/trunk/services/modules/0.2/fournier/NomDetailsFournier.php
File deleted
\ No newline at end of file
/trunk/services/modules/0.2/commun/NomsListeGenerique.php
New file
0,0 → 1,304
<?php
class NomsListeGenerique implements NomsListe {
 
private $parametres = null;
private $ressources = null;
private $bdd = null;
private $projet = null;
private $versions = null;
private $listeUrl = null;
private $detailsHrefTpl = null;
private $ontologieHrefTpl = null;
private $champsProjet = array();
 
private $nbreTotalNoms = 0;
private $noms = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->bdd = $bdd;
}
 
public function setProjet($projet) {
$this->projet = $projet;
}
 
public function setVersions($versions) {
$this->versions = $versions;
}
 
public function setChampsProjet($champsProjet) {
$this->champsProjet = $champsProjet;
}
 
public function setDetailsHrefTpl($tpl) {
$this->detailsHrefTpl = $tpl;
}
 
public function setOntologieHrefTpl($tpl) {
$this->ontologieHrefTpl = $tpl;
}
 
public function setListeUrl($url) {
$this->listeUrl = $url;
}
 
public function consulter() {
$this->noms = $this->rechercher();
$this->nbreNomsTotal = $this->recupererNombreNomsTotal();
$this->trierNoms();
$retour = $this->construireTableauRetour();
return $retour;
}
 
private function getTable() {
$versions = $this->versions->getVersions();
return $this->projet.'_v'.end($versions);
}
 
private function rechercher() {
$resultats = array();
$recherche = $this->parametres->get('recherche');
 
if ($recherche == 'stricte') {
$resultats = $this->rechercherStricte();
} else if ($recherche == 'etendue') {
$resultats = $this->rechercherEtendue();
} else if ($recherche == 'floue') {
$resultats = $this->rechercherFloue();
}
 
return $resultats;
}
 
private function rechercherStricte() {
$table = $this->getTable();
$conditions = array();
if ($masque = $this->parametres->getMasquePourBdd()) {
$conditions[] = "ns.nom_sci = $masque";
}
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
$conditions[] = "ns.nom_supra_generique = $masqueSg";
}
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
$conditions[] = "ns.genre = $masqueGen";
}
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
$conditions[] = "ns.epithete_sp = $masqueSp";
}
 
$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
(count($conditions) > 0 ? 'WHERE ' : '').
implode(' AND ', $conditions).
'ORDER BY ns.nom_sci ASC '.
'LIMIT 0,100';
$resultats = $this->bdd->recupererTous($requete);
 
return $resultats;
}
 
private function rechercherEtendue() {
$table = $this->getTable();
$conditions = array();
if ($masque = $this->parametres->getMasquePourBdd()) {
$conditions[] = "ns.nom_sci LIKE $masque";
}
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
$conditions[] = "ns.nom_supra_generique LIKE $masqueSg";
}
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
$conditions[] = "ns.genre LIKE $masqueGen";
}
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
$conditions[] = "ns.epithete_sp LIKE $masqueSp";
}
$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
(count($conditions) > 0 ? 'WHERE ' : '').
implode(' AND ', $conditions).
'ORDER BY ns.nom_sci ASC '.
'LIMIT 0,100';
 
$resultats = $this->bdd->recupererTous($requete);
return $resultats;
}
 
private function rechercherFloue() {
$table = $this->getTable();
$masque = $this->parametres->getMasquePourBdd();
$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
($masque ? 'WHERE '.
" (SOUNDEX(ns.nom_sci) = SOUNDEX($masque)) ".
" OR (SOUNDEX(REVERSE(ns.nom_sci)) = SOUNDEX(REVERSE($masque))) " : '').
'ORDER BY ns.nom_sci ASC '.
'LIMIT 0,100';
$resultats = $this->bdd->recupererTous($requete);
return $resultats;
}
 
private function recupererNombreNomsTotal() {
$requete = 'SELECT FOUND_ROWS() AS nbre';
$nombre = $this->bdd->recuperer($requete);
return (int) $nombre['nbre'];
}
 
private function trierNoms() {
$recherche = $this->parametres->get('recherche');
if ($recherche == 'floue') {
$this->trierRechercheFloue();
}
}
 
public function trierRechercheFloue() {
$nomDemande = $this->parametres->get('masque');
$nomDemandeSimple = strtolower(Chaine::supprimerAccents($nomDemande));
 
foreach ($this->noms as $id => $nom) {
$nomFlouSimple = strtolower(Chaine::supprimerAccents($nom['nom_sci']));
// Prime pour la ressemblance globale :
$score = 500 - levenshtein($nomFlouSimple, $nomDemandeSimple);
// On affine
$score += similar_text($nomDemandeSimple, $nomFlouSimple) * 3;
$this->noms[$id]['score'] = $score;
}
$noms = $this->noms;
$this->noms = Tableau::trierMD($noms, array('score' => false));
//print_r($this->noms);
}
 
private function construireTableauRetour() {
$retour = array('entete' => array(), 'resultats' => array());
$retour['resultats'] = $this->construireResultats();
$retour['entete'] = $this->construireEntete();
return $retour;
}
 
private function construireResultats() {
$nomsFormates = array();
foreach ($this->noms as $nom) {
$id = $nom['num_nom'];
$nomsFormates[$id] = $this->formaterNom($nom);
}
return $nomsFormates;
}
 
private function formaterNom($infos) {
$nomAFormater = new NomDO($infos);
$formateur = new NomFormateur($nomAFormater);
$formateur->setBdd($this->bdd);
$formateur->setDetailsHrefTpl($this->detailsHrefTpl);
$formateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$nom = $formateur->formaterListe();
return $nom;
}
 
private function formaterHref($nom) {
$href = sprintf($this->detailsHrefTpl, $nom['num_nom']);
return $href;
}
 
private function construireEntete() {
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
$entete['masque'] = $this->formaterEnteteMasque();
$entete['depart'] = (int) $this->parametres->get('navigation.depart');
$entete['limite'] = (int) $this->parametres->get('navigation.limite');
$entete['total'] = $this->nbreNomsTotal;
if ($hrefPrecedent = $this->formaterEnteteHrefPrecedent()) {
$entete['href.precedent'] = $hrefPrecedent;
}
if ($hrefSuivant = $this->formaterEnteteHrefSuivant()) {
$entete['href.suivant'] = $hrefSuivant;
}
return $entete;
}
 
private function formaterEnteteMasque() {
$masqueComplet = array();
if ($this->parametres->exister('masque')) {
$masque = '';
$masque .= 'nom_sci='.$this->parametres->get('masque');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
if ($this->parametres->exister('masque.sg')) {
$masque = '';
$masque .= 'nom_supra_generique='.$this->parametres->get('masque.sg');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
if ($this->parametres->exister('masque.gen')) {
$masque = '';
$masque .= 'genre='.$this->parametres->get('masque.gen');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
if ($this->parametres->exister('masque.sp')) {
$masque = '';
$masque .= 'epithete_sp='.$this->parametres->get('masque.sp');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
return implode('&', $masqueComplet);
}
 
private function formaterEnteteHrefPrecedent() {
$limite = $this->parametres->get('navigation.limite');
$departActuel = $this->parametres->get('navigation.depart');
$departPrecedent = $departActuel - $limite;
$href = null;
if ($departPrecedent >= 0) {
$squelette = $this->construireTplHrefNavigation();
$href = sprintf($squelette, $departPrecedent, $limite);
}
return $href;
}
 
private function formaterEnteteHrefSuivant() {
$limite = $this->parametres->get('navigation.limite');
$departActuel = $this->parametres->get('navigation.depart');
$departSuivant = $departActuel + $limite;
$href = null;
if ($departSuivant < $this->nbreNomsTotal) {
$squelette = $this->construireTplHrefNavigation();
$href = sprintf($squelette, $departSuivant, $limite);
}
return $href;
}
 
private function construireTplHrefNavigation() {
$requetes = array();
$this->parametres->rewind();
while (is_null($parametre = $this->parametres->key()) === false) {
if (strpos($parametre, 'navigation') === false) {
$valeur = $this->parametres->current();
$requetes[] = "$parametre=$valeur";
}
$this->parametres->next();
}
$requetes[] = "navigation.depart=%s";
$requetes[] = "navigation.limite=%s";
$tpl = $this->listeUrl.'?'.implode('&', $requetes);
return $tpl;
}
}
?>
/trunk/services/modules/0.2/commun/TaxonsListeGenerique.php
New file
0,0 → 1,307
<?php
class TaxonsListeGenerique implements NomsListe {
 
private $parametres = null;
private $ressources = null;
private $bdd = null;
private $projet = null;
private $versions = null;
private $listeUrl = null;
private $detailsHrefTpl = null;
private $ontologieHrefTpl = null;
private $champsProjet = array();
 
private $nbreTotalNoms = 0;
private $noms = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->bdd = $bdd;
}
 
public function setProjet($projet) {
$this->projet = $projet;
}
 
public function setVersions($versions) {
$this->versions = $versions;
}
 
public function setChampsProjet($champsProjet) {
$this->champsProjet = $champsProjet;
}
 
public function setDetailsHrefTpl($tpl) {
$this->detailsHrefTpl = $tpl;
}
 
public function setOntologieHrefTpl($tpl) {
$this->ontologieHrefTpl = $tpl;
}
 
public function setListeUrl($url) {
$this->listeUrl = $url;
}
 
public function consulter() {
$this->noms = $this->rechercher();
$this->nbreNomsTotal = $this->recupererNombreNomsTotal();
$this->trierNoms();
$retour = $this->construireTableauRetour();
return $retour;
}
 
private function getTable() {
$versions = $this->versions->getVersions();
return $this->projet.'_v'.end($versions);
}
 
private function rechercher() {
$resultats = array();
$recherche = $this->parametres->get('recherche');
 
if ($recherche == 'stricte') {
$resultats = $this->rechercherStricte();
} else if ($recherche == 'etendue') {
$resultats = $this->rechercherEtendue();
} else if ($recherche == 'floue') {
$resultats = $this->rechercherFloue();
}
 
return $resultats;
}
 
private function rechercherStricte() {
$table = $this->getTable();
$conditions = array();
if ($masque = $this->parametres->getMasquePourBdd()) {
$conditions[] = "ns.nom_sci = $masque";
}
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
$conditions[] = "ns.nom_supra_generique = $masqueSg";
}
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
$conditions[] = "ns.genre = $masqueGen";
}
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
$conditions[] = "ns.epithete_sp = $masqueSp";
}
 
$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
'WHERE ns.num_nom = ns.num_nom_retenu '.
implode(' AND ', $conditions).
'ORDER BY ns.nom_sci ASC '.
'LIMIT 0,100';
$resultats = $this->bdd->recupererTous($requete);
 
return $resultats;
}
 
private function rechercherEtendue() {
$table = $this->getTable();
$conditions = array();
if ($masque = $this->parametres->getMasquePourBdd()) {
$conditions[] = "ns.nom_sci LIKE $masque";
}
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
$conditions[] = "ns.nom_supra_generique LIKE $masqueSg";
}
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
$conditions[] = "ns.genre LIKE $masqueGen";
}
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
$conditions[] = "ns.epithete_sp LIKE $masqueSp";
}
$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
'WHERE ns.num_nom = ns.num_nom_retenu '.
implode(' AND ', $conditions).
'ORDER BY ns.nom_sci ASC '.
'LIMIT 0,100';
 
$resultats = $this->bdd->recupererTous($requete);
return $resultats;
}
 
private function rechercherFloue() {
$table = $this->getTable();
$masque = $this->parametres->getMasquePourBdd();
$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
'WHERE ns.num_nom = ns.num_nom_retenu '.
($masque ?
" (SOUNDEX(ns.nom_sci) = SOUNDEX($masque)) ".
" OR (SOUNDEX(REVERSE(ns.nom_sci)) = SOUNDEX(REVERSE($masque))) " : '').
'ORDER BY ns.nom_sci ASC '.
'LIMIT 0,100';
$resultats = $this->bdd->recupererTous($requete);
return $resultats;
}
 
private function recupererNombreNomsTotal() {
$requete = 'SELECT FOUND_ROWS() AS nbre';
$nombre = $this->bdd->recuperer($requete);
return (int) $nombre['nbre'];
}
 
private function trierNoms() {
$recherche = $this->parametres->get('recherche');
if ($recherche == 'floue') {
$this->trierRechercheFloue();
}
}
 
public function trierRechercheFloue() {
$nomDemande = $this->parametres->get('masque');
$nomDemandeSimple = strtolower(Chaine::supprimerAccents($nomDemande));
 
foreach ($this->noms as $id => $nom) {
$nomFlouSimple = strtolower(Chaine::supprimerAccents($nom['nom_sci']));
// Prime pour la ressemblance globale :
$score = 500 - levenshtein($nomFlouSimple, $nomDemandeSimple);
// On affine
$score += similar_text($nomDemandeSimple, $nomFlouSimple) * 3;
$this->noms[$id]['score'] = $score;
}
$noms = $this->noms;
$this->noms = Tableau::trierMD($noms, array('score' => false));
//print_r($this->noms);
}
 
private function construireTableauRetour() {
$retour = array('entete' => array(), 'resultats' => array());
$retour['resultats'] = $this->construireResultats();
$retour['entete'] = $this->construireEntete();
return $retour;
}
 
private function construireResultats() {
$nomsFormates = array();
foreach ($this->noms as $nom) {
$id = $nom['num_nom'];
$nomsFormates[$id] = $this->formaterNom($nom);
}
return $nomsFormates;
}
 
private function formaterNom($infos) {
$nomAFormater = new NomDO($infos);
$formateur = new NomFormateur($nomAFormater);
$formateur->setBdd($this->bdd);
$formateur->setChampsProjet($this->champsProjet);
$formateur->setDetailsHrefTpl($this->detailsHrefTpl);
$formateur->setOntologieHrefTpl($this->ontologieHrefTpl);
$formateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$nom = $formateur->formaterListe();
return $nom;
}
 
private function formaterHref($nom) {
$href = sprintf($this->detailsHrefTpl, $nom['num_nom']);
return $href;
}
 
private function construireEntete() {
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
$entete['masque'] = $this->formaterEnteteMasque();
$entete['depart'] = (int) $this->parametres->get('navigation.depart');
$entete['limite'] = (int) $this->parametres->get('navigation.limite');
$entete['total'] = $this->nbreNomsTotal;
if ($hrefPrecedent = $this->formaterEnteteHrefPrecedent()) {
$entete['href.precedent'] = $hrefPrecedent;
}
if ($hrefSuivant = $this->formaterEnteteHrefSuivant()) {
$entete['href.suivant'] = $hrefSuivant;
}
return $entete;
}
 
private function formaterEnteteMasque() {
$masqueComplet = array();
if ($this->parametres->exister('masque')) {
$masque = '';
$masque .= 'nom_sci='.$this->parametres->get('masque');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
if ($this->parametres->exister('masque.sg')) {
$masque = '';
$masque .= 'nom_supra_generique='.$this->parametres->get('masque.sg');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
if ($this->parametres->exister('masque.gen')) {
$masque = '';
$masque .= 'genre='.$this->parametres->get('masque.gen');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
if ($this->parametres->exister('masque.sp')) {
$masque = '';
$masque .= 'epithete_sp='.$this->parametres->get('masque.sp');
if ($this->parametres->get('recherche') == 'etendue') {
$masque .= '%';
}
$masqueComplet[] = $masque;
}
return implode('&', $masqueComplet);
}
 
private function formaterEnteteHrefPrecedent() {
$limite = $this->parametres->get('navigation.limite');
$departActuel = $this->parametres->get('navigation.depart');
$departPrecedent = $departActuel - $limite;
$href = null;
if ($departPrecedent >= 0) {
$squelette = $this->construireTplHrefNavigation();
$href = sprintf($squelette, $departPrecedent, $limite);
}
return $href;
}
 
private function formaterEnteteHrefSuivant() {
$limite = $this->parametres->get('navigation.limite');
$departActuel = $this->parametres->get('navigation.depart');
$departSuivant = $departActuel + $limite;
$href = null;
if ($departSuivant < $this->nbreNomsTotal) {
$squelette = $this->construireTplHrefNavigation();
$href = sprintf($squelette, $departSuivant, $limite);
}
return $href;
}
 
private function construireTplHrefNavigation() {
$requetes = array();
$this->parametres->rewind();
while (is_null($parametre = $this->parametres->key()) === false) {
if (strpos($parametre, 'navigation') === false) {
$valeur = $this->parametres->current();
$requetes[] = "$parametre=$valeur";
}
$this->parametres->next();
}
$requetes[] = "navigation.depart=%s";
$requetes[] = "navigation.limite=%s";
$tpl = $this->listeUrl.'?'.implode('&', $requetes);
return $tpl;
}
}
?>
/trunk/services/modules/0.2/commun/NomDetailsGenerique.php
New file
0,0 → 1,79
<?php
class NomDetailsGenerique implements NomDetails {
 
private $parametres = null;
private $ressources = null;
private $bdd = null;
private $projet = null;
private $versions = null;
private $detailsHrefTpl = null;
private $ontologieHrefTpl = null;
 
private $nom = array();
private $champsProjet = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->bdd = $bdd;
}
 
public function setProjet($projet) {
$this->projet = $projet;
}
 
public function setVersions($versions) {
$this->versions = $versions;
}
 
public function setChampsProjet($champsProjet) {
$this->champsProjet = $champsProjet;
}
 
public function setDetailsHrefTpl($tpl) {
$this->detailsHrefTpl = $tpl;
}
 
public function setOntologieHrefTpl($tpl) {
$this->ontologieHrefTpl = $tpl;
}
 
public function consulter() {
$infos = $this->rechercherInfosNom();
$retour = $this->formaterDetails($infos);
return $retour;
}
 
private function getTable() {
$versions = $this->versions->getVersions();
return $this->projet.'_v'.end($versions);
}
 
private function rechercherInfosNom() {
$table = $this->getTable();
$detailsId = $this->ressources->getDetailsId();
$detailsId = $this->bdd->proteger($detailsId);
$requete =
'SELECT ns.*, '.
' nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
"FROM $table AS ns ".
" LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
" LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
"WHERE ns.num_nom = $detailsId ";
$resultats = $this->bdd->recuperer($requete);
return $resultats;
}
 
private function formaterDetails($infos) {
$nomAFormater = new NomDO($infos);
$formateur = new NomFormateur($nomAFormater);
$formateur->setBdd($this->bdd);
$formateur->setChampsProjet($this->champsProjet);
$formateur->setDetailsHrefTpl($this->detailsHrefTpl);
$formateur->setOntologieHrefTpl($this->ontologieHrefTpl);
$formateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$details = $formateur->formaterDetails();
return $details;
}
}
?>