33,14 → 33,10 |
class ListeObservations2 { |
|
private $conteneur; |
private $navigation; |
private $masque; |
private $gestionBdd; |
private $bdd; |
private $parametres = array(); |
private $ressources = array(); |
private $tri = 'date_transmission'; |
private $directionTri = 'desc'; |
|
static $tris_possibles = array('date_observation'); |
// paramètres autorisés |
137,7 → 133,7 |
$db = $this->bdd; |
|
// filtrage de l'INPUT |
$params = self::requestFilterParams($parametres, $this->conteneur); |
$params = self::requestFilterParams($parametres, self::$parametres_autorises, $this->conteneur); |
// création des contraintes (masques) |
self::sqlAddConstraint($params, $db, $req, $this->conteneur); |
|
169,28 → 165,7 |
|
// 6) JSON output |
$resultat = new ResultatService(); |
|
$prev_url = $next_url = NULL; |
|
$next_offset = $params['navigation.depart'] + $params['navigation.limite']; |
if($next_offset < $total) { |
$next_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : Config::get('url_service'), |
http_build_query(array_merge($params, array('navigation.depart' => $next_offset)))); |
} |
$prev_offset = $params['navigation.depart'] - $params['navigation.limite']; |
if($prev_offset > 0) { |
$prev_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : Config::get('url_service'), |
http_build_query(array_merge($params, array('navigation.depart' => $prev_offset)))); |
} |
|
$resultat->corps = array('entete' => array( |
'masque' => http_build_query(array_diff_key($params, array_flip(array('navigation.depart', 'navigation.limite', 'tri', 'ordre')))), |
'total' => $total, |
'depart' => $params['navigation.depart'], |
'limite' => $params['navigation.limite'], |
'href.precedent' => $prev_url, |
'href.suivant' => $next_url |
), |
$resultat->corps = array('entete' => self::makeJSONHeader($total, $params, Config::get('url_service')), |
'resultats' => $observations); |
|
return $resultat; |
342,7 → 317,7 |
$req['where'][] = 'dob.nom_sel LIKE '.$db->proteger($p['masque.ns'].'%'); |
} |
if(!empty($p['masque.nn'])) { |
$req['where'][] = sprintf('dob.nom_sel_nn = %d', $p['masque.nn']); |
$req['where'][] = sprintf('dob.nom_sel_nn = %1$d OR dob.nom_ret_nn = %1$d', $p['masque.nn']); |
} |
if(!empty($p['masque.referentiel'])) { |
$req['where'][] = sprintf('dob.nom_referentiel = %s', $db->proteger($p['masque.referentiel'])); |
375,7 → 350,7 |
'masque.date' => $p['masque'], |
'masque.genre' => $p['masque'], |
/* milieu: TODO */ ); |
$or_masque = self::requestFilterParams($or_params, $c); |
$or_masque = self::requestFilterParams($or_params, array_keys($or_params), $c); |
// $or_req = array('select' => array(), 'join' => array(), 'where' => array(), 'groupby' => array(), 'having' => array()); |
$or_req = array('join' => array(), 'where' => array()); |
self::sqlAddConstraint($or_masque, $db, $or_req); |
566,8 → 541,8 |
|
/* filtre et valide les paramètres reconnus. |
Effectue *toute* la sanitization *sauf* l'escape-string */ |
static function requestFilterParams(Array $params, Conteneur $c = NULL /* pour la récup des départements */ ) { |
$params = array_intersect_key($params, array_flip(self::$parametres_autorises)); |
static function requestFilterParams(Array $params, $parametres_autorises, Conteneur $c = NULL /* pour la récup des départements */ ) { |
$params = array_intersect_key($params, array_flip($parametres_autorises)); |
|
$p['tri'] = self::unsetIfInvalid($params, 'tri', array('date_observation')); |
$p['ordre'] = self::unsetIfInvalid($params, 'ordre', array('asc','desc')); |
689,4 → 664,28 |
return $p; |
} |
|
static function makeJSONHeader($total, $params, $url_service) { |
$prev_url = $next_url = NULL; |
|
$next_offset = $params['navigation.depart'] + $params['navigation.limite']; |
if($next_offset < $total) { |
$next_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $url_service, |
http_build_query(array_merge($params, array('navigation.depart' => $next_offset)))); |
} |
|
$prev_offset = $params['navigation.depart'] - $params['navigation.limite']; |
if($prev_offset > 0) { |
$prev_url = sprintf("http://%s?%s", isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $url_service, |
http_build_query(array_merge($params, array('navigation.depart' => $prev_offset)))); |
} |
|
return array( |
'masque' => http_build_query(array_diff_key($params, array_flip(array('navigation.depart', 'navigation.limite', 'tri', 'ordre')))), |
'total' => $total, |
'depart' => $params['navigation.depart'], |
'limite' => $params['navigation.limite'], |
'href.precedent' => $prev_url, |
'href.suivant' => $next_url |
); |
} |
} |