Subversion Repositories eFlore/Applications.del

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
341 aurelien 1
<?php
2
class Observations 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
				$obs = $this->obtenirObservationsAvecImages();
49
				$total = count($obs);
50
				$tranche = array_slice($obs,$this->debut,$this->limite);
51
 
52
				$retour = array('total' => count($obs),
53
								'contenu' => array_slice($obs,$this->debut,$this->limite)
54
								);
55
				$retour = json_encode($retour);
56
				$mime = 'application/json';
57
				break;
58
 
59
			case 'xml':
60
				break;
61
		}
62
 
63
		$this->envoyer($retour,$mime);
64
	}
65
 
66
	private function obtenirObservationsAvecImages() {
67
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/obsmock.json'));
68
	}
69
}
70
?>