Subversion Repositories eFlore/Applications.del

Rev

Rev 384 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 384 Rev 468
Line 2... Line 2...
2
class Images extends Del {
2
class Images extends Del {
Line 3... Line 3...
3
	
3
	
4
	private $debut = 0;
4
	private $debut = 0;
Line -... Line 5...
-
 
5
	private $limite = 50;
-
 
6
	
-
 
7
	private $champ_tri = 'date_observation';
-
 
8
	private $ordre = 'desc';
5
	private $limite = 50;
9
	private $tri_demande = false;
6
	
10
	
7
	/**
11
	/**
8
	* Méthode appelée avec une requête de type GET avec une url de la forme
12
	* Méthode appelée avec une requête de type GET avec une url de la forme
9
	* http://localhost/jrest/ExempleService/
13
	* http://localhost/jrest/ExempleService/
Line 29... Line 33...
29
	* @param $uid un tableau contenant les élements passés dans l'url après le nom du service
33
	* @param $uid un tableau contenant les élements passés dans l'url après le nom du service
30
	*
34
	*
31
	*/
35
	*/
32
	public function getElement($uid)
36
	public function getElement($uid)
33
	{
37
	{
34
		$format = 'html';
38
		$format = 'json';
Line 35... Line 39...
35
		
39
		
36
		$this->debut = isset($_GET['debut']) ? $_GET['debut'] : $this->debut;
40
		$this->debut = isset($_GET['debut']) ? $_GET['debut'] : $this->debut;
-
 
41
		$this->limite = isset($_GET['limite']) ? $_GET['limite'] : $this->limite;
-
 
42
		
-
 
43
		$this->champ_tri = isset($_GET['tri']) ? $_GET['tri'] : $this->champ_tri;
-
 
44
		$this->ordre = isset($_GET['ordre']) ? $_GET['ordre'] : $this->ordre;
-
 
45
		
Line 37... Line 46...
37
		$this->limite = isset($_GET['limite']) ? $_GET['limite'] : $this->limite;
46
		$this->tri_demande = isset($_GET['tri']) ? true : false;
38
	
47
	
39
		if(isset($_GET['format'])) {
48
		if(isset($_GET['format'])) {
Line 46... Line 55...
46
					
55
					
47
			case 'json':
56
			case 'json':
Line 48... Line 57...
48
				$images = $this->obtenirImagesAvecObservations();
57
				$images = $this->obtenirImagesAvecObservations();
-
 
58
				
-
 
59
				$total = count($images);
-
 
60
				if($this->tri_demande) {
49
				
61
					usort($images, array($this,'comparerObservations'));
Line 50... Line 62...
50
				$total = count($images);
62
				}
51
				$tranche = array_slice($images,$this->debut,$this->limite);
63
				$tranche = array_slice($images,$this->debut,$this->limite);
52
				
64
				
Line 53... Line 65...
53
				$retour = array('total' => count($images),
65
				$retour = array('total' => $total,
54
								'contenu' => $tranche
66
								'contenu' => $tranche
55
								);
67
								);				
Line 63... Line 75...
63
		}
75
		}
Line 64... Line 76...
64
	
76
	
65
		$this->envoyer($retour,$mime);
77
		$this->envoyer($retour,$mime);
Line -... Line 78...
-
 
78
	}
-
 
79
	
-
 
80
	private function comparerObservations($image_a, $image_b) {
-
 
81
		
-
 
82
		$champ_tri = $this->champ_tri;
-
 
83
		
-
 
84
		$champ_a_comparer_a = isset($image_a->observation->$champ_tri) ? $image_a->observation->$champ_tri : 0;
-
 
85
		$champ_a_comparer_b = isset($image_b->observation->$champ_tri) ? $image_b->observation->$champ_tri : 0;
-
 
86
		
-
 
87
		if($this->ordre == 'desc') {
-
 
88
			return $champ_a_comparer_a > $champ_a_comparer_b;
-
 
89
		} else {
-
 
90
			return $champ_a_comparer_a < $champ_a_comparer_b;
-
 
91
		}
66
	}
92
	}
67
	
93
	
68
	private function obtenirImagesAvecObservations() {
94
	private function obtenirImagesAvecObservations() {
69
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json'));
95
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json'));
70
	}
96
	}
71
}
97
}