4,6 → 4,10 |
private $debut = 0; |
private $limite = 50; |
|
private $champ_tri = 'date_observation'; |
private $ordre = 'desc'; |
private $tri_demande = false; |
|
/** |
* Méthode appelée avec une requête de type GET avec une url de la forme |
* http://localhost/jrest/ExempleService/ |
35,6 → 39,11 |
|
$this->debut = isset($_GET['debut']) ? $_GET['debut'] : $this->debut; |
$this->limite = isset($_GET['limite']) ? $_GET['limite'] : $this->limite; |
|
$this->champ_tri = isset($_GET['tri']) ? $_GET['tri'] : $this->champ_tri; |
$this->ordre = isset($_GET['ordre']) ? $_GET['ordre'] : $this->ordre; |
|
$this->tri_demande = isset($_GET['tri']) ? true : false; |
|
if(isset($_GET['format'])) { |
$format = strtolower($_GET['format']); |
47,6 → 56,9 |
case 'json': |
$obs = $this->obtenirObservationsAvecImages(); |
$total = count($obs); |
if($this->tri_demande) { |
usort($obs, array($this,'comparerObservations')); |
} |
$tranche = array_slice($obs,$this->debut,$this->limite); |
|
$retour = array('total' => count($obs), |
63,6 → 75,20 |
$this->envoyer($retour,$mime); |
} |
|
private function comparerObservations($observation_a, $observation_b) { |
|
$champ_tri = $this->champ_tri; |
|
$observation_a = isset($observation_a->$champ_tri) ? $observation_a->$champ_tri : -1; |
$observation_b = isset($observation_b->$champ_tri) ? $observation_b->$champ_tri : -1; |
|
if($this->ordre == 'desc') { |
return $observation_a > $observation_b; |
} else { |
return $observation_a < $observation_b; |
} |
} |
|
private function obtenirObservationsAvecImages() { |
return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/obsmock.json')); |
} |