Subversion Repositories eFlore/Applications.del

Rev

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

Rev 341 Rev 468
Line 2... Line 2...
2
class Observations extends Del {
2
class Observations 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 33... Line 37...
33
	{
37
	{
34
		$format = 'html';
38
		$format = 'html';
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 45... Line 54...
45
			case 'html':
54
			case 'html':
Line 46... Line 55...
46
					
55
					
47
			case 'json':
56
			case 'json':
48
				$obs = $this->obtenirObservationsAvecImages();
57
				$obs = $this->obtenirObservationsAvecImages();
-
 
58
				$total = count($obs);
-
 
59
				if($this->tri_demande) {
-
 
60
					usort($obs, array($this,'comparerObservations'));
49
				$total = count($obs);
61
				}
Line 50... Line 62...
50
				$tranche = array_slice($obs,$this->debut,$this->limite);
62
				$tranche = array_slice($obs,$this->debut,$this->limite);
51
				
63
				
52
				$retour = array('total' => count($obs),
64
				$retour = array('total' => count($obs),
Line 61... Line 73...
61
		}
73
		}
Line 62... Line 74...
62
	
74
	
63
		$this->envoyer($retour,$mime);
75
		$this->envoyer($retour,$mime);
Line -... Line 76...
-
 
76
	}
-
 
77
	
-
 
78
	private function comparerObservations($observation_a, $observation_b) {
-
 
79
	
-
 
80
		$champ_tri = $this->champ_tri;
-
 
81
	
-
 
82
		$observation_a = isset($observation_a->$champ_tri) ? $observation_a->$champ_tri : -1;
-
 
83
		$observation_b = isset($observation_b->$champ_tri) ? $observation_b->$champ_tri : -1;
-
 
84
	
-
 
85
		if($this->ordre == 'desc') {
-
 
86
			return $observation_a > $observation_b;
-
 
87
		} else {
-
 
88
			return $observation_a < $observation_b;
-
 
89
		}
64
	}
90
	}
65
	
91
	
66
	private function obtenirObservationsAvecImages() {
92
	private function obtenirObservationsAvecImages() {
67
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/obsmock.json'));
93
		return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/obsmock.json'));
68
	}
94
	}
69
}
95
}