Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 922 → Rev 921

/trunk/services/bibliotheque/Ressources.php
New file
0,0 → 1,108
<?php
class Ressources {
 
private $ressources = array();
 
public function __construct(Array $ressources) {
$this->ressources = $ressources;
}
 
public function getParPosition($position) {
$valeur = '';
if (array_key_exists($position, $this->ressources)) {
$valeur = $this->ressources[$position];
}
return $valeur;
}
 
public function getNombre() {
return count($this->ressources);
}
 
public function getProjetNom() {
return $this->getParPosition(0);
}
 
public function getServiceNom() {
return $this->getParPosition(1);
}
 
public function getDetailsId() {
return (int) $this->getParPosition(2);
}
 
public function etreId($aTester) {
$etreId = is_numeric($aTester) ? true : false;
return $etreId;
}
 
public function etreStats($aTester) {
$etreStats = $aTester == 'stats' ? true : false;
return $etreStats;
}
 
public function etreTypeDeStats($aTester) {
$typesStats = array('annees', 'rangs', 'initiales');
$etreStatsType = in_array($aTester, $typesStats) ? true : false;
return $etreStatsType;
}
 
public function etreRelations($aTester) {
$etreRelations = $aTester == 'relations' ? true : false;
return $etreRelations;
}
 
public function etreTypeDeRelations($aTester) {
$typesRelations = array('synonymie', 'homonymie', 'flores');
$etreRelationsType = in_array($aTester, $typesRelations) ? true : false;
return $etreRelationsType;
}
 
public function getServiceClasse() {
$classeNom = '';
if ($this->getNombre() == 2) {
if ($this->getServiceNom() == 'noms') {
$classeNom = 'NomsListe';
} else if ($this->getServiceNom() == 'taxons') {
$classeNom = 'TaxonsListe';
} else if ($this->getServiceNom() == 'ontologies') {
$classeNom = 'OntologiesListe';
}
 
} else if ($this->getNombre() == 3) {
$position3 = $this->getParPosition(2);
if ($this->etreId($position3)) {
if ($this->getServiceNom() == 'noms') {
$classeNom = 'NomDetails';
} else if ($this->getServiceNom() == 'taxons') {
$classeNom = 'TaxonDetails';
}
}
} else if ($this->getNombre() == 4) {
$position3 = $this->getParPosition(2);
$position4 = $this->getParPosition(3);
if ($this->etreStats($position3)) {
if ($this->etreTypeDeStats($position4)) {
$classeNom = 'NomsStats'.ucfirst($position4);
}
} else if ($this->etreId($position3)) {
if ($this->etreRelations($position4)) {
$classeNom = 'NomRelations';
}
}
} else if ($this->getNombre() == 5) {
$position3 = $this->getParPosition(2);
$position4 = $this->getParPosition(3);
$position5 = $this->getParPosition(4);
if ($this->etreId($position3)) {
if ($this->etreRelations($position4)) {
if ($this->etreTypeDeRelations($position5)) {
$classeNom = 'NomRelations'.ucfirst($position5);
}
}
}
}
return $classeNom;
}
}
?>
/trunk/services/bibliotheque/interfaces/OntologiesListe.php
New file
0,0 → 1,6
<?php
interface OntologiesListe {
public function __construct(OntologiesListeGenerique $ontologiesListe);
public function consulter();
}
?>
/trunk/services/bibliotheque/interfaces/NomsListe.php
New file
0,0 → 1,6
<?php
interface NomsListe {
public function __construct(NomsListeGenerique $nomsListe);
public function consulter();
}
?>
/trunk/services/bibliotheque/interfaces/NomDetails.php
New file
0,0 → 1,6
<?php
interface NomDetails {
public function __construct(NomDetailsGenerique $nomDetails);
public function consulter();
}
?>
/trunk/services/bibliotheque/VersionVerificateur.php
New file
0,0 → 1,44
<?php
class VersionVerificateur {
 
private $ressources = null;
private $parametres = null;
private $versions = null;
 
public function __construct(Ressources $ressources, Parametres $parametres, Versions $versions) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->versions = $versions;
}
 
public function verifier() {
$this->verifierDispoMultiProjetPourService();
$this->verifierExistance();
}
 
private function verifierDispoMultiProjetPourService() {
$servicesMultiProjet = array('NomDetails');
$classeService = $this->ressources->getServiceClasse();
$versionDemandee = $this->parametres->get('version.projet');
if ($versionDemandee == '*' && in_array($classeService, $servicesMultiProjet) === false) {
$message = "L'affichage de plusieurs versions ne fonctionne que pour les ressources de type /ressources/#id";
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($message, $code);
}
}
 
private function verifierExistance() {
$versionDemandee = $this->parametres->get('version.projet');
$versionTrouvee = $this->versions->getVersions();
if (is_numeric($versionDemandee)) {
if (count($versionTrouvee) == 0) {
$projet = $this->ressources->getProjetNom();
$message = "La version '$versionDemandee' n'est pas disponible pour le projet '$projet' !";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
}
 
}
}
?>
/trunk/services/bibliotheque/generique/NomsListeGenerique.php
New file
0,0 → 1,187
<?php
class NomsListeGenerique {
 
private $parametres = null;
private $ressources = null;
private $nomDao = null;
private $nomFormateur = null;
 
private $listeUrl = null;
private $nbreNomsTotal = 0;
private $noms = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, NomDAO $nomDao, NomFormateur $nomFormateur) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->nomDao = $nomDao;
$this->nomFormateur = $nomFormateur;
}
 
public function setListeUrl($url) {
$this->listeUrl = $url;
}
 
public function consulter() {
$this->rechercher();
if ($this->avoirResultats()) {
$this->trierNoms();
$retour = $this->construireTableauRetour();
} else {
$message = "Aucun résultat ne correspond a votre requête !";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
return $retour;
}
 
private function avoirResultats() {
$resultat = ($this->nbreNomsTotal == 0) ? false : true;
return $resultat;
}
 
 
private function rechercher() {
$resultats = array();
$recherche = $this->parametres->get('recherche');
 
if ($recherche == 'floue') {
$resultats = $this->nomDao->rechercherFloue();
} else {
$resultats = $this->nomDao->rechercher();
}
$this->noms = $resultats;
$this->nbreNomsTotal = $this->nomDao->recupererNombreNomsTotal();
}
 
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);
$this->nomFormateur->setNomAFormater($nomAFormater);
$this->nomFormateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$nom = $this->nomFormateur->formaterListe();
return $nom;
}
 
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() {
$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');
$etendre = ($this->parametres->get('recherche') == 'etendue') ? true : false;
 
$masqueComplet = array();
foreach ($paramsMasque as $masqueType => $champ) {
$masqueParam = 'masque'.($masqueType != '' ? '.'.$masqueType : $masqueType);
if ($this->parametres->exister($masqueParam)) {
$masqueValeur = $this->parametres->get($masqueParam);
$masque = "$champ=$masqueValeur";
$masque .= ($etendre && in_array($masqueType, $masquesStrictes) === false) ? '%' : '';
 
$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/bibliotheque/generique/TaxonsListeGenerique.php
New file
0,0 → 1,187
<?php
class TaxonsListeGenerique {
 
private $parametres = null;
private $ressources = null;
private $nomDao = null;
private $nomFormateur = null;
 
private $listeUrl = null;
private $nbreTotalNoms = 0;
private $noms = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, NomDAO $nomDao, NomFormateur $nomFormateur) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->nomDao = $nomDao;
$this->nomFormateur = $nomFormateur;
}
 
public function setListeUrl($url) {
$this->listeUrl = $url;
}
 
public function consulter() {
$this->noms = $this->rechercher();
$this->nbreNomsTotal = $this->nomDao->recupererNombreNomsTotal();
$this->trierNoms();
$retour = $this->construireTableauRetour();
return $retour;
}
 
private function rechercher() {
$resultats = array();
$recherche = $this->parametres->get('recherche');
 
if ($recherche == 'stricte') {
$resultats = $this->nomDao->rechercherStricte();
} else if ($recherche == 'etendue') {
$resultats = $this->nomDao->rechercherEtendue();
} else if ($recherche == 'floue') {
$resultats = $this->nomDao->rechercherFloue();
}
 
return $resultats;
}
 
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);
$this->nomFormateur->setNomAFormater($nomAFormater);
$this->nomFormateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$nom = $this->nomFormateur->formaterListe();
return $nom;
}
 
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/bibliotheque/generique/NomDetailsGenerique.php
New file
0,0 → 1,30
<?php
class NomDetailsGenerique {
 
private $parametres = null;
private $ressources = null;
private $nomDao = null;
private $nomFormateur = null;
private $nom = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, NomDAO $nomDao, NomFormateur $nomFormateur) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->nomDao = $nomDao;
$this->nomFormateur = $nomFormateur;
}
 
public function consulter() {
$this->nom = $this->nomDao->rechercherInfosNom();
$retour = $this->formaterDetails();
return $retour;
}
 
private function formaterDetails() {
$this->nomFormateur->setNomAFormater($this->nom);
$this->nomFormateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$details = $this->nomFormateur->formaterDetails();
return $details;
}
}
?>
/trunk/services/bibliotheque/generique/OntologiesListeGenerique.php
New file
0,0 → 1,157
<?php
class OntologiesListeGenerique {
 
private $parametres = null;
private $ressources = null;
private $ontologieDao = null;
private $ontologieFormateur = null;
 
private $listeUrl = null;
private $nbreTotalTermes = 0;
private $termes = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, OntologieDAO $ontologieDao, OntologieFormateur $ontologieFormateur) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->ontologieDao = $ontologieDao;
$this->ontologieFormateur = $ontologieFormateur;
}
 
public function setListeUrl($url) {
$this->listeUrl = $url;
}
 
public function consulter() {
$this->rechercher();
if ($this->avoirResultats()) {
$this->trierResultats();
$retour = $this->construireTableauRetour();
} else {
$message = "Aucun résultat ne correspond a votre requête !";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
return $retour;
}
 
private function rechercher() {
$resultats = array();
$resultats = $this->ontologieDao->rechercher();
$this->termes = $resultats;
$this->nbreTotalTermes = $this->ontologieDao->recupererNombreTermesTotal();
}
 
private function avoirResultats() {
$resultat = ($this->nbreTotalTermes == 0) ? false : true;
return $resultat;
}
 
private function trierResultats() {
$recherche = $this->parametres->get('recherche');
if ($recherche == 'floue') {
$this->termes = $this->ontologieDao->trierResultatsFloue($this->termes);
}
}
 
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->termes as $terme) {
$id = $terme['id_terme'];
$termesFormates[$id] = $this->formaterTerme($terme);
}
return $termesFormates;
}
 
private function formaterTerme($infos) {
$termeAFormater = new OntologieDO($infos);
$this->ontologieFormateur->setTermeAFormater($termeAFormater);
$this->ontologieFormateur->setChampsRetour($this->parametres->getListe('retour.champs'));
$terme = $this->ontologieFormateur->formaterListe();
return $terme;
}
 
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->nbreTotalTermes;
if ($hrefPrecedent = $this->formaterEnteteHrefPrecedent()) {
$entete['href.precedent'] = $hrefPrecedent;
}
if ($hrefSuivant = $this->formaterEnteteHrefSuivant()) {
$entete['href.suivant'] = $hrefSuivant;
}
return $entete;
}
 
private function formaterEnteteMasque() {
$masquesStrictes = array('code');
$paramsMasque = array(
'' => 'terme',
'code' => 'id_terme',
'nom' => 'terme',
'description' => 'definition');
$etendre = ($this->parametres->get('recherche') == 'etendue') ? true : false;
 
$masqueComplet = array();
foreach ($paramsMasque as $masqueType => $champ) {
$masqueParam = 'masque'.($masqueType != '' ? '.'.$masqueType : $masqueType);
if ($this->parametres->exister($masqueParam)) {
$masqueValeur = $this->parametres->get($masqueParam);
$masque = "$champ=$masqueValeur";
$masque .= ($etendre && in_array($masqueType, $masquesStrictes) === false) ? '%' : '';
 
$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->nbreTotalTermes) {
$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/bibliotheque/Conteneur.php
34,6 → 34,65
$this->parametres[$cle] = $valeur;
}
 
public function getParametresUrl() {
if (!isset($this->partages['Parametres'])){
$this->partages['Parametres'] = new Parametres($this->parametres['parametres'], $this->getBdd());
}
return $this->partages['Parametres'];
}
 
public function getParametresUrlVerificateur() {
if (!isset($this->partages['ParametresVerificateur'])){
$parametres = $this->getParametresUrl();
$parametresAPI = $this->getParametreTableau('parametresAPI');
$this->partages['ParametresVerificateur'] = new ParametresVerificateur($parametres, $parametresAPI);
}
return $this->partages['ParametresVerificateur'];
}
 
public function getRessourcesUrl() {
if (!isset($this->partages['Ressources'])){
$this->partages['Ressources'] = new Ressources($this->parametres['ressources']);
}
return $this->partages['Ressources'];
}
 
public function getRessourcesUrlVerificateur() {
if (!isset($this->partages['RessourcesVerificateur'])){
$ressources = $this->getRessourcesUrl();
$projetsDispo = $this->getParametreTableau('projetsDispo');
$servicesDispo = $this->getParametreTableau('servicesDispo');
$this->partages['RessourcesVerificateur'] = new RessourcesVerificateur($ressources, $projetsDispo, $servicesDispo);
}
return $this->partages['RessourcesVerificateur'];
}
 
public function getUrlFormatage() {
if (!isset($this->partages['UrlFormatage'])){
$Bdd = $this->getBdd();
$this->partages['UrlFormatage'] = new UrlFormatage($Bdd);
}
return $this->partages['UrlFormatage'];
}
 
public function getRequetesAssemblage() {
if (!isset($this->partages['RequetesAssemblage'])){
$this->partages['RequetesAssemblage'] = new RequetesAssemblage($this->getBdd());
}
return $this->partages['RequetesAssemblage'];
}
 
 
public function getVersionVerificateur() {
if (!isset($this->partages['VersionVerificateur'])){
$ressources = $this->getRessourcesUrl();
$parametres = $this->getParametresUrl();
$versions = $this->getVersions();
$this->partages['VersionVerificateur'] = new VersionVerificateur($ressources, $parametres, $versions);
}
return $this->partages['VersionVerificateur'];
}
 
public function getBdd() {
if (!isset($this->partages['Bdd'])){
$this->partages['Bdd'] = new Bdd();
46,6 → 105,17
return $cache;
}
 
public function getVersions() {
if (!isset($this->partages['Versions'])){
$parametres = $this->getParametresUrl();
$ressources = $this->getRessourcesUrl();
$bdd = $this->getBdd();
$versions = new Versions($parametres, $bdd);
$this->partages['Versions'] = $versions;
}
return $this->partages['Versions'];
}
 
public function getWikipediaBot($options = array()) {
$wpBot = new WikipediaBot($options);
return $wpBot;
55,5 → 125,24
$url = new Url($url);
return $url;
}
 
public function getServiceGenerique() {
$ressources = $this->getRessourcesUrl();
$classe = $ressources->getServiceClasse();
$classeGenerique = $classe.'Generique';
if ($ressources->getServiceNom() == 'noms' || $ressources->getServiceNom() == 'taxons') {
$service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getNomDao(), $this->getNomFormateur());
if ($classe == 'NomsListe') {
$service->setListeUrl($this->getParametre('listeUrl'));
}
} else if ($ressources->getServiceNom() == 'ontologies') {
$service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getOntologiesDao(), $this->getOntologiesFormateur());
if ($classe == 'OntologiesListe') {
$service->setListeUrl($this->getParametre('listeUrlOntologies'));
}
}
 
return $service;
}
}
?>
/trunk/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;
}
}
?>
/trunk/services/bibliotheque/nom/decorateurs/NomResponsabilite.php
New file
0,0 → 1,5
<?php
interface NomResponsabilite {
public function traiterChampsRetour(Array $champsRetour);
}
?>
/trunk/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;
}
}
}
?>
/trunk/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;
}
}
?>
/trunk/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;
}
}
?>
/trunk/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;
}
}
}
}
?>
/trunk/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;
}
}
?>
/trunk/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;
}
}
?>
/trunk/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'];
}
}
?>
/trunk/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);
}
}
}
?>
/trunk/services/bibliotheque/Parametres.php
New file
0,0 → 1,124
<?php
// TODO : il est peut être nécessaire de mieux distinguer les attributs parametres et parametresOrigine
// TODO : déplacer les méthodes getMasquePourBdd et getPourBdd dans les DAO
class Parametres implements Iterator {
 
private $parametres = array();
private $parametresOrigine = array();
private $parametresTypeEntier = array('navigation.limite', 'navigation.depart');
private $bdd = null;
 
public function __construct(Array $parametres, Bdd $bdd) {
$this->parametresOrigine = $parametres;
$this->parametres = $this->parametresOrigine;
$this->bdd = $bdd;
$this->definirValeursParDefaut();
}
 
public function current () {
return current($this->parametresOrigine);
}
 
public function key() {
return key($this->parametresOrigine);
}
 
public function next() {
return next($this->parametresOrigine);
}
 
public function rewind() {
return reset($this->parametresOrigine);
}
 
public function valid() {
return current($this->parametresOrigine) == false ? false : true;
}
 
public function get($parametreCode) {
$valeur = '';
if ($this->exister($parametreCode)) {
$valeur = $this->parametres[$parametreCode];
}
return $this->etreParametreDeTypeEntier($parametreCode) ? (int) $valeur : $valeur;
}
 
private function etreParametreDeTypeEntier($parametreCode) {
$entier = in_array($parametreCode, $this->parametresTypeEntier) ? true : false;
return $entier;
}
 
public function getListe($parametreCode) {
$valeurs = array();
if ($this->exister($parametreCode)) {
$valeurs = explode(',', $this->parametres[$parametreCode]);
$valeurs = array_map('trim', $valeurs);
}
return $valeurs;
}
 
public function exister($parametreCode) {
$existe = false;
if (array_key_exists($parametreCode, $this->parametres) && $this->parametres[$parametreCode] != '') {
$existe = true;
}
return $existe;
}
 
public function getPourBdd($parametreCode) {
$valeur = false;
if ($this->exister($parametreCode)) {
$valeur = $this->get($parametreCode);
$valeur = $this->proteger($valeur);
}
return $valeur;
}
 
private function proteger($valeur) {
$valeur = $this->bdd->proteger($valeur);
return $valeur;
}
 
public function getMasquePourBdd($type = '') {
$masque = false;
$parametreMasque = 'masque'.($type != '' ? '.'.$type : $type);
if ($this->exister($parametreMasque)) {
$masque = $this->get($parametreMasque);
$recherche = $this->get('recherche');
if ($recherche == 'etendue') {
$masque = str_replace(' ', '% ', $masque);
$masque .= '%';
}
$masque = $this->proteger($masque);
}
return $masque;
}
 
private function definirValeursParDefaut() {
if ($this->exister('recherche') == false) {
$this->parametres['recherche'] = 'stricte';
}
if ($this->exister('ns.format') == false) {
$this->parametres['ns.format'] = 'txt';
}
if ($this->exister('retour') == false) {
$this->parametres['retour'] = 'application/json';
}
if ($this->exister('retour.format') == false) {
$this->parametres['retour.format'] = 'max';
}
if ($this->exister('retour.langue') == false) {
$this->parametres['retour.langue'] = 'fr';
}
if ($this->exister('version.projet') == false) {
$this->parametres['version.projet'] = '+';
}
if ($this->exister('navigation.depart') == false) {
$this->parametres['navigation.depart'] = (int) 0;
}
if ($this->exister('navigation.limite') == false) {
$this->parametres['navigation.limite'] = (int) 100;
}
}
}
?>
/trunk/services/bibliotheque/Projet.php
New file
0,0 → 1,135
<?php
class Projet {
private $ressources = null;
private $paramsVerif = null;
private $ressourcesVerif = null;
private $versionVerif = null;
private $cheminBase = '';
private $cheminConfig = '';
private $cheminBiblio = '';
private $serviceGenerique = '';
 
public function __construct(Ressources $ressources) {
$this->ressources = $ressources;
}
 
public function setCheminBase($chemin) {
$this->cheminBase = $chemin;
}
 
public function setCheminConfig($chemin) {
$this->cheminConfig = $chemin;
}
 
public function setCheminBiblio($chemin) {
$this->cheminBiblio = $chemin;
}
 
public function setParamsVerif($paramsVerificateur) {
$this->paramsVerif = $paramsVerificateur;
}
 
public function setVersionVerif($versionVerificateur) {
$this->versionVerif = $versionVerificateur;
}
 
public function setRessourcesVerif($ressourcesVerificateur) {
$this->ressourcesVerif = $ressourcesVerificateur;
}
 
public function setServiceGenerique($generique) {
$this->serviceGenerique = $generique;
}
 
public function initialiser() {
$this->chargerConfig();
// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services
if (phpversion() < 5.3) {
spl_autoload_register(array($this, 'chargerClasseProjet'));
} else {
spl_autoload_register(array($this, 'chargerClasseProjet'), true , true);
}
}
 
private function chargerConfig() {
$projet = $this->getNom();
$chemin = $this->cheminConfig."config_$projet.ini";
Config::charger($chemin);
}
 
public function getNom() {
return $this->ressources->getProjetNom();
}
 
public function getClasse() {
return $this->ressources->getServiceClasse().ucfirst($this->getNom());
}
 
private function chargerClasseProjet($classe) {
if (class_exists($classe)) {
return null;
}
 
$chemins = array();
$chemins[] = $this->cheminBase.$this->getNom().DS;
$chemins[] = $this->cheminBase.'commun'.DS;
$chemins[] = $this->cheminBiblio;
$chemins[] = $this->cheminBiblio.'generique'.DS;
$chemins[] = $this->cheminBiblio.'interfaces'.DS;
$chemins[] = $this->cheminBiblio.'nom'.DS;
$chemins[] = $this->cheminBiblio.'nom'.DS.'decorateurs'.DS;
$chemins[] = $this->cheminBiblio.'ontologie'.DS;
$chemins[] = $this->cheminBiblio.'ontologie'.DS.'decorateurs'.DS;
 
foreach ($chemins as $chemin) {
$chemin = $chemin.$classe.'.php';
if (file_exists($chemin)) {
require_once $chemin;
}
}
}
 
public function verifier() {
$this->paramsVerif->verifier();
$this->ressourcesVerif->verifier();
$this->versionVerif->verifier();
$this->verifierExistanceServiceClasse();
}
 
private function verifierExistanceServiceClasse() {
$classe = $this->getClasse();
$existe = $this->verifierExistanceClasseDuProjet($classe);
 
if ($existe === false) {
$service = $this->ressources->getServiceNom();
$projet = $this->getNom();
$message = "La classe du service demandé '$service' n'existe pas dans le projet '$projet' !";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
}
 
private function verifierExistanceClasseDuProjet($classe) {
$chemins = array();
$chemins[] = $this->cheminBase.$this->getNom().DS.$classe.'.php';
$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php';
 
$existe = false;
foreach ($chemins as $chemin) {
if (file_exists($chemin)) {
$existe = true;
break;
}
}
return $existe;
}
 
public function consulter() {
$serviceNom = $this->getClasse();
$service = new $serviceNom($this->serviceGenerique);
$retour = $service->consulter();
return $retour;
}
 
}
?>
/trunk/services/bibliotheque/RessourcesVerificateur.php
New file
0,0 → 1,51
<?php
class RessourcesVerificateur {
 
private $ressources = null;
private $projetsDispo = array();
private $servicesDispo = array();
 
public function __construct(Ressources $ressources, Array $projetsDispo, Array $servicesDispo) {
$this->ressources = $ressources;
$this->projetsDispo = $projetsDispo;
$this->servicesDispo = $servicesDispo;
}
 
public function verifier() {
$this->verifierPresenceRessources();
$this->verifierPresenceProjet();
$this->verifierPresenceService();
}
 
private function verifierPresenceRessources() {
if ($this->ressources->getNombre() == 0) {
$message = "Aucune ressource n'a été indiquée.\n".
"Veuillez indiquer au moins un code de projet et un type de service.";
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($message, $code);
}
}
 
private function verifierPresenceProjet() {
$projet = $this->ressources->getProjetNom();
if (in_array($projet, $this->projetsDispo) === false) {
$message = "La ressource '$projet' n'indique pas un projet existant.\n".
"Les projets existant sont :\n".implode(', ', $this->projetsDispo);
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($message, $code);
}
}
 
private function verifierPresenceService() {
$service = $this->ressources->getServiceNom();
if (in_array($service, $this->servicesDispo) === false) {
$message = "La service demandé '$service' n'est pas disponible pour le projet '{$this->ressources->getProjetNom()}' !\n".
"Les services disponibles sont : ".implode(', ', $this->servicesDispo);
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
}
 
 
}
?>
/trunk/services/bibliotheque/Versions.php
New file
0,0 → 1,65
<?php
class Versions {
private $parametres = null;
private $ressources = null;
private $bdd = null;
private $projetNom = null;
private $versionsDispo = array();
private $versionCourrante = array();
 
public function __construct(Parametres $parametres, Ressources $ressources, Bdd $bdd) {
$this->parametres = $parametres;
$this->ressources = $ressources;
$this->bdd = $bdd;
$this->projetNom = $this->ressources->getProjetNom();
$this->versionsDispo = $this->chargerVersionsDisponibles();
}
 
private function chargerVersionsDisponibles() {
$tableMeta = $this->projetNom.'_meta';
$requete = "SELECT version FROM $tableMeta";
$resultat = $this->bdd->recupererTous($requete);
if ($resultat == '') {
//cas ou la requete comporte des erreurs
$message = "La requête SQL de versionnage formée comporte une erreur : $requete";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
} elseif ($resultat === false) {
$message = "Versions introuvables dans la table des méta-données";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
} else {
foreach ($resultat as $version) {
$versionsDispo[] = $version['version'];
}
}
 
return $versionsDispo;
}
 
public function getVersions() {
$versions = array();
$versionDemandee = $this->parametres->get('version.projet');
if ($versionDemandee == '+') {
$versions[] = end($this->versionsDispo);
} else if (is_numeric($versionDemandee)) {
if (in_array($versionDemandee, $this->versionsDispo)) {
$versions[] = $versionDemandee;
}
} else if ($versionDemandee == '*') {
$versions = $this->versionsDispo;
}
$versions = $this->remplacerPointParUnderscore($versions);
return $versions;
}
 
private function remplacerPointParUnderscore($versions) {
if (count($versions) > 0) {
foreach ($versions as $cle => $valeur) {
$versions[$cle] = str_replace('.', '_', $valeur);
}
}
return $versions;
}
}
?>
/trunk/services/bibliotheque/ontologie/OntologieDO.php
New file
0,0 → 1,21
<?php
class OntologieDO {
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;
}
}
?>
/trunk/services/bibliotheque/ontologie/OntologieDAO.php
New file
0,0 → 1,202
<?php
class OntologieDAO {
private $bdd = null;
private $versions = null;
private $requeteNbreTermesTotal = null;
private $masquesStrictes = array();
private $paramsMasque = array();
 
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd, Versions $versions) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->bdd = $bdd;
$this->versions = $versions;
$this->masquesStrictes = array('code');
$this->paramsMasque = array(
'' => 'nom',
'code' => 'id_terme',
'nom' => $this->getChampPourLangue('nom'),
'description' => $this->getChampPourLangue('description'));
}
 
public function getDetails() {
$table = $this->getTableTerme();
$tableType = $this->getTableType();
$detailsId = $this->ressources->getDetailsId();
$detailsId = $this->bdd->proteger($detailsId);
$requete =
'SELECT o.*, type '.
"FROM $table AS o ".
" LEFT JOIN $tableType ON (ce_type = id_type) ".
"WHERE id_terme = $detailsId ";
$resultats = $this->bdd->recuperer($requete);
$terme = new OntologieDO($resultats);
return $terme;
}
 
public function rechercher() {
$clause = $this->getClauseSelectSpeciale();
$table = $this->getTableTerme();
$tableType = $this->getTableType();
$tablePublication = $this->getTablePublication();
$tableAuteur = $this->getTableAuteur();
$tableImage = $this->getTableImage();
$conditions = $this->getConditions();
$where = $this->getWhere($conditions);
$ordre = $this->getOrdre();
$navigation = $this->getNavigation();
 
$requete = "SELECT $clause o.*, t.type, p.*, a.*, i.* ".
"FROM $table AS o ".
" LEFT JOIN $tableType AS t ON (ce_type = id_type) ".
" LEFT JOIN $tablePublication AS p ON (ce_publication = id_publication) ".
" LEFT JOIN $tableAuteur AS a ON (ce_auteur = id_auteur) ".
" LEFT JOIN $tableImage AS i ON (ce_image = id_image) ".
$where.' '.$conditions.' '.$ordre.' '.
"LIMIT $navigation ";
//die($requete);
$this->requeteNbreNomsTotal = $this->transformerRequetePourNbreTermesTotal($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 getTableTerme() {
return sprintf($this->getNomTableTpl(), 'terme');
}
 
private function getTableType() {
return sprintf($this->getNomTableTpl(), 'type');
}
 
private function getTablePublication() {
return sprintf($this->getNomTableTpl(), 'publication');
}
 
private function getTableAuteur() {
return sprintf($this->getNomTableTpl(), 'auteur');
}
 
private function getTableImage() {
return sprintf($this->getNomTableTpl(), 'image');
}
 
private function getTableHierarchie() {
return sprintf($this->getNomTableTpl(), 'hierarchie');
}
 
private function getNomTableTpl() {
$versions = $this->versions->getVersions();
$derniereVersion = end($versions);
$projetNom = strtolower($this->ressources->getProjetNom());
return $projetNom.'_ontologies_%s_v'.$derniereVersion;
}
 
private function getConditions() {
$operateurParDefaut = $this->getOperateurCondition();
$conditionsSql = array();
foreach ($this->paramsMasque as $typeMasque => $champ) {
$operateur = in_array($typeMasque, $this->masquesStrictes) ? '=' : $operateurParDefaut;
if ($valeurMasque = $this->parametres->getMasquePourBdd($typeMasque)) {
if ($operateur == 'SOUNDEX') {
$tpl = '(SOUNDEX(%s) = SOUNDEX(%s)) OR (SOUNDEX(REVERSE(%s)) = SOUNDEX(REVERSE(%s))) ';
$conditionsSql[] = sprintf($tpl, $champ, $valeurMasque, $champ, $valeurMasque);
} else {
$conditionsSql[] = "$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';
} else if ($recherche == 'floue') {
$operateur = 'SOUNDEX';
}
return $operateur;
}
 
private function getWhere($conditions = '') {
$where = '';
if ($conditions != '') {
$where = 'WHERE ';
}
return $where;
}
 
private function getOrdre() {
$champNom = $this->getChampPourLangue('nom');
$ordre = "ORDER BY $champNom ASC ";
return $ordre;
}
 
private function getChampPourLangue($champ) {
$lg = $this->parametres->get('retour.langue');
if ($lg == 'en') {
$champ .= '_en';
}
return $champ;
}
 
private function getNavigation() {
$debut = (int) $this->parametres->get('navigation.depart');
$nbre = $this->parametres->get('navigation.limite');
$navigation = "$debut,$nbre";
return $navigation;
}
 
private function transformerRequetePourNbreTermesTotal($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 trierResultatsFloue($termes) {
foreach ($this->paramsMasque as $typeMasque => $champ) {
if ($termeDemande = $this->parametres->getMasquePourBdd($typeMasque)) {
$termeDemandeSimple = strtolower(Chaine::supprimerAccents($termeDemande));
 
foreach ($termes as $id => $terme) {
$termeFlouSimple = strtolower(Chaine::supprimerAccents($terme[$this->getChampPourLangue('nom')]));
// Prime pour la ressemblance globale :
$leven = levenshtein($termeFlouSimple, $termeDemandeSimple);
// On affine
$similar = similar_text($termeDemandeSimple, $termeFlouSimple) * 3;
// Prime Soundex
$soundex = (soundex($termeDemandeSimple) == soundex($termeFlouSimple)) ? 1000 : 0;
// Calcul du score
$score = 500 - $leven + $similar + $soundex;
 
$termes[$id]['score'] = $score;
$termes[$id]['score_calcul'] = "$termeDemandeSimple / $termeFlouSimple : 500 - $leven + $similar + $soundex = $score";
}
$termes = Tableau::trierMD($termes, array('score' => SORT_DESC));
}
}
//echo 'ici<pre>'.print_r($termes, true).'</pre>';die();
return $termes;
}
 
public function recupererNombreTermesTotal() {
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'];
}
}
?>
/trunk/services/bibliotheque/ontologie/OntologieFormateur.php
New file
0,0 → 1,89
<?php
class OntologieFormateur {
 
private $termeAFormater = null;
private $decorateurs = array();
private $bdd = null;
private $champsProjet = array();
private $champsRetour = null;
private $detailsHrefTpl = null;
private $langueDemandee = null;
 
public function setTermeAFormater(OntologieDO $ontologieDO) {
$this->termeAFormater = $ontologieDO;
}
 
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 setLangueDemandee($langue) {
$this->langueDemandee = $langue;
}
 
public function setBdd($bdd) {
$this->bdd = $bdd;
}
 
public function formaterDetails() {
$termeDeco = new OntologieDecorateur($this->termeAFormater, $this->detailsHrefTpl, $this->langueDemandee);
$projetDeco = new OntologieChampsProjetDecorateur($termeDeco, $this->champsProjet);
 
if ($this->avoirDemandeChampsRetour()) {
$this->decorateurs[] = $termeDeco;
$this->decorateurs[] = $projetDeco;
 
$this->traiterChampsRetour();
} else {
$termeDeco->ajouterId();
$termeDeco->ajouterIntitule();
$termeDeco->ajouterDescription();
$termeDeco->ajouterClasseId();
$termeDeco->ajouterClasse();
$termeDeco->ajouterClasseHref();
 
$projetDeco->ajouterChampsSupplementaires();
}
 
return $termeDeco->getTermeFormate();
}
 
public function formaterListe() {
$termeDeco = new OntologieDecorateur($this->termeAFormater, $this->detailsHrefTpl, $this->langueDemandee);
$termeDeco->ajouterId();
$termeDeco->ajouterIntitule();
$termeDeco->ajouterHref();
 
if ($this->avoirDemandeChampsRetour()) {
$this->decorateurs[] = $termeDeco;
$this->decorateurs[] = new OntologieChampsProjetDecorateur($termeDeco, $this->champsProjet);
 
$this->traiterChampsRetour();
}
 
return $termeDeco->getTermeFormate();
}
 
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);
}
}
}
?>
/trunk/services/bibliotheque/ontologie/decorateurs/OntologieChampsProjetDecorateur.php
New file
0,0 → 1,38
<?php
class OntologieChampsProjetDecorateur extends OntologieDecorateur {
 
private $ontologieDecorateur = null;
private $champs = array();
protected $correspondances = array();
 
public function __construct(OntologieDecorateur $ontologieDecorateur, Array $champs) {
$this->ontologieDecorateur = $ontologieDecorateur;
$this->champs = $champs;
$this->correspondances = array_flip($this->champs);
}
 
public function traiterChampsRetour(Array $champsRetour) {
//die(print_r($this->correspondances,true));
foreach ($champsRetour as $champ) {
if (array_key_exists($champ, $this->correspondances)) {
$champBdd = $this->correspondances[$champ];
$champSortie = $champ;
//die(print_r($this->ontologieDecorateur->terme,true));
if ($this->ontologieDecorateur->terme->verifierTag($champBdd)) {
$valeur = $this->ontologieDecorateur->terme->getTag($champBdd);
$this->ontologieDecorateur->termeFormate[$champSortie] = $valeur;
}
}
}
}
 
public function ajouterChampsSupplementaires() {
foreach ($this->champs as $champBdd => $champSortie) {
if ($this->ontologieDecorateur->terme->verifierTag($champBdd)) {
$valeur = $this->ontologieDecorateur->terme->getTag($champBdd);
$this->ontologieDecorateur->termeFormate[$champSortie] = $valeur;
}
}
}
}
?>
/trunk/services/bibliotheque/ontologie/decorateurs/OntologieDecorateur.php
New file
0,0 → 1,92
<?php
class OntologieDecorateur implements OntologieResponsabilite {
protected $terme = null;
protected $termeFormate = array();
private $detailsHrefTpl = null;
private $langueDemandee = null;
protected $correspondances = array(
'id' => 'Id',
'nom' => 'Intitule',
'description' => 'Description',
'href' => 'Href',
'classe' => 'Classe',
'classe.id' => 'ClasseId',
'classe.href' => 'ClasseHref',
'classe.*' => 'ClasseId,Classe,ClasseHref');
 
public function __construct(OntologieDO $termeADecorer, $detailsHrefTpl, $langueDemandee) {
$this->terme = $termeADecorer;
$this->detailsHrefTpl = $detailsHrefTpl;
$this->langueDemandee = $langueDemandee;
$this->initialiserTermeFormate();
}
 
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->termeFormate['id'] = (int) $this->terme->getTag('id_terme');
}
 
public function ajouterIntitule() {
if ($this->langueDemandee == 'en') {
$this->termeFormate['nom'] = $this->terme->getTag('nom_en');
} else {
$this->termeFormate['nom'] = $this->terme->getTag('nom');
}
}
 
public function ajouterDescription() {
if ($this->langueDemandee == 'en') {
if ($this->terme->verifierTag('description_en')) {
$this->termeFormate['description'] = $this->terme->getTag('description_en');
}
} else {
if ($this->terme->verifierTag('description')) {
$this->termeFormate['description'] = $this->terme->getTag('description');
}
}
}
 
public function ajouterHref() {
if ($this->terme->verifierTag('id_terme')) {
$href = sprintf($this->detailsHrefTpl, $this->terme->getTag('id_terme'));
$this->termeFormate['href'] = $href;
}
}
 
public function ajouterClasseId() {
$this->termeFormate['classe.id'] = (int) $this->terme->getTag('ce_type');
}
 
public function ajouterClasse() {
$this->termeFormate['classe'] = (string) $this->terme->getTag('type');
}
 
public function ajouterClasseHref() {
if ($this->terme->verifierTag('ce_type')) {
$href = sprintf($this->detailsHrefTpl, $this->terme->getTag('ce_type'));
$this->termeFormate['classe.href'] = $href;
}
}
 
public function initialiserTermeFormate() {
$this->termeFormate = array();
}
 
public function getTermeFormate() {
return $this->termeFormate;
}
}
?>
/trunk/services/bibliotheque/ontologie/decorateurs/OntologieResponsabilite.php
New file
0,0 → 1,5
<?php
interface OntologieResponsabilite {
public function traiterChampsRetour(Array $champsRetour);
}
?>
/trunk/services/bibliotheque/Requete.php
New file
0,0 → 1,12
<?php
 
class Requete {
 
public $champs_recherches = " * ";
public $table = "";
public $requete_condition = "";
public $requete_jointure = "";
public $limite_requete = array('depart' => 0, 'limite' => 100);
public $limite_besoin = false;
}
?>
/trunk/services/bibliotheque/ParametresVerificateur.php
New file
0,0 → 1,99
<?php
class ParametresVerificateur {
private $parametres = null;
private $parametresApi = array();
private $erreursParametres = array();
private $typesVerif = array(
'recherche' => 'Simple',
'ns.format' => 'Simple',
'retour' => 'Simple',
'retour.format' => 'Simple',
'retour.langue' => 'RegExp',
'ns.structure' => 'Multiple',
'version.projet' => 'RegExp'
);
private $valeursPermises = array(
'recherche' => 'stricte|floue|etendue',
'ns.format' => 'htm|txt',
'retour' => 'application/json|image/jpeg',
'retour.format' => 'min|max|oss|perso',
'retour.langue' => '/^(?:[*]|orig|[a-z]{2})$/',
'ns.structure' => '|an|au|bib|ad',
'version.projet' => '/^(?:[0-9]+[.][0-9]+|[*+])$/'
);
 
public function __construct(Parametres $parametres, Array $parametresApi) {
$this->parametres = $parametres;
$this->parametresApi = $parametresApi;
}
 
public function verifier() {
$this->verifierConformiteApi();
$this->verifierValeurs();
}
 
public function verifierConformiteApi() {
$this->parametres->rewind();
while (is_null($parametre = $this->parametres->key()) === false) {
if (in_array($parametre, $this->parametresApi) === false) {
$message = "Le paramètre '$parametre' n'est pas pris en compte par cette version de l'API.";
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($message, $code);
}
$this->parametres->next();
}
}
 
public function verifierValeurs() {
foreach ($this->typesVerif as $parametre => $type) {
$methode = "verifierValeur$type";
$this->$methode($parametre);
}
 
if (count($this->erreursParametres) > 0) {
array_unshift($this->erreursParametres, 'Erreur dans le paramètrage de votre URL :');
$message = implode('<br/>', $this->erreursParametres);
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($message, $code);
}
}
 
private function verifierValeurSimple($parametre) {
$valeur = $this->parametres->get($parametre);
$valeursPermises = $this->valeursPermises[$parametre];
$permissionOk = $this->verifierValeursPermises($valeur, $valeursPermises);
if ($permissionOk == false) {
$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $valeursPermises";
}
}
 
private function verifierValeursPermises($valeur, $valeursPermises) {
$permise = false;
if (in_array($valeur, explode('|', $valeursPermises))) {
$permise = true;
}
return $permise;
}
 
private function verifierValeurRegExp($parametre) {
$valeur = $this->parametres->get($parametre);
$regexp = $this->valeursPermises[$parametre];
$permissionOk = preg_match($regexp, $valeur) ? true : false;
if ($permissionOk == false) {
$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $regexp";
}
}
 
private function verifierValeurMultiple($parametre) {
$valeursConcatenees = $this->parametres->get($parametre);
$valeursPermises = $this->valeursPermises[$parametre];
$valeurs = explode(',', $valeursConcatenees);
foreach ($valeurs as $valeur) {
$permissionOk = $this->verifierValeursPermises($valeur, $valeursPermises);
if ($permissionOk == false) {
$this->erreursParametres[] = "Le paramètre '$parametre' ne peut pas prendre la valeur '$valeur'. Valeurs permises : $valeursPermises";
}
}
}
}
?>
/trunk/services/bibliotheque/RequetesAssemblage.php
New file
0,0 → 1,90
<?php
 
/** FONCTIONS D'ASSEMBLAGE DE REQUETE
*
* @package eflore-projets
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @version 1.0
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
*/
 
class RequetesAssemblage {
private $table;
private $total_resultat;
private $Bdd;
private $condition;
public function __construct(BDD $bdd) {
$this->Bdd = $bdd;
}
 
public function getTotal_resultat() {
return $this->total_resultat;
}
public function retournerRequeteJointure($requete_jointure) {
$jointure = '';
if ($requete_jointure !== "") {
foreach ($requete_jointure as $req_j) {
$jointure .= ' '.$req_j['type'].' '.$req_j['table'].' ON '
.implode(' AND', $req_j['on']);
}
}
return $jointure;
}
 
public function assemblerLaRequete(Requete $requete_param) {
$this->table = $requete_param->table;
$requete_jointure = $this->retournerRequeteJointure($requete_param->requete_jointure);
$this->condition = $this->retournerRequeteCondition($requete_param->requete_condition);
$limites = $this->delimiterResultatsRequete($requete_param->limite_besoin, $requete_param->limite_requete);
$requete = ' SELECT '.$requete_param->champs_recherches.' FROM '.$requete_param->table.' '
.$requete_jointure .' '.$this->condition.' '.$limites;
return $requete;
}
 
public function retournerRequeteCondition($requete_condition) {
$condition = '';
if ($requete_condition !== "") {
$condition = ' WHERE '.implode(' AND ', $requete_condition);
}
return $condition;
}
 
public function calculerTotalResultat() {
$requete = 'SELECT count(*) as nombre FROM '.$this->table.' '.$this->condition;
$res = $this->Bdd->recuperer($requete);
if ($res) {
$this->total_resultat = $res['nombre'];
} else {
$this->total_resultat = 0;
$e = 'Données introuvables dans la base';
throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
}
}
 
public function delimiterResultatsRequete($limite_besoin, $limite_requete) {
$this->calculerTotalResultat();
$requete_limite = '';
if ($limite_besoin) {
if (($limite_requete['depart'] <= $this->total_resultat) ){
if (($limite_requete['limite'] + $limite_requete['depart'] )
< $this->total_resultat ){
$requete_limite = 'LIMIT '.$limite_requete['depart'].', '
.$limite_requete['limite'];
}
} else {
$e = "Erreur : la valeur pour le paramètre navigation.départ est supérieure".
" au nombre total de résultats.";
throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
}
}
return $requete_limite;
}
}
?>