Commit 777333b6a41a6d26a50ff6bacee1a757a4e90da3

Authored by Bruno Noronha
1 parent 88d71ec7
Exists in master and in 1 other branch 3.1

modulo mapaController

src/Cacic/WSBundle/Controller/MapaController.php 0 → 100644
... ... @@ -0,0 +1,96 @@
  1 +<?php
  2 +
  3 +namespace Cacic\WSBundle\Controller;
  4 +
  5 +
  6 +use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7 +use Symfony\Component\HttpFoundation\Request;
  8 +use Symfony\Component\HttpFoundation\Response;
  9 +use Cacic\WSBundle\Helper\OldCacicHelper;
  10 +use Cacic\WSBundle\Helper\TagValueHelper;
  11 +
  12 +class MapaController extends Controller {
  13 +
  14 + /**
  15 + * Método responsável por enviar as configurações de Patrimônio necessarias ao Agente CACIC
  16 + * @param Symfony\Component\HttpFoundation\Request $request
  17 + */
  18 + public function mapaAction ( Request $request ) {
  19 +
  20 + $logger = $this->get('logger');
  21 +
  22 + OldCacicHelper::autenticaAgente($request);
  23 + $strNetworkAdapterConfiguration = OldCacicHelper::deCrypt( $request, $request->get('NetworkAdapterConfiguration') );
  24 + $netmask = TagValueHelper::getValueFromTags( 'IPSubnet', $strNetworkAdapterConfiguration );
  25 + $ip_computador = $request->get('te_ip_computador');
  26 + if ( empty($ip_computador) ){
  27 + $ip_computador = TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration );
  28 + }
  29 + if (empty($ip_computador)) {
  30 + $ip_computador = $request->getClientIp();
  31 + }
  32 +
  33 +
  34 + $te_node_address = TagValueHelper::getValueFromTags( 'MACAddress', OldCacicHelper::deCrypt( $request, $request->get('NetworkAdapterConfiguration')));
  35 +
  36 + // Caso não tenha encontrado, tenta pegar a variável da requisição
  37 + if (empty($te_node_address)) {
  38 + $te_node_address = $request->get('te_node_address');
  39 + }
  40 +
  41 + if (empty($netmask)) {
  42 + $netmask = $request->get('netmask');
  43 + }
  44 +
  45 + $so = $this->getDoctrine()->getRepository('CacicCommonBundle:So')->findOneBy( array('teSo'=>$request->get( 'te_so' )));
  46 + $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask );
  47 + $computador = $this->getDoctrine()->getRepository('CacicCommonBundle:Computador')->getComputadorPreCole( $request, $request->get( 'te_so' ),$te_node_address, $rede, $so, $ip_computador );
  48 + $idComputador = $computador->getIdComputador();
  49 + $logger->debug("Teste de Conexão MAPA ! Ip do computador: $ip_computador Máscara da rede: $netmask MAC Address: $te_node_address ID Computador: $idComputador");
  50 +
  51 + $em = $this->getDoctrine()->getManager();
  52 +
  53 + /**
  54 + * Verificar se o módulo está habilitado para o computador;
  55 + */
  56 + $patr = $this->getDoctrine()->getRepository('CacicCommonBundle:AcaoRede')->findOneBy( array('rede'=>$rede->getIdRede(), 'acao'=>'col_patr'));
  57 +
  58 + /**
  59 + * Se o módulo estiver habilitado, verifica se existe coleta de patrimônio
  60 + */
  61 + if (!empty($patr)){
  62 + $query = $em->createQuery(
  63 + 'SELECT COUNT(cc) FROM CacicCommonBundle:ComputadorColeta cc INNER JOIN CacicCommonBundle:ClassProperty cp WHERE cp.idClass = 15 AND cc.computador = :id'
  64 + )->setParameter('id', $computador);
  65 +
  66 + $result = $query->getSingleResult();
  67 +
  68 + $dadosPatrimonio = implode('',$result);
  69 +
  70 + }
  71 +
  72 + if (empty($dadosPatrimonio))
  73 + $modPatrimonio = "True";
  74 + else
  75 + $modPatrimonio = "False";
  76 +
  77 + /**
  78 + * Mensagem a ser exibida na tela de Pop-Up do patrimônio
  79 + */
  80 + $query = $em->createQuery(
  81 + 'SELECT cp.vlConfiguracao FROM CacicCommonBundle:ConfiguracaoPadrao cp WHERE cp.idConfiguracao = :idconfig'
  82 + )->setParameter('idconfig', 'msg_popup_patrimonio');
  83 +
  84 + $result = $query->getSingleResult();
  85 + $mensagem = implode('',$result);
  86 +
  87 + $response = new Response();
  88 + $response->headers->set('Content-Type', 'xml');
  89 +
  90 + return $this->render('CacicWSBundle:Default:mapa.xml.twig', array(
  91 + 'mensagem'=>$mensagem,
  92 + 'modPatrimonio' => $modPatrimonio,
  93 + ), $response);
  94 +
  95 + }
  96 +}
0 97 \ No newline at end of file
... ...