New file |
0,0 → 1,78 |
<?php |
class ImagesPourObservation extends Del { |
|
private $debut = 0; |
private $limite = 50; |
|
/** |
* Méthode appelée avec une requête de type GET avec une url de la forme |
* http://localhost/jrest/ExempleService/ |
* |
* Sert normalement à renvoyer la description des possibilités du service |
* |
*/ |
public function getRessource() { |
return $this->getElement(array()); |
} |
|
/** |
* Méthode appelée avec une requête de type GET avec une url de la forme |
* http://localhost/jrest/ExempleService/uid[0]/$uid[1]/ etc... |
* |
* Sert normalement à ramener un élément précis indiqué par un identifiant |
* qui se situe dans l'url après le nom du service |
* Le filtrage, le format de retour, les paramètres optionnels ... sont normalement indiqués |
* dans le tableau $_GET |
* Pour obtenir l'élément 2501 dans le format HTML cela pourrait donner |
* http://localhost/jrest/ExempleService/2501?format=HTML |
* |
* @param $uid un tableau contenant les élements passés dans l'url après le nom du service |
* |
*/ |
public function getElement($uid) |
{ |
$format = 'json'; |
|
$this->debut = isset($_GET['debut']) ? $_GET['debut'] : $this->debut; |
$this->limite = isset($_GET['limite']) ? $_GET['limite'] : $this->limite; |
|
if(isset($_GET['format'])) { |
$format = strtolower($_GET['format']); |
} |
|
if(!isset($uid[0]) && !is_numeric($uid[0])) { |
return; |
} |
|
$id_observation = $uid[0]; |
|
switch ($format) { |
|
case 'html': |
|
case 'json': |
$images = $this->obtenirImagesPourObservation(); |
$images_pour_obs = $images->$id_observation; |
$total = count($images_pour_obs); |
$tranche = $images_pour_obs; |
|
$retour = array('total' => $total, |
'contenu' => $tranche |
); |
|
$retour = json_encode($retour); |
$mime = 'application/json'; |
break; |
|
case 'xml': |
break; |
} |
|
$this->envoyer($retour,$mime); |
} |
|
private function obtenirImagesPourObservation() { |
return json_decode(file_get_contents(realpath(dirname(__FILE__)).'/imagesparobsmock.json')); |
} |
} |
?> |