Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1816 → Rev 1817

/trunk/services/modules/0.1/Protocoles.php
1,7 → 1,11
<?php
// declare(encoding='UTF-8');
/**
* Classe principale de chargement des sous-services de Protocoles.
*
* Urls possibles :
* http://localhost/service:del:0.1/protocoles => tous les protocoles
*
* @category DEL
* @package Services
* @subpackage Protocoles
15,18 → 19,11
*/
class Protocoles extends RestService {
 
 
/*
* url possibles :
* http://localhost/del/services/0.1/observations/ => toutes les observations (infos obs, infos images, infos propositions, infos nb commentaires)
* http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
* */
 
private $parametres = array();
private $ressources = array();
private $methode = null;
private $projetNom = array();
private $serviceNom = array();
private $serviceNom = 'protocoles';
private $sousServiceNom = null;
private $cheminCourant = null;
 
private $conteneur;
40,10 → 37,18
 
public function consulter($ressources, $parametres) {
$this->methode = 'consulter';
$resultat = '';
$this->initialiserRessourcesEtParametres($ressources, $parametres);
return $this->executerService();
}
 
private function initialiserRessourcesEtParametres($ressources, $parametres = array()) {
$this->ressources = $ressources;
$this->parametres = $parametres;
}
 
private function executerService() {
$reponseHttp = new ReponseHttp();
try {
$this->initialiserRessourcesEtParametres($ressources, $parametres);
$this->conteneur = new Conteneur($this->parametres);
$resultat = $this->traiterRessources();
$reponseHttp->setResultatService($resultat);
55,132 → 60,60
return $corps;
}
 
public function ajouter($ressources, $requeteDonnees) {
$this->methode = 'ajouter';
$resultat = '';
try {
$this->initialiserRessourcesEtParametres($ressources, $requeteDonnees);
$this->conteneur = new Conteneur($this->parametres);
$resultat = $this->traiterRessources();
} catch (Exception $e) {
$reponseHttp->ajouterErreur($e);
}
}
 
private function initialiserRessourcesEtParametres($ressources, $parametres) {
$this->ressources = $ressources;
$this->parametres = $parametres;
}
 
private function traiterRessources() {
$retour = '';
$this->initialiserProjet();
if ($this->avoirRessourceService()) {
$retour = $this->initialiserService();
}
$this->analyserRessources();
$retour = $this->initialiserService();
return $retour;
}
 
private function avoirRessourceIdentifiant($num) {
$presenceId = false;
if (is_numeric($this->ressources[$num])) {
$presenceId = true;
} else {
$message = "Le service demandé '$service' nécessite d'avoir un identifiant d'image valide";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
private function analyserRessources() {
if ($this->methode == 'consulter') {
if (count($this->ressources) == 0) {
$this->sousServiceNom = 'liste-protocoles';
}
return $presenceId;
}
/*------------------------------------------------------------------------------------------------------------------
CONFIGURATION DU PROJET
------------------------------------------------------------------------------------------------------------------*/
private function initialiserProjet() {
$this->chargerNomDuProjet();
$this->chargerConfigProjet();
 
}
 
private function chargerNomDuProjet() {
$this->projetNom = 'protocoles';
}
 
private function chargerConfigProjet() {
$projet = $this->projetNom;
$chemin = Config::get('chemin_configurations')."config_$projet.ini";
Config::charger($chemin);
}
 
/*------------------------------------------------------------------------------------------------------------------
CONFIGURATION DU SERVICE
------------------------------------------------------------------------------------------------------------------*/
private function avoirRessourceService() {
/*
* url possibles :
* http://localhost/del/services/0.1/observations/ => toutes les observations (infos obs, infos images, infos propositions, infos nb commentaires)
* http://localhost/del/services/0.1/observations/#id => une observation donnée et ses images, SANS LES propositions & nombre de commentaire
* */
$presenceRessourceService = false;
if (isset($this->ressources[0])) {
if ($this->avoirRessourceIdentifiant(0)) {
if (sizeof($this->ressources) == 1) {
$presenceRessourceService = true;
$this->serviceNom = 'observation';
} else {
if (isset($this->ressources[1])) {
$presenceRessourceService = $this->avoirRessourceSousService();
}
}
}
} else {
$presenceRessourceService = true;
$this->serviceNom = 'liste-protocoles';
}
return $presenceRessourceService;
if ($this->sousServiceNom == null) {
$this->lancerMessageErreurRessource();
}
}
 
private function avoirRessourceSousService() {
$presenceRessourceService = false;
$servicesDispo = Outils::recupererTableauConfig('servicesDispo');
if ($this->avoirRessourceIdentifiant(1)) {
$service = $this->ressources[2];
if (in_array($service, $servicesDispo)) {
$presenceRessourceService = true;
$this->serviceNom = 'vote-observation';
} else {
$message = "Le service demandé '$service' n'est pas disponible pour le projet {$this->projetNom} !\n".
"Les services disponibles sont : ".implode(', ', $servicesDispo);
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
}
return $presenceRessourceService;
private function lancerMessageErreurRessource() {
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
$message = "La ressource demandée '$ressource' ".
"n'est pas disponible pour le service ".$this->serviceNom." !\n".
"Les URLs disponibles sont : \n".
" - en GET : protocoles (paramètres : aucun) \n";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
 
private function initialiserService() {
//$this->chargerNomDuService();
 
$classe = $this->obtenirNomClasseService($this->serviceNom);
$classe = $this->obtenirNomClasseService($this->sousServiceNom);
$chemins = array();
$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
$chemins[] = $this->cheminCourant.$this->serviceNom.DS.$classe.'.php';
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
$retour = '';
$service = null;
 
foreach ($chemins as $chemin) {
if (file_exists($chemin)) {
$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
require_once $chemin;
$service = new $classe($this->conteneur);
if ($this->methode == 'consulter') {
$retour = $service->consulter($this->ressources, $this->parametres);
} elseif ($this->methode == 'ajouter') {
$retour = $service->ajouter($this->ressources, $this->parametres);
$retour = $service->consulter();
} else {
$message = "Le sous-service '{$this->sousServiceNom}' du service '{$this->serviceNom}' ".
"ne possède pas de méthode '{$this->methode}' !";
$code = RestServeur::HTTP_NON_IMPLEMENTE;
throw new Exception($message, $code);
}
}
}
 
if (is_null($service)) {
$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
$message = "Le classe '$classe' correspondant à la ressource '$ressource' ".
"est introuvable par le service '{$this->serviceNom}' !";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
191,5 → 124,4
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
return $classeNom;
}
}
?>
}