Commit a87a60feea800177b55d69d4aaeb622cbae1d184
1 parent
99facf92
Exists in
master
and in
1 other branch
[Feat] Paginando usuários
Showing
2 changed files
with
19 additions
and
2 deletions
Show diff stats
controlador_ws.php
| @@ -150,6 +150,12 @@ $app->group('/api/v1',function(){ | @@ -150,6 +150,12 @@ $app->group('/api/v1',function(){ | ||
| 150 | if($request->getParam('unidade')){ | 150 | if($request->getParam('unidade')){ |
| 151 | $dto->setNumIdUnidade($request->getParam('unidade')); | 151 | $dto->setNumIdUnidade($request->getParam('unidade')); |
| 152 | } | 152 | } |
| 153 | + if($request->getParam('limit')){ | ||
| 154 | + $dto->setNumMaxRegistrosRetorno($request->getParam('limit')); | ||
| 155 | + } | ||
| 156 | + if(!is_null($request->getParam('start'))){ | ||
| 157 | + $dto->setNumPaginaAtual($request->getParam('start')); | ||
| 158 | + } | ||
| 153 | /** @var $request Slim\Http\Request */ | 159 | /** @var $request Slim\Http\Request */ |
| 154 | $rn = new MdWsSeiUsuarioRN(); | 160 | $rn = new MdWsSeiUsuarioRN(); |
| 155 | return $response->withJSON($rn->listarUsuarios($dto)); | 161 | return $response->withJSON($rn->listarUsuarios($dto)); |
rn/MdWsSeiUsuarioRN.php
| @@ -262,6 +262,14 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -262,6 +262,14 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
| 262 | protected function listarUsuariosConectado(UnidadeDTO $unidadeDTOParam){ | 262 | protected function listarUsuariosConectado(UnidadeDTO $unidadeDTOParam){ |
| 263 | try{ | 263 | try{ |
| 264 | $idUnidade = null; | 264 | $idUnidade = null; |
| 265 | + $limit = 10; | ||
| 266 | + $start = 0; | ||
| 267 | + if($unidadeDTOParam->isSetNumMaxRegistrosRetorno()){ | ||
| 268 | + $limit = $unidadeDTOParam->getNumMaxRegistrosRetorno(); | ||
| 269 | + } | ||
| 270 | + if(!is_null($unidadeDTOParam->getNumPaginaAtual())){ | ||
| 271 | + $start = $unidadeDTOParam->getNumPaginaAtual(); | ||
| 272 | + } | ||
| 265 | if($unidadeDTOParam->isSetNumIdUnidade()){ | 273 | if($unidadeDTOParam->isSetNumIdUnidade()){ |
| 266 | $idUnidade = $unidadeDTOParam->getNumIdUnidade(); | 274 | $idUnidade = $unidadeDTOParam->getNumIdUnidade(); |
| 267 | } | 275 | } |
| @@ -274,7 +282,10 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -274,7 +282,10 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
| 274 | false | 282 | false |
| 275 | ); | 283 | ); |
| 276 | 284 | ||
| 277 | - foreach ($ret as $data){ | 285 | + //Paginação lógica pois o SIP não retorna os usuários paginados... |
| 286 | + $total = count($ret); | ||
| 287 | + $paginado = array_slice($ret, ($limit*$start), $limit); | ||
| 288 | + foreach ($paginado as $data){ | ||
| 278 | $result[] = array( | 289 | $result[] = array( |
| 279 | 'id_usuario' => $data[0], | 290 | 'id_usuario' => $data[0], |
| 280 | 'id_origem' => $data[1], | 291 | 'id_origem' => $data[1], |
| @@ -287,7 +298,7 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -287,7 +298,7 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
| 287 | ); | 298 | ); |
| 288 | } | 299 | } |
| 289 | 300 | ||
| 290 | - return MdWsSeiRest::formataRetornoSucessoREST(null, $result); | 301 | + return MdWsSeiRest::formataRetornoSucessoREST(null, $result, $total); |
| 291 | }catch (Exception $e){ | 302 | }catch (Exception $e){ |
| 292 | return MdWsSeiRest::formataRetornoErroREST($e); | 303 | return MdWsSeiRest::formataRetornoErroREST($e); |
| 293 | } | 304 | } |