Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 2211 → Rev 2212

/branches/v1.12-aluminium/services/modules/0.1/commentaires/CommentaireDetails.php
New file
0,0 → 1,68
<?php
// declare(encoding='UTF-8');
/**
* Retourne le contenu d'un commentaire pour un identifiant donné.
* http://localhost/service:del:0.1/commentaires/#id => retourne le contenu d'un commentaire d'id #id
*
* @category DEL
* @package Services
* @subpackage Commentaires
* @version 0.1
* @author Mathias CHOUET <mathias@tela-botanica.org>
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Aurelien PERONNET <aurelien@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>
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
*/
 
class CommentaireDetails {
 
private $conteneur;
private $bdd;
private $idCommentaire;
 
private $mapping = array();
 
public function __construct(Conteneur $conteneur = null) {
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
$this->bdd = $this->conteneur->getBdd();
 
$this->mapping = $this->conteneur->getParametreTableau('commentaires.mapping');
}
 
public function consulter($ressources) {
$this->idCommentaire = $ressources[0];
 
// Lancement du service
$commentaire = $this->chargerCommentaire();
$commentaire = $this->formaterCommentaires($commentaire);
 
// Mettre en forme le résultat et l'envoyer pour affichage*/
$resultat = new ResultatService();
$resultat->corps = $commentaire;
 
return $resultat;
}
 
private function chargerCommentaire() {
$requete = 'SELECT * '.
'FROM del_commentaire '.
'WHERE id_commentaire = '.$this->idCommentaire.' '.
' -- '.__FILE__.' : '.__LINE__;
$resultat = $this->bdd->recuperer($requete);
if ($resultat === false) {
$message = "Aucune information ne correspond au commentaire # «{$this->idCommentaire}».";
throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
}
return is_array($resultat) ? $resultat : array();
}
 
private function formaterCommentaires($infos) {
$retour = array();
foreach ($this->mapping as $nomChampBdd => $nomAttributSortie) {
$retour[$nomAttributSortie] = $infos[$nomChampBdd];
}
return $retour;
}
}