/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; |
} |
} |
?> |
/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/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/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/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/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); |
} |
} |
} |
?> |