Subversion Repositories eFlore/Applications.del

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2212 arthur 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Retourne le contenu d'un commentaire pour un identifiant donné.
5
 * http://localhost/service:del:0.1/commentaires/#id => retourne le contenu d'un commentaire d'id #id
6
 *
7
 * @category   DEL
8
 * @package    Services
9
 * @subpackage Commentaires
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
17
 */
18
 
19
class CommentaireDetails {
20
 
21
	private $conteneur;
22
	private $bdd;
23
	private $idCommentaire;
24
 
25
	private $mapping = array();
26
 
27
	public function __construct(Conteneur $conteneur = null) {
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
29
		$this->bdd = $this->conteneur->getBdd();
30
 
31
		$this->mapping = $this->conteneur->getParametreTableau('commentaires.mapping');
32
	}
33
 
34
	public function consulter($ressources) {
35
		$this->idCommentaire = $ressources[0];
36
 
37
		// Lancement du service
38
		$commentaire = $this->chargerCommentaire();
39
		$commentaire = $this->formaterCommentaires($commentaire);
40
 
41
		// Mettre en forme le résultat et l'envoyer pour affichage*/
42
		$resultat = new ResultatService();
43
		$resultat->corps = $commentaire;
44
 
45
		return $resultat;
46
	}
47
 
48
	private function chargerCommentaire() {
49
		$requete = 'SELECT * '.
50
			'FROM del_commentaire '.
51
			'WHERE id_commentaire = '.$this->idCommentaire.' '.
52
			' -- '.__FILE__.' : '.__LINE__;
53
		$resultat = $this->bdd->recuperer($requete);
54
		if ($resultat === false) {
55
			$message = "Aucune information ne correspond au commentaire # «{$this->idCommentaire}».";
56
			throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
57
		}
58
		return is_array($resultat) ? $resultat : array();
59
	}
60
 
61
	private function formaterCommentaires($infos) {
62
		$retour = array();
63
		foreach ($this->mapping as $nomChampBdd => $nomAttributSortie) {
64
			$retour[$nomAttributSortie] = $infos[$nomChampBdd];
65
		}
66
		return $retour;
67
	}
68
}