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 |
|
|
|
19 |
class ConsulterCommentaire {
|
1612 |
jpm |
20 |
|
858 |
gduche |
21 |
private $conteneur;
|
|
|
22 |
private $navigation;
|
|
|
23 |
private $bdd;
|
|
|
24 |
private $idCommentaire;
|
1612 |
jpm |
25 |
|
1795 |
jpm |
26 |
private $mapping = array();
|
|
|
27 |
private $mappingInverse = array();
|
|
|
28 |
|
858 |
gduche |
29 |
public function __construct(Conteneur $conteneur = null) {
|
|
|
30 |
$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
|
|
|
31 |
$this->navigation = $conteneur->getNavigation();
|
1793 |
jpm |
32 |
$this->bdd = $this->conteneur->getBdd();
|
1795 |
jpm |
33 |
|
|
|
34 |
$this->mapping = $this->conteneur->getParametreTableau('commentaires.mapping');
|
|
|
35 |
$this->mappingInverse = array_flip($this->mapping);
|
858 |
gduche |
36 |
}
|
1612 |
jpm |
37 |
|
1795 |
jpm |
38 |
public function consulter($ressources) {
|
|
|
39 |
$this->idCommentaire = $ressources[0];
|
1612 |
jpm |
40 |
|
858 |
gduche |
41 |
// Lancement du service
|
1795 |
jpm |
42 |
$commentaire = $this->chargerCommentaire();
|
|
|
43 |
$commentaire = $this->formaterCommentaires($commentaire);
|
|
|
44 |
$this->navigation->setTotal(count($commentaire));
|
1612 |
jpm |
45 |
|
858 |
gduche |
46 |
// Mettre en forme le résultat et l'envoyer pour affichage*/
|
|
|
47 |
$resultat = new ResultatService();
|
1795 |
jpm |
48 |
$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $commentaire);
|
1612 |
jpm |
49 |
|
858 |
gduche |
50 |
return $resultat;
|
|
|
51 |
}
|
1612 |
jpm |
52 |
|
1795 |
jpm |
53 |
private function chargerCommentaire() {
|
|
|
54 |
$requete = 'SELECT * '.
|
|
|
55 |
'FROM del_commentaire '.
|
|
|
56 |
'WHERE id_commentaire = '.$this->idCommentaire.' '.
|
|
|
57 |
'LIMIT '.$this->navigation->getDepart().', '.$this->navigation->getLimite().' '.
|
|
|
58 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
59 |
$resultat = $this->bdd->recuperer($requete);
|
|
|
60 |
if ($resultat === false) {
|
|
|
61 |
$message = "Aucune information ne correspond au commentaire # «{$this->idCommentaire}».";
|
|
|
62 |
throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
|
858 |
gduche |
63 |
}
|
1795 |
jpm |
64 |
return is_array($resultat) ? $resultat : array();
|
858 |
gduche |
65 |
}
|
1612 |
jpm |
66 |
|
1795 |
jpm |
67 |
private function formaterCommentaires($infos) {
|
|
|
68 |
$retour = array();
|
|
|
69 |
$idCommentaire = $infos['id_commentaire'];
|
|
|
70 |
foreach ($this->mapping as $nomChampBdd => $nomAttributSortie) {
|
|
|
71 |
$retour[$idCommentaire][$nomAttributSortie] = $infos[$nomChampBdd];
|
858 |
gduche |
72 |
}
|
1795 |
jpm |
73 |
return $retour;
|
858 |
gduche |
74 |
}
|
1795 |
jpm |
75 |
}
|