retourne le contenu d'un commentaire d'id #id * * @category DEL * @package Services * @subpackage Commentaires * @version 0.1 * @author Mathias CHOUET * @author Jean-Pascal MILCENT * @author Aurelien PERONNET * @license GPL v3 * @license CECILL v2 * @copyright 1999-2014 Tela Botanica */ 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; } }