Subversion Repositories eFlore/Applications.del

Rev

Rev 341 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
384 aurelien 1
<?php
2
class Images extends Del {
3
 
4
	private $debut = 0;
5
	private $limite = 50;
6
 
7
	/**
8
	* Méthode appelée avec une requête de type GET avec une url de la forme
9
	* http://localhost/jrest/ExempleService/
10
	*
11
	* Sert normalement à renvoyer la description des possibilités du service
12
	*
13
	*/
14
	public function getRessource() {
15
		return $this->getElement(array());
16
	}
17
 
18
	/**
19
	* Méthode appelée avec une requête de type GET avec une url de la forme
20
	* http://localhost/jrest/ExempleService/uid[0]/$uid[1]/ etc...
21
	*
22
	* Sert normalement à ramener un élément précis indiqué par un identifiant
23
	* qui se situe dans l'url après le nom du service
24
	* Le filtrage, le format de retour, les paramètres optionnels ... sont normalement indiqués
25
	* dans le tableau $_GET
26
	* Pour obtenir l'élément 2501 dans le format HTML cela pourrait donner
27
	* http://localhost/jrest/ExempleService/2501?format=HTML
28
	*
29
	* @param $uid un tableau contenant les élements passés dans l'url après le nom du service
30
	*
31
	*/
32
	public function getElement($uid)
33
	{
34
		$format = 'html';
35
 
36
		$this->debut = isset($_GET['debut']) ? $_GET['debut'] : $this->debut;
37
		$this->limite = isset($_GET['limite']) ? $_GET['limite'] : $this->limite;
38
 
39
		if(isset($_GET['format'])) {
40
			$format = strtolower($_GET['format']);
41
		}
42
 
43
		switch ($format) {
44
 
45
			case 'html':
46
 
47
			case 'json':
48
				$images = $this->obtenirImagesAvecObservations();
49
 
50
				$total = count($images);
51
				$tranche = array_slice($images,$this->debut,$this->limite);
52
 
53
				$retour = array('total' => count($images),
54
								'contenu' => $tranche
55
								);
56
 
57
				$retour = json_encode($retour);
58
				$mime = 'application/json';
59
				break;
60
 
61
			case 'xml':
62
				break;
63
		}
64
 
65
		$this->envoyer($retour,$mime);
66
	}
67
 
68
	private function obtenirImagesAvecObservations() {
69
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json'));
70
	}
71
}
72
?>