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 | 150 | if($request->getParam('unidade')){ |
| 151 | 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 | 159 | /** @var $request Slim\Http\Request */ |
| 154 | 160 | $rn = new MdWsSeiUsuarioRN(); |
| 155 | 161 | return $response->withJSON($rn->listarUsuarios($dto)); | ... | ... |
rn/MdWsSeiUsuarioRN.php
| ... | ... | @@ -262,6 +262,14 @@ class MdWsSeiUsuarioRN extends InfraRN { |
| 262 | 262 | protected function listarUsuariosConectado(UnidadeDTO $unidadeDTOParam){ |
| 263 | 263 | try{ |
| 264 | 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 | 273 | if($unidadeDTOParam->isSetNumIdUnidade()){ |
| 266 | 274 | $idUnidade = $unidadeDTOParam->getNumIdUnidade(); |
| 267 | 275 | } |
| ... | ... | @@ -274,7 +282,10 @@ class MdWsSeiUsuarioRN extends InfraRN { |
| 274 | 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 | 289 | $result[] = array( |
| 279 | 290 | 'id_usuario' => $data[0], |
| 280 | 291 | 'id_origem' => $data[1], |
| ... | ... | @@ -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 | 302 | }catch (Exception $e){ |
| 292 | 303 | return MdWsSeiRest::formataRetornoErroREST($e); |
| 293 | 304 | } | ... | ... |