Rev 723 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/**** */class Conteneur {protected $parametres = array();protected $partages = array();protected $masque = array();protected $urlNavigation;protected $total;public function __construct(array $parametres = null) {$this->parametres = is_null($parametres) ? array() : $parametres;}public function chargerConfiguration($chemin) {$cheminConfigurations = Config::get('chemin_configurations');Config::charger($cheminConfigurations.DS.$chemin);$this->chargerMasque();$this->chargerUrl();}public function getDepart() {return isset($this->parametres['navigation.depart']) ? $this->parametres['navigation.depart'] : 0;}public function getLimite() {return isset($this->parametres['navigation.limite']) ? $this->parametres['navigation.limite'] : 10;}private function chargerMasque() {$masques = Config::get('masques_possibles');$masquesPossibles = explode(',', $masques);foreach ($this->parametres as $id => $parametre) {if (strpos($id, 'masque.') === 0) {if (in_array(str_replace('masque.', '', $id), $masquesPossibles)) {$this->masque[$id] = $parametre;}}}}private function chargerUrl() {$this->UrlNavigation = new Url(Config::get('url_service'));$this->UrlNavigation->setOption(Url::OPTION_ENCODER_VALEURS, true);}public function getUrl($depart = null, $limite = null) {if ($depart == null && $limite == null) {return $this->urlNavigation;} else {return $this->obtenirUrlNavigation($depart, $limite);}}/*** Récupérer l'url de navigation en concaténant d'éventuels paramètres* @param $depart l'entier de départ de la recherche* @param $limite le nombre de résultats à retourner* @param $parametresAdditionnels le tableau contenant les parametres => valeurs additionnels* */private function obtenirUrlNavigation($depart, $limite) {$parametres = $this->parametres;$parametres['navigation.depart'] = $depart;$parametres['navigation.limite'] = $limite;$this->UrlNavigation->setRequete($parametres);$url = $this->UrlNavigation->getURL();return $url;}public function getTotal() {return $this->total;}public function setTotal($total) {$this->total = $total;}/*** Créer l'entête en fonction des paramètres donnés* */public function getEntete() {$entete = array();$entete['masque'] = $this->getChaineMasque();$entete['depart'] = $this->getDepart();$entete['limite'] = $this->getLimite();$entete['total'] = $this->getTotal();$lienPrecedent = $this->recupererHrefPrecedent();if ($lienPrecedent != null) {$entete['entete.precedent'] = $lienPrecedent;}$lienSuivant = $this->recupererHrefSuivant();if ($lienSuivant) {$entete['entete.suivant'] = $lienSuivant;}return $entete;}/*** Récupérer le lien pour afficher les images précédentes en fonction des paramètres* */private function recupererHrefPrecedent() {$departActuel = $this->getDepart();$limite = $this->getLimite();$departPrecedent = $departActuel - $limite;$url = null;if ($departActuel > 0) {$url = $this->getUrl($departPrecedent, $limite);}return $url;}/*** Récupérer le lien pour afficher les images suivantes en fonction des paramètres* */private function recupererHrefSuivant() {$departActuel = $this->getDepart();$limite = $this->getLimite();$departSuivant = $departActuel + $limite;$url = null;if ($departSuivant < $this->total) {$url = $this->getUrl($departSuivant, $limite);}return $url;}public function getMasque($id = null) {if (isset($id)) {return $this->masque['masque.'.$id];} else {return $this->masque;}}public function getChaineMasque() {$chaine = array();foreach ($this->masque as $id => $valeur) {$chaine[] = $id.'='.$valeur;}return implode('&', $chaine);}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[] = trim($champ);} else {list($cle, $val) = explode('=', $champ);$tableau[trim($cle)] = trim($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 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();}return $this->partages['Bdd'];}public function getCacheSimple($options = array()) {$cache = new CacheSimple($options);return $cache;}public function getVersions() {if (!isset($this->partages['Versions'])){$parametres = $this->getParametresUrl();$ressources = $this->getRessourcesUrl();$bdd = $this->getBdd();$versions = new Versions($parametres, $ressources, $bdd);$this->partages['Versions'] = $versions;}return $this->partages['Versions'];}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());$projet->setVersionVerif($this->getVersionVerificateur());$projet->setServiceGenerique($this->getServiceGenerique());$this->partages['Projet'] = $projet;}return $this->partages['Projet'];}/*** Créer la chaine de limite de requête en fonction des paramètres donnés* */public function getLimitSql() {return ' LIMIT '.$this->getDepart().', '.$this->getLimite();}public function getSchemaBdd() {return $this->getParametre('schemaBdd');}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;}}?>