/branches/acheb/services/bibliotheque/nom/decorateurs/NomCompoDecorateur.php |
---|
New file |
0,0 → 1,84 |
<?php |
class NomCompoDecorateur extends NomDecorateur { |
private $nomDecorateur; |
protected $correspondances = array( |
'nom_sci.*' => 'Compo', |
'nom_sci.supra_generique', 'SupraGenre', |
'nom_sci.genre' => 'Genre', |
'nom_sci.infra_generique' => 'InfraGenre', |
'nom_sci.sp' => 'Sp', |
'nom_sci.type_epithete' => 'TypeInfraSp', |
'nom_sci.infra_sp' => 'InfraSp', |
'nom_sci.cultivar_groupe' => 'CultivarGroupe', |
'nom_sci.cultivar' => 'Cultivar', |
'nom_sci.nom_commercial' => 'NomCommercial'); |
public function __construct(NomDecorateur $nomDecorateur) { |
$this->nomDecorateur = $nomDecorateur; |
} |
public function ajouterCompo() { |
$this->ajouterSupraGenre(); |
$this->ajouterGenre(); |
$this->ajouterInfraGenre(); |
$this->ajouterSp(); |
$this->ajouterTypeInfraSp(); |
$this->ajouterInfraSp(); |
$this->ajouterCultivarGroupe(); |
$this->ajouterCultivar(); |
$this->ajouterNomCommercial(); |
} |
public function ajouterSupraGenre() { |
$this->ajouterPourChampSonFormatage('nom_supra_generique', 'supra_generique'); |
} |
public function ajouterGenre() { |
$this->ajouterPourChampSonFormatage('genre', 'genre'); |
} |
public function ajouterInfraGenre() { |
$this->ajouterPourChampSonFormatage('epithete_infra_generique', 'infra_generique'); |
} |
public function ajouterSp() { |
$this->ajouterPourChampSonFormatage('epithete_sp', 'sp'); |
} |
public function ajouterTypeInfraSp() { |
$this->ajouterPourChampSonFormatage('type_epithete', 'type_epithete'); |
} |
public function ajouterInfraSp() { |
$this->ajouterPourChampSonFormatage('epithete_infra_sp', 'infra_sp'); |
} |
public function ajouterCultivarGroupe() { |
$this->ajouterPourChampSonFormatage('cultivar_groupe', 'cultivar_groupe'); |
} |
public function ajouterCultivar() { |
$this->ajouterPourChampSonFormatage('cultivar', 'cultivar'); |
} |
public function ajouterNomCommercial() { |
$this->ajouterPourChampSonFormatage('nom_commercial', 'nom_commercial'); |
} |
private function ajouterPourChampSonFormatage($champ, $format) { |
$valeur = $this->nomDecorateur->nom->getTag($champ); |
if ($this->exister($valeur)) { |
$this->nomDecorateur->nomFormate["nom_sci.$format"] = $valeur; |
} |
} |
private function exister($valeur) { |
$existe = true; |
if (is_null($valeur) || $valeur == '') { |
$existe = false; |
} |
return $existe; |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/decorateurs/NomChampsProjetDecorateur.php |
---|
New file |
0,0 → 1,36 |
<?php |
class NomChampsProjetDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $champs = array(); |
protected $correspondances = array(); |
public function __construct(NomDecorateur $nomDecorateur, Array $champs) { |
$this->nomDecorateur = $nomDecorateur; |
$this->champs = $champs; |
$this->correspondances = array_flip($this->champs); |
} |
public function traiterChampsRetour(Array $champsRetour) { |
foreach ($champsRetour as $champ) { |
if (array_key_exists($champ, $this->correspondances)) { |
$champBdd = $this->correspondances[$champ]; |
$champSortie = $champ; |
if ($this->nomDecorateur->nom->verifierTag($champBdd)) { |
$valeur = $this->nomDecorateur->nom->getTag($champBdd); |
$this->nomDecorateur->nomFormate[$champSortie] = $valeur; |
} |
} |
} |
} |
public function ajouterChampsSupplementaires() { |
foreach ($this->champs as $champBdd => $champSortie) { |
if ($this->nomDecorateur->nom->verifierTag($champBdd)) { |
$valeur = $this->nomDecorateur->nom->getTag($champBdd); |
$this->nomDecorateur->nomFormate[$champSortie] = $valeur; |
} |
} |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/decorateurs/NomDecorateur.php |
---|
New file |
0,0 → 1,96 |
<?php |
class NomDecorateur implements NomResponsabilite { |
protected $nom = null; |
protected $nomFormate = array(); |
private $detailsHrefTpl = null; |
protected $correspondances = array( |
'id' => 'Id', |
'nom_sci' => 'Intitule', |
'href' => 'Href', |
'auteur' => 'Auteur', |
'annee' => 'Annee', |
'biblio_origine' => 'Biblio', |
'nom_addendum' => 'Addendum', |
'notes' => 'Notes', |
'homonyme' => 'Homonyme'); |
public function __construct(NomDO $nomADecorer, $detailsHrefTpl) { |
$this->nom = $nomADecorer; |
$this->detailsHrefTpl = $detailsHrefTpl; |
$this->initialiserNomFormate(); |
} |
public function traiterChampsRetour(Array $champsRetour) { |
foreach ($champsRetour as $champ) { |
if (array_key_exists($champ, $this->correspondances)) { |
$methodesAExecuter = explode(',', $this->correspondances[$champ]); |
foreach ($methodesAExecuter as $methodeNom) { |
$methodeAjouter = 'ajouter'.$methodeNom; |
if (method_exists($this, $methodeAjouter)) { |
$this->$methodeAjouter(); |
} |
} |
} |
} |
} |
public function ajouterId() { |
$this->nomFormate['id'] = (int) $this->nom->getTag('num_nom'); |
} |
public function ajouterIntitule() { |
$this->nomFormate['nom_sci'] = $this->nom->getTag('nom_sci'); |
} |
public function ajouterHref() { |
if ($this->nom->verifierTag('num_nom')) { |
$href = sprintf($this->detailsHrefTpl, $this->nom->getTag('num_nom')); |
$this->nomFormate['href'] = $href; |
} |
} |
public function ajouterAuteur() { |
if ($this->nom->verifierTag('auteur')) { |
$this->nomFormate['auteur'] = $this->nom->getTag('auteur'); |
} |
} |
public function ajouterAnnee() { |
if ($this->nom->verifierTag('annee')) { |
$this->nomFormate['annee'] = $this->nom->getTag('annee'); |
} |
} |
public function ajouterBiblio() { |
if ($this->nom->verifierTag('biblio_origine')) { |
$this->nomFormate['biblio_origine'] = $this->nom->getTag('biblio_origine'); |
} |
} |
public function ajouterAddendum() { |
if ($this->nom->verifierTag('nom_addendum')) { |
$this->nomFormate['nom_addendum'] = $this->nom->getTag('nom_addendum'); |
} |
} |
public function ajouterNotes() { |
if ($this->nom->verifierTag('notes')) { |
$this->nomFormate['notes'] = $this->nom->getTag('notes'); |
} |
} |
public function ajouterHomonyme() { |
if ($this->nom->verifierTag('homonyme') && $this->nom->getTag('homonyme') == 1) { |
$this->nomFormate['homonyme'] = true; |
} |
} |
public function initialiserNomFormate() { |
$this->nomFormate = array(); |
} |
public function getNomFormate() { |
return $this->nomFormate; |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/decorateurs/NomRetenuDecorateur.php |
---|
New file |
0,0 → 1,47 |
<?php |
class NomRetenuDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $numNom = null; |
private $numNomRetenu = null; |
private $nomSciRetenu = null; |
private $detailsHrefTpl = null; |
protected $correspondances = array( |
'retenu' => 'Retenu', |
'nom_retenu' => 'Intitule', |
'nom_retenu.id' => 'Id', |
'nom_retenu.href' => 'Href', |
'nom_retenu.*' => 'Intitule,Id,Href'); |
public function __construct(NomDecorateur $nomDecorateur, $detailsHrefTpl) { |
$this->nomDecorateur = $nomDecorateur; |
$this->numNom = $this->nomDecorateur->nom->getTag('num_nom'); |
$this->numNomRetenu = $this->nomDecorateur->nom->getTag('num_nom_retenu'); |
$this->nomSciRetenu = $this->nomDecorateur->nom->getTag('nr_nom_sci'); |
$this->detailsHrefTpl = $detailsHrefTpl; |
} |
public function ajouterRetenu() { |
$nn = (int) $this->numNom; |
$nnr = (int) $this->numNomRetenu; |
$this->nomDecorateur->nomFormate['retenu'] = ($nn == $nnr) ? true : false; |
} |
public function ajouterId() { |
if (empty($this->numNomRetenu) === false) { |
$this->nomDecorateur->nomFormate['nom_retenu.id'] = (int) $this->numNomRetenu; |
} |
} |
public function ajouterHref() { |
if (empty($this->numNomRetenu) === false) { |
$href = sprintf($this->detailsHrefTpl, $this->numNomRetenu); |
$this->nomDecorateur->nomFormate['nom_retenu.href'] = $href; |
} |
} |
public function ajouterIntitule() { |
$this->nomDecorateur->nomFormate['nom_retenu'] = $this->nomSciRetenu; |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/decorateurs/NomResponsabilite.php |
---|
New file |
0,0 → 1,5 |
<?php |
interface NomResponsabilite { |
public function traiterChampsRetour(Array $champsRetour); |
} |
?> |
/branches/acheb/services/bibliotheque/nom/decorateurs/NomBasionymeDecorateur.php |
---|
New file |
0,0 → 1,44 |
<?php |
class NomBasionymeDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $basionyme = null; |
private $basionymeId = null; |
private $detailsHrefTpl = null; |
protected $correspondances = array( |
'basionyme' => 'Intitule', |
'basionyme.id' => 'Id', |
'basionyme.href' => 'Href', |
'basionyme.*' => 'Intitule,Id,Href'); |
public function __construct(NomDecorateur $nomDecorateur, $detailsHrefTpl) { |
$this->nomDecorateur = $nomDecorateur; |
$this->detailsHrefTpl = $detailsHrefTpl; |
if ($this->nomDecorateur->nom->verifierTag('basionyme')) { |
$this->basionymeId = $this->nomDecorateur->nom->getTag('basionyme'); |
} |
if ($this->nomDecorateur->nom->verifierTag('nb_nom_sci')) { |
$this->basionyme = $this->nomDecorateur->nom->getTag('nb_nom_sci'); |
} |
} |
public function ajouterId() { |
if (is_null($this->basionymeId) === false) { |
$this->nomDecorateur->nomFormate['basionyme.id'] = $this->basionymeId; |
} |
} |
public function ajouterHref() { |
if (is_null($this->basionymeId) === false) { |
$href = sprintf($this->detailsHrefTpl, $this->basionymeId); |
$this->nomDecorateur->nomFormate['basionyme.href'] = $href; |
} |
} |
public function ajouterIntitule() { |
if (is_null($this->basionyme) === false) { |
$this->nomDecorateur->nomFormate['basionyme'] = $this->basionyme; |
} |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/decorateurs/NomRangDecorateur.php |
---|
New file |
0,0 → 1,47 |
<?php |
class NomRangDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $rang = null; |
private $bdd = null; |
private $ontologieHrefTpl = null; |
protected $correspondances = array( |
'rang' => 'Intitule', |
'rang.code' => 'Code', |
'rang.href' => 'Href', |
'rang.*' => 'Intitule,Code,Href'); |
public function __construct(NomDecorateur $nomDecorateur, Bdd $bdd = null, $ontologieHrefTpl) { |
$this->nomDecorateur = $nomDecorateur; |
$this->rang = $this->nomDecorateur->nom->getTag('rang'); |
$this->bdd = is_null($bdd) ? new Bdd() : $bdd; |
$this->ontologieHrefTpl = $ontologieHrefTpl; |
} |
public function ajouterCode() { |
$squelette = 'bdnt.rangTaxo:%s'; |
$rangCode = sprintf($squelette, $this->rang); |
$this->nomDecorateur->nomFormate['rang.code'] = $rangCode; |
} |
public function ajouterHref() { |
$href = sprintf($this->ontologieHrefTpl, $this->rang); |
$this->nomDecorateur->nomFormate['rang.href'] = $href; |
} |
public function ajouterIntitule() { |
$resultat = $this->rechercherOntologieNomParCode($this->rang); |
$this->nomDecorateur->nomFormate['rang'] = $resultat['nom']; |
} |
// TODO : supprimer cette recherche dans la bdd de cette classe |
private function rechercherOntologieNomParCode($code) { |
$code = $this->bdd->proteger($code); |
$requete = 'SELECT nom '. |
'FROM bdnt_ontologies_v4_30 '. |
"WHERE code = $code "; |
$resultats = $this->bdd->recuperer($requete); |
return $resultats; |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/NomDO.php |
---|
New file |
0,0 → 1,21 |
<?php |
class NomDO { |
private $infos; |
public function __construct(Array $infos) { |
$this->infos = $infos; |
} |
public function getTag($tag) { |
return isset($this->infos[$tag]) ? $this->infos[$tag] : null; |
} |
public function verifierTag($tag) { |
$existe = true; |
if ($this->getTag($tag) == null || $this->getTag($tag) == '') { |
$existe = false; |
} |
return $existe; |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/NomDAO.php |
---|
New file |
0,0 → 1,155 |
<?php |
class NomDAO { |
private $bdd = null; |
private $versions = null; |
private $requeteNbreNomsTotal = null; |
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd, Versions $versions) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
$this->bdd = $bdd; |
$this->versions = $versions; |
} |
public 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); |
$nom = new NomDO($resultats); |
return $nom; |
} |
public function rechercher() { |
$clause = $this->getClauseSelectSpeciale(); |
$table = $this->getTable(); |
$conditions = $this->getConditions(); |
$where = $this->getWhere($conditions); |
$navigation = $this->getNavigation(); |
$requete = "SELECT $clause 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.' '.$conditions.' '. |
'ORDER BY ns.nom_sci ASC '. |
"LIMIT $navigation "; |
$this->requeteNbreNomsTotal = $this->transformerRequetePourNbreNomsTotal($requete); |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
public function rechercherFloue() { |
$clause = $this->getClauseSelectSpeciale(); |
$table = $this->getTable(); |
$masque = $this->parametres->getMasquePourBdd(); |
$where = $this->getWhere(); |
$navigation = $this->getNavigation(); |
$requete = "SELECT $clause 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 . |
($masque ? ($where ? ' AND ' : ' WHERE '). |
" (SOUNDEX(ns.nom_sci) = SOUNDEX($masque)) ". |
" OR (SOUNDEX(REVERSE(ns.nom_sci)) = SOUNDEX(REVERSE($masque))) " : ''). |
'ORDER BY ns.nom_sci ASC '. |
"LIMIT $navigation "; |
$this->requeteNbreNomsTotal = $this->transformerRequetePourNbreNomsTotal($requete); |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function getClauseSelectSpeciale() { |
$clause = (Config::get('bdd_protocole') == 'mysql') ? 'SQL_CALC_FOUND_ROWS' : ''; |
return $clause; |
} |
private function getTable() { |
$versions = $this->versions->getVersions(); |
$derniereVersion = end($versions); |
$projetNom = strtolower($this->ressources->getProjetNom()); |
return $projetNom.'_v'.$derniereVersion; |
} |
private function getConditions() { |
$masquesStrictes = array('nn', 'rg'); |
$paramsMasque = array( |
'' => 'nom_sci', |
'nn' => 'num_nom', |
'rg' => 'rang', |
'sg' => 'nom_supra_generique', |
'gen' => 'genre', |
'sp' => 'epithete_sp', |
'ssp' => 'epithete_infra_sp', |
'au' => 'auteur', |
'an' => 'annee'); |
$operateurParDefaut = $this->getOperateurCondition(); |
$conditionsSql = array(); |
foreach ($paramsMasque as $typeMasque => $champ) { |
$operateur = in_array($typeMasque, $masquesStrictes) ? '=' : $operateurParDefaut; |
if ($valeurMasque = $this->parametres->getMasquePourBdd($typeMasque)) { |
$conditionsSql[] = "ns.$champ $operateur $valeurMasque"; |
} |
} |
return implode(' AND ', $conditionsSql); |
} |
private function getOperateurCondition() { |
$operateur = ''; |
$recherche = $this->parametres->get('recherche'); |
if ($recherche == 'stricte') { |
$operateur = '='; |
} else if ($recherche == 'etendue') { |
$operateur = 'LIKE'; |
} |
return $operateur; |
} |
private function getWhere($conditions = '') { |
$where = ''; |
if ($this->ressources->getServiceNom() == 'taxons') { |
$where = 'WHERE ns.num_nom = ns.num_nom_retenu '; |
} else if ($conditions != '') { |
$where = 'WHERE '; |
} |
return $where; |
} |
private function getNavigation() { |
$debut = (int) $this->parametres->get('navigation.depart'); |
$nbre = $this->parametres->get('navigation.limite'); |
$navigation = "$debut,$nbre"; |
return $navigation; |
} |
private function transformerRequetePourNbreNomsTotal($requete) { |
$requete = preg_replace('/SELECT .* FROM/', 'SELECT COUNT(*) AS nbre FROM', $requete); |
$requete = preg_replace('/LIMIT [0-9]+,[0-9]+/', '', $requete); |
return $requete; |
} |
public function recupererNombreNomsTotal() { |
if (Config::get('bdd_protocole') == 'mysql') { |
$requete = 'SELECT FOUND_ROWS() AS nbre'; |
} else { |
$requete = $this->requeteNbreNomsTotal; |
} |
$nombre = $this->bdd->recuperer($requete); |
return (int) $nombre['nbre']; |
} |
} |
?> |
/branches/acheb/services/bibliotheque/nom/NomFormateur.php |
---|
New file |
0,0 → 1,121 |
<?php |
class NomFormateur { |
private $nomAFormater = null; |
private $decorateurs = array(); |
private $bdd = null; |
private $champsProjet = array(); |
private $champsRetour = null; |
private $detailsHrefTpl = null; |
private $ontologieHrefTpl = null; |
public function setNomAFormater(NomDO $nomDO) { |
$this->nomAFormater = $nomDO; |
} |
public function setChampsRetour(Array $champsRetour) { |
$this->champsRetour = $champsRetour; |
} |
public function setChampsProjet(Array $champsProjet) { |
$this->champsProjet = $champsProjet; |
} |
public function setDetailsHrefTpl($tpl) { |
$this->detailsHrefTpl = $tpl; |
} |
public function setBdd($bdd) { |
$this->bdd = $bdd; |
} |
public function setOntologieHrefTpl($tpl) { |
$this->ontologieHrefTpl = $tpl; |
} |
public function formaterDetails() { |
$nomDeco = new NomDecorateur($this->nomAFormater, $this->detailsHrefTpl); |
$retenuDeco = new NomRetenuDecorateur($nomDeco, $this->detailsHrefTpl); |
$rangDeco = new NomRangDecorateur($nomDeco, $this->bdd, $this->ontologieHrefTpl); |
$compoDeco = new NomCompoDecorateur($nomDeco); |
$basioDeco = new NomBasionymeDecorateur($nomDeco, $this->detailsHrefTpl); |
$projetDeco = new NomChampsProjetDecorateur($nomDeco, $this->champsProjet); |
if ($this->avoirDemandeChampsRetour()) { |
$this->decorateurs[] = $nomDeco; |
$this->decorateurs[] = $retenuDeco; |
$this->decorateurs[] = $rangDeco; |
$this->decorateurs[] = $compoDeco; |
$this->decorateurs[] = $basioDeco; |
$this->decorateurs[] = $projetDeco; |
$this->traiterChampsRetour(); |
} else { |
$nomDeco->ajouterId(); |
$nomDeco->ajouterIntitule(); |
$retenuDeco->ajouterRetenu(); |
$retenuDeco->ajouterId(); |
$retenuDeco->ajouterIntitule(); |
$retenuDeco->ajouterHref(); |
$rangDeco->ajouterCode(); |
$rangDeco->ajouterIntitule(); |
$rangDeco->ajouterHref(); |
$compoDeco->ajouterCompo(); |
$nomDeco->ajouterAuteur(); |
$nomDeco->ajouterAnnee(); |
$nomDeco->ajouterBiblio(); |
$nomDeco->ajouterAddendum(); |
$nomDeco->ajouterNotes(); |
$basioDeco->ajouterId(); |
$basioDeco->ajouterIntitule(); |
$basioDeco->ajouterHref(); |
$projetDeco->ajouterChampsSupplementaires(); |
} |
return $nomDeco->getNomFormate(); |
} |
public function formaterListe() { |
$nomDeco = new NomDecorateur($this->nomAFormater, $this->detailsHrefTpl); |
$nomDeco->ajouterIntitule(); |
$retenuDeco = new NomRetenuDecorateur($nomDeco, $this->detailsHrefTpl); |
$retenuDeco->ajouterRetenu(); |
$nomDeco->ajouterHref(); |
if ($this->avoirDemandeChampsRetour()) { |
$this->decorateurs[] = $nomDeco; |
$this->decorateurs[] = $retenuDeco; |
$this->decorateurs[] = new NomRangDecorateur($nomDeco, $this->bdd, $this->ontologieHrefTpl); |
$this->decorateurs[] = new NomCompoDecorateur($nomDeco); |
$this->decorateurs[] = new NomBasionymeDecorateur($nomDeco, $this->detailsHrefTpl); |
$this->decorateurs[] = new NomChampsProjetDecorateur($nomDeco, $this->champsProjet); |
$this->traiterChampsRetour(); |
} |
return $nomDeco->getNomFormate(); |
} |
private function avoirDemandeChampsRetour() { |
$demande = true; |
if ($this->champsRetour === null || count($this->champsRetour) == 0) { |
$demande = false; |
} |
return $demande; |
} |
private function traiterChampsRetour() { |
foreach ($this->decorateurs as $deco) { |
$deco->traiterChampsRetour($this->champsRetour); |
} |
} |
} |
?> |