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/ |
31,10 → 35,15 |
*/ |
public function getElement($uid) |
{ |
$format = 'html'; |
$format = 'json'; |
|
$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']); |
48,11 → 57,14 |
$images = $this->obtenirImagesAvecObservations(); |
|
$total = count($images); |
if($this->tri_demande) { |
usort($images, array($this,'comparerObservations')); |
} |
$tranche = array_slice($images,$this->debut,$this->limite); |
|
$retour = array('total' => count($images), |
$retour = array('total' => $total, |
'contenu' => $tranche |
); |
); |
|
$retour = json_encode($retour); |
$mime = 'application/json'; |
65,6 → 77,20 |
$this->envoyer($retour,$mime); |
} |
|
private function comparerObservations($image_a, $image_b) { |
|
$champ_tri = $this->champ_tri; |
|
$champ_a_comparer_a = isset($image_a->observation->$champ_tri) ? $image_a->observation->$champ_tri : 0; |
$champ_a_comparer_b = isset($image_b->observation->$champ_tri) ? $image_b->observation->$champ_tri : 0; |
|
if($this->ordre == 'desc') { |
return $champ_a_comparer_a > $champ_a_comparer_b; |
} else { |
return $champ_a_comparer_a < $champ_a_comparer_b; |
} |
} |
|
private function obtenirImagesAvecObservations() { |
return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesmock.json')); |
} |