1,36 → 1,36 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Classe principale de chargement des sous-services "images" de DEL. |
* Classe principale de chargement des services Observations. |
* |
* Cette classe se charge toujours de : |
* - vérifier l'existance des ressources (services) demandés |
* - vérifier la cohérence et le format des paramêtres passées dans l'url |
* En fonction, de la compléxité du service, elle peut : |
* - dans un premier temps, exécuter directement les actions : consulter, ajouter, modifier, supprimer. |
* - dans un second temps, charger dynamiquement d'éventuelles sous-classes du service en fonction des ressources présentes dans l'URL. |
* |
* URLs possibles : |
* GET : |
* http://localhost/del/services/0.1/images/ => toutes les images : classe ListeImages |
* http://localhost/del/services/0.1/images/#idImg/votes => tous les votes d'une image (#idImg) classés par protocole : classe VotesImage |
* http://localhost/service:del:0.1/observations |
* toutes les observations (infos obs, infos images, infos propositions, infos nb commentaires) |
* |
* Non Implémenté : http://localhost/del/services/0.1/images/#id => une image donnée => en test pour remplacer les appels à eflore/cel |
* Non Implémenté : http://localhost/del/services/0.1/images/#id/votes?protocole=#id => tous les votes d'une image et d'un protocole donné |
* http://localhost/service:del:0.1/observations?retour.format=widget |
* toutes les infos des observations pour le Widget DEL |
* |
* http://localhost/service:del:0.1/observations/#idObs |
* une observation donnée et ses images, SANS LES propositions & nombre de commentaire* |
* |
* http://localhost/service:del:0.1/observations/#idObs/#idVote/vote |
* toutes les infos sur les votes d'une proposition |
* |
* PUT : |
* http://localhost/del/services/0.1/images/#idImg => ajouter un vote sur une image donnée (#idImg) |
* http://localhost/service:del:0.1/observations/#idObs/#idCommentaire/vote |
* ajoute un vote (+ ou -) pour une obs et une proposition donnée |
* |
* POST : |
* http://localhost/del/services/0.1/images/#idImg => modifier un vote sur une image donnée (#idImg) |
* http://localhost/service:del:0.1/observations/#idObs |
* utilisé seulement par les admins pour modifier une obs depuis DEL (dépublication des obs) |
* |
* DELETE : |
* http://localhost/del/services/0.1/images/#idImg => supprimer une image donnée (#idImg) |
* http://localhost/del/services/0.1/images/#idImg/votes/#idVote => supprimer un vote (#idVote) d'une image donnée (#idImg) |
* http://localhost/service:del:0.1/observations/#idObs/#idCommentaire/vote |
* modifie un vote (+ ou -) pour une obs et une proposition donnée |
* |
* @category DEL |
* @package Services |
* @subpackage Images |
* @subpackage Observations |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
39,25 → 39,22 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
restore_error_handler(); |
restore_exception_handler(); |
error_reporting(E_ALL); |
|
class Tepik extends RestService { |
|
private $conteneur; |
private $cheminCourant; |
private $parametres = array(); |
private $ressources = array(); |
private $methode; |
private $methode = null; |
private $serviceNom = 'tepik'; |
private $sousServiceNom; |
private $sousServiceNom = null; |
private $cheminCourant = null; |
|
private $conteneur; |
|
/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */ |
protected $utilisationParametresBruts = true; |
|
public function __construct() { |
$this->conteneur = new Conteneur(); |
$this->cheminCourant = dirname(__FILE__).DS; |
} |
|
68,23 → 65,26 |
} |
|
|
private function initialiserRessourcesEtParametres($ressources, $parametres = array()) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
} |
|
private function executerService() { |
$resultat = $this->traiterRessources(); |
if ($resultat === true || $resultat === false) { |
return $resultat; |
$reponseHttp = new ReponseHttp(); |
try { |
$this->conteneur = new Conteneur($this->parametres); |
$resultat = $this->traiterRessources(); |
$reponseHttp->setResultatService($resultat); |
} catch (Exception $e) { |
$reponseHttp->ajouterErreur($e); |
} |
|
$reponseHttp = new ReponseHttp(); |
$reponseHttp->setResultatService($resultat); |
$reponseHttp->emettreLesEntetes(); |
return $reponseHttp->getCorps(); |
$corps = $reponseHttp->getCorps(); |
return $corps; |
} |
|
private function initialiserRessourcesEtParametres($ressources, $parametres = array()) { |
$this->ressources = $ressources; |
$this->parametres = $parametres; |
} |
|
private function traiterRessources() { |
$this->analyserRessources(); |
$retour = $this->initialiserService(); |
94,27 → 94,37 |
private function analyserRessources() { |
if ($this->methode == 'consulter') { |
$this->analyserRessoucesConsultation(); |
} else if ($this->methode == 'modifier' || $this->methode == 'ajouter') { |
$this->analyserRessoucesModification(); |
} else if ($this->methode == 'supprimer') { |
$this->analyserRessoucesSuppression(); |
} |
} |
} |
|
private function analyserRessoucesConsultation() { |
if (count($this->ressources) == 0) { |
// http://localhost/service:del:0.1/observations |
$this->sousServiceNom = 'liste-observations'; |
} else if (count($this->ressources) == 1) { |
if ($this->etreRessourceIdentifiant(0)) { |
// http://localhost/service:del:0.1/observations/#idObs |
$this->sousServiceNom = 'observation-details'; |
} |
} |
if ($this->sousServiceNom == null) { |
$this->lancerMessageErreurRessource(); |
} |
} |
|
private function analyserRessoucesConsultation() { |
if (count($this->ressources) == 0) { |
$this->sousServiceNom = 'liste-images'; |
} else if (count($this->ressources) == 2) { |
if ($this->etreRessourceIdentifiant(0) && $this->verifierRessourceValeur(1, 'votes')) { |
$this->sousServiceNom = 'votes-image'; |
private function analyserRessoucesModification() { |
if (count($this->ressources) == 1) { |
if ($this->methode == 'modifier' && $this->etreRessourceIdentifiant(0)) { |
// http://localhost/service:del:0.1/observations/#idObs |
$this->sousServiceNom = 'observation-details'; |
} |
} |
|
if ($this->sousServiceNom == null) { |
$this->lancerMessageErreurRessource(); |
} |
} |
|
|
private function etreRessourceIdentifiant($num) { |
$presenceId = false; |
if (isset($this->ressources[$num]) && is_numeric($this->ressources[$num])) { |
131,22 → 141,26 |
return $ok; |
} |
|
private function verifierParametreValeur($cle, $valeur) { |
$ok = false; |
if (isset($this->parametres[$cle]) && $this->ressources[$cle] == $valeur) { |
$ok = true; |
} |
return $ok; |
} |
|
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". |
$this->getDoc(); |
"Les URLs disponibles sont : \n". |
" - en GET : observations, observations/#idObs/#idProposition/vote \n". |
" - en POST : observations/#id, observations/#idObs/#idProposition/vote \n". |
" - en PUT : observations/#idObs/#idProposition/vote \n"; |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
throw new Exception($message, $code); |
} |
|
public function getDoc() { |
return "Les URLs disponibles sont : \n". |
" * en GET : \n". |
" - images => toutes les images\n". |
" - images/#idImg/votes => tous les votes d'une image (#idImg) classés par protocole\n"; |
} |
|
private function initialiserService() { |
$classe = $this->obtenirNomClasseService($this->sousServiceNom); |
$chemins = array(); |
160,15 → 174,21 |
$service = new $classe($this->conteneur); |
if ($this->methode == 'consulter') { |
$retour = $service->consulter($this->ressources, $this->parametres); |
} |
} 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)) { |
$ressource = implode('/', $this->ressources); |
$msg = "Le classe '$classe' correspondant à la ressource '$ressource' ". |
"n'existe pas dans le service '{$this->serviceNom}' !\n".$this->getDoc(); |
throw new Exception($msg, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE); |
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources); |
$message = "Le classe '$classe' correspondant à la ressource '$ressource' ". |
"n'existe pas dans le service '{$this->serviceNom}' !"; |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
throw new Exception($message, $code); |
} |
return $retour; |
} |