/trunk/services/modules/0.2/Projets.php |
---|
New file |
0,0 → 1,56 |
<?php |
/** |
* Description : |
* Classe principale de chargement des services d'eFlore. |
* |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* @package eflore-projets |
* @author Jennifer DHÉ <jennifer.dhe@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 0.1 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org) |
*/ |
class Projets extends RestService { |
private $conteneur = null; |
public function __construct() { |
$this->utilisationParametresBruts = true; |
} |
public function consulter($ressources, $parametres) { |
$resultat = ''; |
$reponseHttp = new ReponseHttp(); |
try { |
$this->initialiserConteneur($ressources, $parametres); |
$resultat = $this->executerProjetService(); |
$reponseHttp->setResultatService($resultat); |
} catch (Exception $e) { |
$reponseHttp->ajouterErreur($e); |
} |
$reponseHttp->emettreLesEntetes(); |
$corps = $reponseHttp->getCorps(); |
return $corps; |
} |
private function initialiserConteneur($ressources, $parametres) { |
$this->conteneur = new Conteneur(); |
$this->conteneur->setParametre('ressources', $ressources); |
$this->conteneur->setParametre('parametres', $parametres); |
$this->conteneur->setParametre('cheminBase', dirname(__FILE__).DS); |
} |
private function executerProjetService() { |
$projet = $this->conteneur->getProjet(); |
$projet->verifier(); |
$classe = $projet->getServiceClasseNom(); |
$service = $this->conteneur->getService($classe); |
$retour = $service->consulter(); |
return $retour; |
} |
} |
?> |
/trunk/services/modules/0.2/bdtfx/NomsListe.php |
---|
New file |
0,0 → 1,251 |
<?php |
class NomsListe { |
private $parametres = null; |
private $ressources = null; |
private $bdd = null; |
private $listeUrl = null; |
private $detailsHrefTpl = null; |
private $nbreTotalNoms = 0; |
private $noms = array(); |
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
$this->bdd = $bdd; |
} |
public function setDetailsHrefTpl($tpl) { |
$this->detailsHrefTpl = $tpl; |
} |
public function setListeUrl($url) { |
$this->listeUrl = $url; |
} |
public function consulter() { |
$this->noms = $this->rechercher(); |
$this->nbreNomsTotal = $this->recupererNombreNomsTotal(); |
$this->trierNoms(); |
$retour = $this->construireTableauRetour(); |
return $retour; |
} |
private function rechercher() { |
$resultats = array(); |
$recherche = $this->parametres->get('recherche'); |
if ($recherche == 'stricte') { |
$resultats = $this->rechercherStricte(); |
} else if ($recherche == 'etendue') { |
$resultats = $this->rechercherEtendue(); |
} else if ($recherche == 'floue') { |
$resultats = $this->rechercherFloue(); |
} |
return $resultats; |
} |
private function rechercherStricte() { |
$conditions = array(); |
if ($masque = $this->parametres->getMasquePourBdd()) { |
$conditions[] = "nom_sci = $masque"; |
} |
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) { |
$conditions[] = "nom_supra_generique = $masqueSg"; |
} |
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) { |
$conditions[] = "genre = $masqueGen"; |
} |
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) { |
$conditions[] = "epithete_sp = $masqueSp"; |
} |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '. |
' num_nom, nom_sci, num_nom_retenu '. |
'FROM bdtfx_v1_01 '. |
(count($conditions) > 0 ? 'WHERE ' : ''). |
implode(' AND ', $conditions). |
'ORDER BY nom_sci ASC '. |
'LIMIT 0,100'; |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function rechercherEtendue() { |
$conditions = array(); |
if ($masque = $this->parametres->getMasquePourBdd()) { |
$conditions[] = "nom_sci LIKE $masque"; |
} |
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) { |
$conditions[] = "nom_supra_generique LIKE $masqueSg"; |
} |
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) { |
$conditions[] = "genre LIKE $masqueGen"; |
} |
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) { |
$conditions[] = "epithete_sp LIKE $masqueSp"; |
} |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '. |
' num_nom, nom_sci, num_nom_retenu '. |
'FROM bdtfx_v1_01 '. |
(count($conditions) > 0 ? 'WHERE ' : ''). |
implode(' AND ', $conditions). |
'ORDER BY nom_sci ASC '. |
'LIMIT 0,100'; |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function rechercherFloue() { |
$masque = $this->parametres->getMasquePourBdd(); |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '. |
' num_nom, nom_sci, num_nom_retenu '. |
'FROM bdtfx_v1_01 '. |
($masque ? 'WHERE '. |
" (SOUNDEX(nom_sci) = SOUNDEX($masque)) ". |
" OR (SOUNDEX(REVERSE(nom_sci)) = SOUNDEX(REVERSE($masque))) " : ''). |
'ORDER BY nom_sci ASC '. |
'LIMIT 0,100'; |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function recupererNombreNomsTotal() { |
$requete = 'SELECT FOUND_ROWS() AS nbre'; |
$nombre = $this->bdd->recuperer($requete); |
return (int) $nombre['nbre']; |
} |
private function trierNoms() { |
$recherche = $this->parametres->get('recherche'); |
if ($recherche == 'floue') { |
$this->trierRechercheFloue(); |
} |
} |
public function trierRechercheFloue() { |
$nomDemande = $this->parametres->get('masque'); |
$nomDemandeSimple = strtolower(Chaine::supprimerAccents($nomDemande)); |
foreach ($this->noms as $id => $nom) { |
$nomFlouSimple = strtolower(Chaine::supprimerAccents($nom['nom_sci'])); |
// Prime pour la ressemblance globale : |
$score = 500 - levenshtein($nomFlouSimple, $nomDemandeSimple); |
// On affine |
$score += similar_text($nomDemandeSimple, $nomFlouSimple) * 3; |
$this->noms[$id]['score'] = $score; |
} |
$noms = $this->noms; |
$this->noms = Tableau::trierMD($noms, array('score' => false)); |
//print_r($this->noms); |
} |
private function construireTableauRetour() { |
$retour = array('entete' => array(), 'resultats' => array()); |
$retour['resultats'] = $this->construireResultats(); |
$retour['entete'] = $this->construireEntete(); |
return $retour; |
} |
private function construireResultats() { |
$nomsFormates = array(); |
foreach ($this->noms as $nom) { |
$id = $nom['num_nom']; |
$nomsFormates[$id] = $this->formaterNom($nom); |
} |
return $nomsFormates; |
} |
private function formaterNom($nom) { |
$nomFormate = array(); |
$nomformate['nom_sci'] = $nom['nom_sci']; |
$nomformate['retenu'] = ($nom['num_nom'] == $nom['num_nom_retenu']) ? true : false; |
$nomformate['href'] = $this->formaterHref($nom); |
return $nomformate; |
} |
private function formaterHref($nom) { |
$href = sprintf($this->detailsHrefTpl, $nom['num_nom']); |
return $href; |
} |
private function construireEntete() { |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0); |
$entete['masque'] = $this->formaterEnteteMasque(); |
$entete['depart'] = (int) $this->parametres->get('navigation.depart'); |
$entete['limite'] = (int) $this->parametres->get('navigation.limite'); |
$entete['total'] = $this->nbreNomsTotal; |
if ($hrefPrecedent = $this->formaterEnteteHrefPrecedent()) { |
$entete['href.precedent'] = $hrefPrecedent; |
} |
if ($hrefSuivant = $this->formaterEnteteHrefSuivant()) { |
$entete['href.suivant'] = $hrefSuivant; |
} |
return $entete; |
} |
private function formaterEnteteMasque() { |
$masqueComplet = array(); |
if ($this->parametres->exister('masque')) { |
$masque = ''; |
$masque .= 'nom_sci='.$this->parametres->get('masque'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
if ($this->parametres->exister('masque.sg')) { |
$masque = ''; |
$masque .= 'nom_supra_generique='.$this->parametres->get('masque.sg'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
if ($this->parametres->exister('masque.gen')) { |
$masque = ''; |
$masque .= 'genre='.$this->parametres->get('masque.gen'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
if ($this->parametres->exister('masque.sp')) { |
$masque = ''; |
$masque .= 'epithete_sp='.$this->parametres->get('masque.sp'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
return implode('&', $masqueComplet); |
} |
private function formaterEnteteHrefPrecedent() { |
$limite = $this->parametres->get('navigation.limite'); |
$departActuel = $this->parametres->get('navigation.depart'); |
$departPrecedent = $departActuel - $limite; |
$href = null; |
if ($departPrecedent >= 0) { |
$squelette = $this->listeUrl.'?navigation.depart=%s&navigation.limite=%s'; |
$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->listeUrl.'?navigation.depart=%s&navigation.limite=%s'; |
$href = sprintf($squelette, $departSuivant, $limite); |
} |
return $href; |
} |
} |
?> |
/trunk/services/modules/0.2/bdtfx/TaxonsListe.php |
---|
New file |
0,0 → 1,243 |
<?php |
class TaxonsListe { |
private $parametres = null; |
private $ressources = null; |
private $bdd = null; |
private $nbreTotalNoms = 0; |
private $noms = array(); |
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
$this->bdd = $bdd; |
} |
public function consulter() { |
$this->noms = $this->rechercher(); |
$this->nbreNomsTotal = $this->recupererNombreNomsTotal(); |
$this->trierNoms(); |
$retour = $this->construireTableauRetour(); |
return $retour; |
} |
private function rechercher() { |
$resultats = array(); |
$recherche = $this->parametres->get('recherche'); |
if ($recherche == 'stricte') { |
$resultats = $this->rechercherStricte(); |
} else if ($recherche == 'etendue') { |
$resultats = $this->rechercherEtendue(); |
} else if ($recherche == 'floue') { |
$resultats = $this->rechercherFloue(); |
} |
return $resultats; |
} |
private function rechercherStricte() { |
$conditions = array(); |
if ($masque = $this->parametres->getMasquePourBdd()) { |
$conditions[] = "nom_sci = $masque"; |
} |
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) { |
$conditions[] = "nom_supra_generique = $masqueSg"; |
} |
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) { |
$conditions[] = "genre = $masqueGen"; |
} |
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) { |
$conditions[] = "epithete_sp = $masqueSp"; |
} |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '. |
' num_nom, nom_sci '. |
'FROM fournier_v1_00 '. |
'WHERE num_nom = num_nom_retenu '. |
implode(' AND ', $conditions). |
'ORDER BY nom_sci ASC '. |
'LIMIT 0,100'; |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function rechercherEtendue() { |
$conditions = array(); |
if ($masque = $this->parametres->getMasquePourBdd()) { |
$conditions[] = "nom_sci LIKE $masque"; |
} |
if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) { |
$conditions[] = "nom_supra_generique LIKE $masqueSg"; |
} |
if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) { |
$conditions[] = "genre LIKE $masqueGen"; |
} |
if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) { |
$conditions[] = "epithete_sp LIKE $masqueSp"; |
} |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '. |
' num_nom, nom_sci, num_nom_retenu '. |
'FROM fournier_v1_00 '. |
'WHERE num_nom = num_nom_retenu '. |
implode(' AND ', $conditions). |
'ORDER BY nom_sci ASC '. |
'LIMIT 0,100'; |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function rechercherFloue() { |
$masque = $this->parametres->getMasquePourBdd(); |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '. |
' num_nom, nom_sci, num_nom_retenu '. |
'FROM fournier_v1_00 '. |
'WHERE num_nom = num_nom_retenu '. |
($masque ? 'AND '. |
" (SOUNDEX(nom_sci) = SOUNDEX($masque)) ". |
" OR (SOUNDEX(REVERSE(nom_sci)) = SOUNDEX(REVERSE($masque))) " : ''). |
'ORDER BY nom_sci ASC '. |
'LIMIT 0,100'; |
$resultats = $this->bdd->recupererTous($requete); |
return $resultats; |
} |
private function recupererNombreNomsTotal() { |
$requete = 'SELECT FOUND_ROWS() AS nbre'; |
$nombre = $this->bdd->recuperer($requete); |
return (int) $nombre['nbre']; |
} |
private function trierNoms() { |
$recherche = $this->parametres->get('recherche'); |
if ($recherche == 'floue') { |
$this->trierRechercheFloue(); |
} |
} |
public function trierRechercheFloue() { |
$nomDemande = $this->parametres->get('masque'); |
$nomDemandeSimple = strtolower(Chaine::supprimerAccents($nomDemande)); |
foreach ($this->noms as $id => $nom) { |
$nomFlouSimple = strtolower(Chaine::supprimerAccents($nom['nom_sci'])); |
// Prime pour la ressemblance globale : |
$score = 500 - levenshtein($nomFlouSimple, $nomDemandeSimple); |
// On affine |
$score += similar_text($nomDemandeSimple, $nomFlouSimple) * 3; |
$this->noms[$id]['score'] = $score; |
} |
$noms = $this->noms; |
$this->noms = Tableau::trierMD($noms, array('score' => false)); |
//print_r($this->noms); |
} |
private function construireTableauRetour() { |
$retour = array('entete' => array(), 'resultats' => array()); |
$retour['resultats'] = $this->construireResultats(); |
$retour['entete'] = $this->construireEntete(); |
return $retour; |
} |
private function construireResultats() { |
$nomsFormates = array(); |
foreach ($this->noms as $nom) { |
$id = $nom['num_nom']; |
$nomsFormates[$id] = $this->formaterNom($nom); |
} |
return $nomsFormates; |
} |
private function formaterNom($nom) { |
$nomFormate = array(); |
$nomformate['nom_sci'] = $nom['nom_sci']; |
$nomformate['retenu'] = ($nom['num_nom'] == $nom['num_nom_retenu']) ? true : false; |
$nomformate['href'] = $this->formaterHref($nom); |
return $nomformate; |
} |
private function formaterHref($nom) { |
$squelette = 'http://localhost/service:nel:0.1/fournier/taxons/%s'; |
$href = sprintf($squelette, $nom['num_nom_retenu']); |
return $href; |
} |
private function construireEntete() { |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0); |
$entete['masque'] = $this->formaterEnteteMasque(); |
$entete['depart'] = (int) $this->parametres->get('navigation.depart'); |
$entete['limite'] = (int) $this->parametres->get('navigation.limite'); |
$entete['total'] = $this->nbreNomsTotal; |
if ($hrefPrecedent = $this->formaterEnteteHrefPrecedent()) { |
$entete['href.precedent'] = $hrefPrecedent; |
} |
if ($hrefSuivant = $this->formaterEnteteHrefSuivant()) { |
$entete['href.suivant'] = $hrefSuivant; |
} |
return $entete; |
} |
private function formaterEnteteMasque() { |
$masqueComplet = array(); |
if ($this->parametres->exister('masque')) { |
$masque = ''; |
$masque .= 'nom_sci='.$this->parametres->get('masque'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
if ($this->parametres->exister('masque.sg')) { |
$masque = ''; |
$masque .= 'nom_supra_generique='.$this->parametres->get('masque.sg'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
if ($this->parametres->exister('masque.gen')) { |
$masque = ''; |
$masque .= 'genre='.$this->parametres->get('masque.gen'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
if ($this->parametres->exister('masque.sp')) { |
$masque = ''; |
$masque .= 'epithete_sp='.$this->parametres->get('masque.sp'); |
if ($this->parametres->get('recherche') == 'etendue') { |
$masque .= '%'; |
} |
$masqueComplet[] = $masque; |
} |
return implode('&', $masqueComplet); |
} |
private function formaterEnteteHrefPrecedent() { |
$limite = $this->parametres->get('navigation.limite'); |
$departActuel = $this->parametres->get('navigation.depart'); |
$departPrecedent = $departActuel - $limite; |
$href = null; |
if ($departPrecedent >= 0) { |
$squelette = 'http://localhost/service:nel:0.1/fournier/taxons?navigation.depart=%s&navigation.limite=%s'; |
$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 = 'http://localhost/service:nel:0.1/fournier/taxons?navigation.depart=%s&navigation.limite=%s'; |
$href = sprintf($squelette, $departSuivant, $limite); |
} |
return $href; |
} |
} |
?> |
/trunk/services/modules/0.2/bdtfx/NomDetails.php |
---|
New file |
0,0 → 1,88 |
<?php |
class NomDetails { |
private $parametres = null; |
private $ressources = null; |
private $bdd = null; |
private $detailsHrefTpl = null; |
private $ontologieHrefTpl = null; |
private $nom = array(); |
private $champsProjet = array(); |
public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
$this->bdd = $bdd; |
} |
public function setChampsProjets($champsProjet) { |
$this->champsProjet = $champsProjet; |
} |
public function setDetailsHrefTpl($tpl) { |
$this->detailsHrefTpl = $tpl; |
} |
public function setOntologieHrefTpl($tpl) { |
$this->ontologieHrefTpl = $tpl; |
} |
public function consulter() { |
$infos = $this->rechercherInfosNom(); |
$retour = $this->formaterDetails($infos); |
return $retour; |
} |
private function rechercherInfosNom() { |
$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 bdtfx_v1_01 AS ns '. |
' LEFT JOIN bdtfx_v1_01 AS nr ON (ns.num_nom_retenu = nr.num_nom) '. |
' LEFT JOIN bdtfx_v1_01 AS nb ON (ns.basionyme = nb.num_nom) '. |
"WHERE ns.num_nom = $detailsId "; |
$resultats = $this->bdd->recuperer($requete); |
return $resultats; |
} |
private function formaterDetails($infos) { |
$nomAFormater = new NomDO($infos); |
$nomDeco = new NomDecorateur($nomAFormater); |
$nomDeco->ajouterId(); |
$nomDeco->ajouterIntitule(); |
$retenuDeco = new NomRetenuDecorateur($nomDeco, $this->detailsHrefTpl); |
$retenuDeco->ajouterRetenu(); |
$retenuDeco->ajouterId(); |
$retenuDeco->ajouterIntitule(); |
$retenuDeco->ajouterHref(); |
$rangDeco = new NomRangDecorateur($nomDeco, $this->bdd, $this->ontologieHrefTpl); |
$rangDeco->ajouterCode(); |
$rangDeco->ajouterIntitule(); |
$rangDeco->ajouterHref(); |
$compoDeco = new NomCompoDecorateur($nomDeco); |
$compoDeco->ajouterCompo(); |
$nomDeco->ajouterAuteur(); |
$nomDeco->ajouterAnnee(); |
$nomDeco->ajouterBiblio(); |
$nomDeco->ajouterAddendum(); |
$nomDeco->ajouterNotes(); |
$basioDeco = new NomBasionymeDecorateur($nomDeco, $this->detailsHrefTpl); |
$basioDeco->ajouterId(); |
$basioDeco->ajouterIntitule(); |
$basioDeco->ajouterHref(); |
$projetDeco = new NomChampsProjetDecorateur($nomDeco, $this->champsProjet); |
$projetDeco->ajouterChampsSupplementaires(); |
return $nomDeco->getNomFormate(); |
} |
} |
?> |
/trunk/services/configurations/config_bdtfx.ini |
---|
17,7 → 17,15 |
; URL de l'ontologie des bdnt |
url_ontologie="{ref:url_base}service:eflore:0.1/bdnt/ontologies/" |
; +------------------------------------------------------------------------------------------------------+ |
; Paramètres pour la V2 |
baseServiceUrl = "{ref:url_base}service:eflore:0.2/" |
baseProjetUrl = "{ref:baseServiceUrl}bdtfx/" |
listeUrl = "{ref:baseProjetUrl}noms" |
detailsHrefTpl = "{ref:baseProjetUrl}noms/%s" |
ontologieHrefTpl = "{ref:baseServiceUrl}bdnt/ontologies/rangTaxo:%s" |
; +------------------------------------------------------------------------------------------------------+ |
; Config spécifique au projet |
; Noms des ressources disponible pour ce projet |
43,8 → 51,10 |
masque.an, |
masque.bib, |
masque.ad, |
retour, |
retour.format, |
retour.champs, |
retour.langue, |
version.projet" |
;correspondance champs bdnt pour l'affichage lors du résultat renvoyé |
/trunk/services/bibliotheque/Conteneur.php |
---|
New file |
0,0 → 1,105 |
<?php |
class Conteneur { |
protected $parametres = array(); |
protected $partages = array(); |
public function __construct(array $parametres = null) { |
$this->parametres = is_null($parametres) ? array() : $parametres; |
} |
public function getParametre($cle) { |
$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle); |
return $valeur; |
} |
public function getParametreTableau($cle) { |
$tableau = array(); |
$parametre = $this->getParametre($cle); |
if (empty($parametre) === false) { |
$tableauPartiel = explode(',', $parametre); |
$tableauPartiel = array_map('trim', $tableauPartiel); |
foreach ($tableauPartiel as $champ) { |
if (strpos($champ, '=') === false) { |
$tableau[] = $champ; |
} else { |
list($cle, $val) = explode('=', $champ); |
$tableau[$cle] = $val; |
} |
} |
} |
return $tableau; |
} |
public function setParametre($cle, $valeur) { |
$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 getProjet() { |
if (!isset($this->partages['Projet'])){ |
$ressources = $this->getRessourcesUrl(); |
$projet = new Projet($ressources); |
$projet->setCheminBase($this->getParametre('cheminBase')); |
$projet->setCheminConfig($this->getParametre('chemin_configurations')); |
$projet->setCheminBiblio($this->getParametre('chemin_bibliotheque')); |
$projet->initialiser(); |
$projet->setParamsVerif($this->getParametresUrlVerificateur()); |
$projet->setRessourcesVerif($this->getRessourcesUrlVerificateur()); |
$this->partages['Projet'] = $projet; |
} |
return $this->partages['Projet']; |
} |
public function getBdd() { |
if (!isset($this->partages['Bdd'])){ |
$this->partages['Bdd'] = new Bdd(); |
} |
return $this->partages['Bdd']; |
} |
public function getService($classe) { |
$service = new $classe($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getBdd()); |
if ($service instanceof NomDetails) { |
$service->setDetailsHrefTpl($this->getParametre('detailsHrefTpl')); |
$service->setChampsProjets($this->getParametreTableau('champsProjets')); |
$service->setOntologieHrefTpl($this->getParametre('ontologieHrefTpl')); |
} else if ($service instanceof NomsListe) { |
$service->setDetailsHrefTpl($this->getParametre('detailsHrefTpl')); |
$service->setListeUrl($this->getParametre('listeUrl')); |
} |
return $service; |
} |
} |
?> |
/trunk/services/bibliotheque/Parametres.php |
---|
New file |
0,0 → 1,105 |
<?php |
class Parametres implements Iterator { |
/** Contients les paramètres.*/ |
private $parametres = array(); |
private $bdd = null; |
public function __construct(Array $parametres, Bdd $bdd) { |
$this->parametres = $parametres; |
$this->bdd = $bdd; |
$this->definirValeursParDefaut(); |
} |
public function current () { |
return current($this->parametres); |
} |
public function key() { |
return key($this->parametres); |
} |
public function next() { |
return next($this->parametres); |
} |
public function rewind() { |
return reset($this->parametres); |
} |
public function valid() { |
return current($this->parametres) == false ? false : true; |
} |
public function get($parametreCode) { |
$valeur = ''; |
if ($this->exister($parametreCode)) { |
$valeur = $this->parametres[$parametreCode]; |
} |
return $valeur; |
} |
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'] = 0; |
} |
if ($this->exister('navigation.limite') == false) { |
$this->parametres['navigation.limite'] = 100; |
} |
} |
} |
?> |
/trunk/services/bibliotheque/Projet.php |
---|
New file |
0,0 → 1,150 |
<?php |
class Projet { |
private $ressources = null; |
private $paramsVerif = null; |
private $ressourcesVerif = null; |
private $cheminBase = ''; |
private $cheminConfig = ''; |
private $cheminBiblio = ''; |
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 setRessourcesVerif($ressourcesVerificateur) { |
$this->ressourcesVerif = $ressourcesVerificateur; |
} |
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(); |
} |
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.'nom'.DS; |
$chemins[] = $this->cheminBiblio.'nom'.DS.'decorateurs'.DS; |
foreach ($chemins as $chemin) { |
$chemin = $chemin.$classe.'.php'; |
if (file_exists($chemin)) { |
require_once $chemin; |
} |
} |
} |
public function getServiceClasseNom() { |
$classeNom = ''; |
if ($this->ressources->getNombre() == 2) { |
if ($this->ressources->getServiceNom() == 'noms') { |
$classeNom = 'NomsListe'; |
} else if ($this->ressources->getServiceNom() == 'taxons') { |
$classeNom = 'TaxonsListe'; |
} |
} else if ($this->ressources->getNombre() == 3) { |
$position3 = $this->ressources->getParPosition(2); |
if ($this->ressources->etreId($position3)) { |
if ($this->ressources->getServiceNom() == 'noms') { |
$classeNom = 'NomDetails'; |
} else if ($this->ressources->getServiceNom() == 'taxons') { |
$classeNom = 'TaxonDetails'; |
} |
} |
} else if ($this->ressources->getNombre() == 4) { |
$position3 = $this->ressources->getParPosition(2); |
$position4 = $this->ressources->getParPosition(3); |
if ($this->ressources->etreStats($position3)) { |
if ($this->ressources->etreTypeDeStats($position4)) { |
$classeNom = 'NomsStats'.ucfirst($position4); |
} |
} else if ($this->ressources->etreId($position3)) { |
if ($this->ressources->etreRelations($position4)) { |
$classeNom = 'NomRelations'; |
} |
} |
} else if ($this->ressources->getNombre() == 5) { |
$position3 = $this->ressources->getParPosition(2); |
$position4 = $this->ressources->getParPosition(3); |
$position5 = $this->ressources->getParPosition(4); |
if ($this->ressources->etreId($position3)) { |
if ($this->ressources->etreRelations($position4)) { |
if ($this->ressources->etreTypeDeRelations($position5)) { |
$classeNom = 'NomRelations'.ucfirst($position5); |
} |
} |
} |
} |
return $classeNom; |
} |
public function verifier() { |
$this->paramsVerif->verifier(); |
$this->ressourcesVerif->verifier(); |
$this->verifierExistanceServiceClasse(); |
} |
private function verifierExistanceServiceClasse() { |
$service = $this->ressources->getServiceNom(); |
$classe = $this->getServiceClasseNom(); |
$projet = $this->getNom(); |
$chemins = array(); |
$chemins[] = $this->cheminBase.$projet.DS.$classe.'.php'; |
$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php'; |
$existe = false; |
foreach ($chemins as $chemin) { |
if (file_exists($chemin)) { |
$existe = true; |
break; |
} |
} |
if ($existe === false) { |
$message = "La classe '$classe' du service demandé '$service' n'existe pas dans le projet '$projet' !"; |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
throw new Exception($message, $code); |
} |
} |
} |
?> |
/trunk/services/bibliotheque/nom/NomDO.php |
---|
New file |
0,0 → 1,25 |
<?php |
class NomDO { |
private $infos; |
public function __construct(Array $infos) { |
$this->infos = $infos; |
} |
public function getTag($tag) { |
return $this->infos[$tag]; |
} |
public function verifierTag($tag) { |
$existe = true; |
if ($this->getTag($tag) == null || $this->getTag($tag) == '') { |
$existe = false; |
} |
return $existe; |
} |
public function getNomDetails() { |
return $this->getTitle().' by '.$this->getAuthor(); |
} |
} |
?> |
/trunk/services/bibliotheque/nom/decorateurs/NomCompoDecorateur.php |
---|
New file |
0,0 → 1,73 |
<?php |
class NomCompoDecorateur extends NomDecorateur { |
private $nomDecorateur; |
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,21 |
<?php |
class NomChampsProjetDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $champs = array(); |
public function __construct(NomDecorateur $nomDecorateur, Array $champs) { |
$this->nomDecorateur = $nomDecorateur; |
$this->champs = $champs; |
} |
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,63 |
<?php |
class NomDecorateur { |
protected $nom = null; |
protected $nomFormate = array(); |
public function __construct(NomDO $nomADecorer) { |
$this->nom = $nomADecorer; |
$this->initialiserNomFormate(); |
} |
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 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/decorateurs/NomRetenuDecorateur.php |
---|
New file |
0,0 → 1,37 |
<?php |
class NomRetenuDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $numNom = null; |
private $numNomRetenu = null; |
private $nomSci = null; |
private $detailsHrefTpl = null; |
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->nomSci = $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() { |
$this->nomDecorateur->nomFormate['nom_retenu.id'] = (int) $this->numNomRetenu; |
} |
public function ajouterHref() { |
$href = sprintf($this->detailsHrefTpl, $this->numNomRetenu); |
$this->nomDecorateur->nomFormate['nom_retenu.href'] = $href; |
} |
public function ajouterIntitule() { |
$this->nomDecorateur->nomFormate['nom_retenu'] = $this->nomSci; |
} |
} |
?> |
/trunk/services/bibliotheque/nom/decorateurs/NomBasionymeDecorateur.php |
---|
New file |
0,0 → 1,39 |
<?php |
class NomBasionymeDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $basionyme = null; |
private $basionymeId = null; |
private $detailsHrefTpl = null; |
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,41 |
<?php |
class NomRangDecorateur extends NomDecorateur { |
private $nomDecorateur = null; |
private $rang = null; |
private $bdd = null; |
private $ontologieHrefTpl = null; |
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']; |
} |
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/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,47 |
<?php |
class Versions { |
private $parametres = null; |
private $projet = null; |
private $versions = array(); |
public function __construct(AnalyseurParametres $parametres, $projetNom) { |
$this->parametres = $parametres; |
$this->projet = $projet; |
} |
private function getVersion() { |
$version = $this->parametres->getVersionProjet(); |
$versionBdd = ''; |
if ($version == '+') { |
$versionBdd = Config::get('Versions.derniere'); |
} else if (is_numeric($version)) { |
$versionBdd = str_replace('.', '_', $version); |
} else if ($version == '*') { |
$message = "La version du projet ne peut valoir * pour cette ressource."; |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
throw new Exception($message, $code); |
} |
return $versionBdd; |
} |
public function chargerVersionsDisponibles() { |
$tableMeta = $this->projetNom.'_meta'; |
$req_version = "SELECT version FROM $tableMeta"; |
$res_version = $this->getBdd()->recupererTous($req_version); |
if ($res_version == '') { |
//cas ou la requete comporte des erreurs |
$e = "La requête SQL de versionnage formée comporte une erreur : $req_version"; |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e); |
} elseif ($res_version) { |
foreach ($res_version as $version) { |
$versions_dispo[] = $version['version']; |
} |
} else { |
$m = 'Versions introuvables dans la table des méta-données'; |
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $m); |
} |
return $versions_dispo; |
} |
} |
?> |
/trunk/services/bibliotheque/ParametresVerificateur.php |
---|
New file |
0,0 → 1,86 |
<?php |
class ParametresVerificateur { |
private $parametres = null; |
private $parametresApi = array(); |
private $erreursParametres = array(); |
public function __construct(Parametres $parametres, Array $parametresApi) { |
$this->parametres = $parametres; |
$this->parametresApi = $parametresApi; |
} |
public function verifier() { |
$this->verifierConformiteApi(); |
$this->verifierValeurs(); |
} |
private function verifierConformiteApi() { |
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(); |
} |
} |
private function verifierValeurs() { |
$this->verifierValeurSimple('recherche', 'stricte|floue|etendue'); |
$this->verifierValeurSimple('ns.format', 'htm|txt'); |
$this->verifierValeurSimple('retour', 'application/json|image/jpeg'); |
$this->verifierValeurSimple('retour.format', 'min|max|oss|perso'); |
$this->verifierValeurRegExp('retour.langue', '/^(?:[*]|orig|[a-z]{2})$/'); |
$this->verifierValeurMultipe('ns.structure', '|an|au|bib|ad'); |
$this->verifierVersionProjet(); |
if (count($this->erreursParametres) > 0) { |
$message = 'Erreur dans le paramètrage de votre URL : <br />'.implode('<br/>', $this->erreursParametres); |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
throw new Exception($message, $code); |
} |
} |
private function verifierValeurSimple($parametre, $valeursPermises) { |
$valeur = $this->parametres->get($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, $regexp) { |
$valeur = $this->parametres->get($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 verifierValeurMultipe($parametre, $valeursPermises) { |
$valeursConcatenees = $this->parametres->get($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"; |
} |
} |
} |
private function verifierVersionProjet() { |
$valeur = $this->parametres->get('version.projet'); |
if (preg_match('/^(?:[0-9]+[.][0-9]+|[*+])$/', $valeur) == 0) { |
$this->erreursParametres[] = "Le paramètre 'version.projet' ne peut pas prendre la valeur '$valeur'. Valeurs permises : +,* ou [0-9]+.[0-9]+"; |
} |
} |
} |
?> |
/trunk/services/bibliotheque/Ressources.php |
---|
New file |
0,0 → 1,61 |
<?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; |
} |
} |
?> |