Commit 8bbbbeab12c25b3376c7b488be620a3fd539d6d4
1 parent
5ab7249e
Exists in
master
Relatório de úsuário logado
Showing
1 changed file
with
113 additions
and
0 deletions
Show diff stats
src/Cacic/RelatorioBundle/Controller/FaturamentoController.php
| @@ -417,4 +417,117 @@ | @@ -417,4 +417,117 @@ | ||
| 417 | ) | 417 | ) |
| 418 | ); | 418 | ); |
| 419 | } | 419 | } |
| 420 | + | ||
| 421 | + /* | ||
| 422 | + * Página inicial do Relatório de usuário logado | ||
| 423 | + */ | ||
| 424 | + public function usuarioAction(Request $request) { | ||
| 425 | + | ||
| 426 | + $locale = $request->getLocale(); | ||
| 427 | + | ||
| 428 | + $form = $this->createForm( new LogPesquisaType() ); | ||
| 429 | + return $this->render( 'CacicRelatorioBundle:Faturamento:usuario.html.twig', | ||
| 430 | + array( | ||
| 431 | + 'locale'=> $locale, | ||
| 432 | + 'form' => $form->createView() | ||
| 433 | + ) | ||
| 434 | + ); | ||
| 435 | + } | ||
| 436 | + | ||
| 437 | + /* | ||
| 438 | + * Página que exibe o resultado da consulta de usuário logado | ||
| 439 | + */ | ||
| 440 | + public function usuarioDetalharAction( Request $request) { | ||
| 441 | + | ||
| 442 | + $locale = $request->getLocale(); | ||
| 443 | + $form = $this->createForm( new LogPesquisaType() ); | ||
| 444 | + | ||
| 445 | + if ( $request->isMethod('POST') ) | ||
| 446 | + { | ||
| 447 | + $form->bind( $request ); | ||
| 448 | + $data = $form->getData(); | ||
| 449 | + | ||
| 450 | + $filtroLocais = array(); // Inicializa array com locais a pesquisar | ||
| 451 | + foreach ( $data['idLocal'] as $locais ) { | ||
| 452 | + array_push( $filtroLocais, $locais->getIdLocal() ); | ||
| 453 | + } | ||
| 454 | + | ||
| 455 | + $dataInicio = $data['dtAcaoInicio']; | ||
| 456 | + $dataFim = $data['dtAcaoFim']; | ||
| 457 | + $usuario = $data['usuario']; | ||
| 458 | + | ||
| 459 | + $dados = $this->getDoctrine() | ||
| 460 | + ->getRepository('CacicCommonBundle:LogAcesso') | ||
| 461 | + ->gerarRelatorioUsuario($filtros = array(),$filtroLocais, $dataInicio, $dataFim, $usuario); | ||
| 462 | + | ||
| 463 | + } | ||
| 464 | + | ||
| 465 | + return $this->render( | ||
| 466 | + 'CacicRelatorioBundle:Faturamento:usuarioDetalhar.html.twig', | ||
| 467 | + array( | ||
| 468 | + 'idioma' => $locale, | ||
| 469 | + 'dados' => ( isset( $dados ) ? $dados : null ), | ||
| 470 | + 'idRede' => $filtroLocais, | ||
| 471 | + 'dtAcaoInicio' => $dataInicio, | ||
| 472 | + 'dtAcaoFim' => $dataFim, | ||
| 473 | + 'usuario' => $usuario | ||
| 474 | + | ||
| 475 | + ) | ||
| 476 | + ); | ||
| 477 | + } | ||
| 478 | + | ||
| 479 | + /* | ||
| 480 | + * Gera o CSV do relatório de usuário logado | ||
| 481 | + */ | ||
| 482 | + public function usuarioCsvAction( Request $request) { | ||
| 483 | + | ||
| 484 | + $locale = $request->getLocale(); | ||
| 485 | + $form = $this->createForm( new LogPesquisaType() ); | ||
| 486 | + | ||
| 487 | + if ( $request->isMethod('POST') ) | ||
| 488 | + { | ||
| 489 | + $form->bind( $request ); | ||
| 490 | + $data = $form->getData(); | ||
| 491 | + | ||
| 492 | + $filtroLocais = array(); // Inicializa array com locais a pesquisar | ||
| 493 | + foreach ( $data['idLocal'] as $locais ) { | ||
| 494 | + array_push( $filtroLocais, $locais->getIdLocal() ); | ||
| 495 | + } | ||
| 496 | + | ||
| 497 | + $dataInicio = $data['dtAcaoInicio']; | ||
| 498 | + $dataFim = $data['dtAcaoFim']; | ||
| 499 | + $usuario = $data['usuario']; | ||
| 500 | + | ||
| 501 | + $dados = $this->getDoctrine() | ||
| 502 | + ->getRepository('CacicCommonBundle:LogAcesso') | ||
| 503 | + ->gerarRelatorioUsuario($filtros = array(),$filtroLocais, $dataInicio, $dataFim, $usuario); | ||
| 504 | + | ||
| 505 | + } | ||
| 506 | + | ||
| 507 | + // Gera CSV | ||
| 508 | + $reader = new ArrayReader($dados); | ||
| 509 | + | ||
| 510 | + // Create the workflow from the reader | ||
| 511 | + $workflow = new Workflow($reader); | ||
| 512 | + | ||
| 513 | + $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader)); | ||
| 514 | + | ||
| 515 | + // Add the writer to the workflow | ||
| 516 | + $tmpfile = tempnam(sys_get_temp_dir(), 'Máquinas sem Coletas'); | ||
| 517 | + $file = new \SplFileObject($tmpfile, 'w'); | ||
| 518 | + $writer = new CsvWriter($file); | ||
| 519 | + $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações')); | ||
| 520 | + $workflow->addWriter($writer); | ||
| 521 | + | ||
| 522 | + // Process the workflow | ||
| 523 | + $workflow->process(); | ||
| 524 | + | ||
| 525 | + // Retorna o arquivo | ||
| 526 | + $response = new BinaryFileResponse($tmpfile); | ||
| 527 | + $response->headers->set('Content-Type', 'text/csv'); | ||
| 528 | + $response->headers->set('Content-Disposition', 'attachment; filename="Não_Coletadas.csv"'); | ||
| 529 | + $response->headers->set('Content-Transfer-Encoding', 'binary'); | ||
| 530 | + | ||
| 531 | + return $response; | ||
| 532 | + } | ||
| 420 | } | 533 | } |
| 421 | \ No newline at end of file | 534 | \ No newline at end of file |