Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 467 → Rev 468

/trunk/jrest/services/Observations.php
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'));
}
/trunk/jrest/services/Images.php
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'));
}