| 858 |
gduche |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
| 1795 |
jpm |
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
|
| 858 |
gduche |
6 |
*
|
| 1795 |
jpm |
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>
|
| 858 |
gduche |
17 |
*/
|
|
|
18 |
|
| 1839 |
jpm |
19 |
class CommentaireDetails {
|
| 1612 |
jpm |
20 |
|
| 858 |
gduche |
21 |
private $conteneur;
|
|
|
22 |
private $bdd;
|
|
|
23 |
private $idCommentaire;
|
| 1612 |
jpm |
24 |
|
| 1795 |
jpm |
25 |
private $mapping = array();
|
|
|
26 |
|
| 858 |
gduche |
27 |
public function __construct(Conteneur $conteneur = null) {
|
|
|
28 |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
|
| 1793 |
jpm |
29 |
$this->bdd = $this->conteneur->getBdd();
|
| 1795 |
jpm |
30 |
|
|
|
31 |
$this->mapping = $this->conteneur->getParametreTableau('commentaires.mapping');
|
| 858 |
gduche |
32 |
}
|
| 1612 |
jpm |
33 |
|
| 1795 |
jpm |
34 |
public function consulter($ressources) {
|
|
|
35 |
$this->idCommentaire = $ressources[0];
|
| 1612 |
jpm |
36 |
|
| 858 |
gduche |
37 |
// Lancement du service
|
| 1795 |
jpm |
38 |
$commentaire = $this->chargerCommentaire();
|
|
|
39 |
$commentaire = $this->formaterCommentaires($commentaire);
|
| 1612 |
jpm |
40 |
|
| 858 |
gduche |
41 |
// Mettre en forme le résultat et l'envoyer pour affichage*/
|
|
|
42 |
$resultat = new ResultatService();
|
| 1837 |
jpm |
43 |
$resultat->corps = $commentaire;
|
| 1612 |
jpm |
44 |
|
| 858 |
gduche |
45 |
return $resultat;
|
|
|
46 |
}
|
| 1612 |
jpm |
47 |
|
| 1795 |
jpm |
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);
|
| 858 |
gduche |
57 |
}
|
| 1795 |
jpm |
58 |
return is_array($resultat) ? $resultat : array();
|
| 858 |
gduche |
59 |
}
|
| 1612 |
jpm |
60 |
|
| 1795 |
jpm |
61 |
private function formaterCommentaires($infos) {
|
|
|
62 |
$retour = array();
|
|
|
63 |
foreach ($this->mapping as $nomChampBdd => $nomAttributSortie) {
|
| 1837 |
jpm |
64 |
$retour[$nomAttributSortie] = $infos[$nomChampBdd];
|
| 858 |
gduche |
65 |
}
|
| 1795 |
jpm |
66 |
return $retour;
|
| 858 |
gduche |
67 |
}
|
| 1795 |
jpm |
68 |
}
|