Subversion Repositories eFlore/Applications.del

Rev

Rev 1837 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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