Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
458 aurelien 1
<?php
2
class ImagesPourObservation 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 = 'json';
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
		if(!isset($uid[0]) && !is_numeric($uid[0])) {
44
			return;
45
		}
46
 
47
		$id_observation = $uid[0];
48
 
49
		switch ($format) {
50
 
51
			case 'html':
52
 
53
			case 'json':
54
				$images = $this->obtenirImagesPourObservation();
55
				$images_pour_obs = $images->$id_observation;
56
				$total = count($images_pour_obs);
57
				$tranche = $images_pour_obs;
58
 
59
				$retour = array('total' => $total,
60
								'contenu' => $tranche
61
								);
62
 
63
				$retour = json_encode($retour);
64
				$mime = 'application/json';
65
				break;
66
 
67
			case 'xml':
68
				break;
69
		}
70
 
71
		$this->envoyer($retour,$mime);
72
	}
73
 
74
	private function obtenirImagesPourObservation() {
543 aurelien 75
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/mocks/imagesparobsmock.json'));
458 aurelien 76
	}
77
}
78
?>