Advertisement
Guest User

Function Index

a guest
Oct 21st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.53 KB | None | 0 0
  1. public function index(){
  2.  
  3.         //----------- PEGANDO INTERVALOS DE DATAS A SEREM APLICADOS A CONSULTA
  4.  
  5.                 date_default_timezone_set('America/Sao_Paulo');
  6.                 // Pega data do Dia
  7.                 $dt2 = date('Y-m-d') ;
  8.                 // Pega Dia Anterior
  9.                 $dt1 = date('Y-m-d', strtotime($dt2. ' - 1 days'));
  10.  
  11.                 $date = date('d/m/Y');
  12.                 $horaAuxiliar = date('H');
  13.  
  14.                 $minuto = date('i');
  15.                 $minutoAnterior1 = $minuto-1;
  16.                 $minutoAnterior5 = $minuto-5;
  17.                 $tempoAnterior1 = (string) $horaAuxiliar.':'.$minutoAnterior1;
  18.                 $tempoAnterior5 = (string) $horaAuxiliar.':'.$minutoAnterior5;
  19.  
  20.         //----------------------- VERIFICA OS COMPUTADORES ONLINE
  21.  
  22.                 $online= DB::table('dados_computador')
  23.                     ->where('data','=', $date)
  24.                     ->where('email', '=', Auth::user()->email)
  25.                     ->whereBetween(DB::raw('substr(informacoes,1,5)'), [$tempoAnterior5,$tempoAnterior1])->
  26.                     ->OrderBy('id','desc')
  27.                     ->LIMIT(250)
  28.                     ->count(DB::raw('DISTINCT usuario'));
  29.  
  30.         //------------------------- MEDE O DESEMPENHO DAS APLICAÇÕES
  31.  
  32.             $vlTotalDesempenho=0;
  33.  
  34.                 $desempenho = DB::table('dados_computador')
  35.                     ->where('email', '=', Auth::user()->email)
  36.                     ->where('aplicacao', '!=', '0')
  37.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2])
  38.                     ->select('aplicacao','informacoes', DB::raw('count(*) as total'))
  39.                     ->groupBy('aplicacao')
  40.                     ->OrderBy('id','ASC')
  41.                     ->get();
  42.  
  43.                 foreach($desempenho as $d){
  44.                     $vlTotalDesempenho += $d->total;
  45.                 }
  46.                 $desempenhoGeral = $vlTotalDesempenho;
  47.  
  48.         //----------------------------- VERIFICA OS COMPUTADORES OCIOSOS
  49.  
  50.                 $ocioso = DB::table('dados_computador')
  51.                     ->where('email', '=', Auth::user()->email)
  52.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2])
  53.                     ->OrderBy('id','ASC')
  54.                     ->get();
  55.  
  56.         //--VERIFICA SE O DADO ATUAL É IGUAL AO ANTERIOR
  57.  
  58.                 $ociosoCont = 0;
  59.                 $ociosoAux = 0;
  60.  
  61.                 foreach($ocioso as $o){
  62.                     if(substr($o->informacoes,5)== $ociosoAux)
  63.                         $ociosoCont++;
  64.                     $ociosoAux =substr($o->informacoes,5);
  65.                 }
  66.  
  67.  
  68.         //---------------------------VERIFICA O DESEMEPNHO UTILIZANDO SOFTWARE
  69.  
  70.                 $desempenhoSoftware = DB::table('dados_computador')
  71.                     ->where('email', '=', Auth::user()->email)
  72.                     ->where('aplicacao', '!=', '0')
  73.                     -> where('aplicacao', '!=', ' ')
  74.                     ->where('aplicacao', '!=', ' Google Chrome')
  75.                     ->where('aplicacao', '!=', ' Mozilla Firefox')
  76.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2])
  77.                     ->select( DB::raw('count(*) as total'))
  78.                     ->OrderBy('id','ASC')
  79.                     ->get();
  80.  
  81.         //---------------------------------VERIFICA O DESEMEPNHO UTILIZANDO NAVEGADORES ESPECIFICOS
  82.  
  83.                 $desempenhoNavegador = DB::table('dados_computador')
  84.                     ->where('email', '=', Auth::user()->email)
  85.                     ->whereIn('aplicacao', [' Google Chrome',' Mozilla Firefox'])
  86.                     ->select('aplicacao', DB::raw('count(*) as total'))
  87.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2])
  88.                     ->OrderBy('id','ASC')
  89.                     ->get();
  90.  
  91.         //--------------------------------- VERIFICA OS ACESSOS INDEVIDOS
  92.  
  93.                 $indevidosCont = DB::table('tempindevidos')
  94.                     ->where('email', '=', Auth::user()->email)
  95.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2])
  96.                     ->select('acesso','nome','hora','horaTemp','id', DB::raw('count(*) as total'))
  97.                     -> groupBy('acesso')->get();
  98.  
  99.         //--------------------------------- PEGA OS USUARIOS DOS COMPUTADORES
  100.  
  101.                 $computador = DB::table('dados_usuario')->
  102.                 where('email', '=', Auth::user()->email)->
  103.                 select(DB::raw('usuario', 'count(*) as valorTotal'))->
  104.                 groupBy('usuario')->get();
  105.  
  106.         //--------------------------------- CONTAS PARA EXIBIR NÚMEROS GERAIS
  107.  
  108.                 $geral = 0;
  109.                 $geral += $desempenhoGeral;
  110.  
  111.                 $contP = 0;
  112.                 foreach(  $desempenhoSoftware as $d){
  113.                     $contP = $d->total;
  114.                 }
  115.                 $contN = 0;
  116.  
  117.                 foreach(  $desempenhoNavegador as $n){
  118.                     $contN = $n->total;
  119.                 }
  120.                 if($contN!=0 && $contP!=0){
  121.  
  122.                     $vlInternet = ($contN*100)/$geral;
  123.                     $vlProgramas = ($contP*100)/$geral;
  124.                     $vlInternet = round($vlInternet);
  125.                     $vlProgramas = round($vlProgramas );
  126.                 }else{
  127.  
  128.                     $vlInternet = 0;
  129.                     $vlProgramas = 0;
  130.  
  131.                 }
  132.  
  133.         //----------------------- PEGA OS DADOS DE IMPRESSÕES
  134.  
  135.                 $impressora = DB::table('impressora')
  136.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2])
  137.                     ->where('email', '=', Auth::user()->email)
  138.                     ->groupBy('impressora')
  139.                     ->get();
  140.  
  141.         //----------------------- QUANTIDADE DE IMPRESSÕES
  142.  
  143.                 $qtdImpressora = DB::table('impressora')
  144.                     ->whereBetween(DB::raw("date_format(STR_TO_DATE(data, '%d/%m/%Y'),'%Y-%m-%d')"),[$dt1,$dt2] )
  145.                     ->where('email', '=', Auth::user()->email)
  146.                     ->Select(DB::raw('count(*) as vlx'))
  147.                     ->get();
  148.  
  149.         //------- CRUZA OS DADOS PARA ENCONTRAR O SOFTWARE QUE EFETUOU A IMPRESSÃO
  150.  
  151.                 $ar = array();
  152.                 $novo = array();
  153.  
  154.                 foreach($impressora as $a){
  155.                     $ar[] = appImpressora($a->data,$a->hora,$a->email,$a->computador);
  156.                 }
  157.  
  158.                 $qtd = count($ar);
  159.  
  160.                 for ($i=0; $i < $qtd ; $i++) {
  161.                     if(!empty($ar[$i]->aplicacao))
  162.                         $novo[] = $ar[$i]->aplicacao;
  163.                 }
  164.                 $impGrafico = array_count_values($novo);
  165.  
  166.          //--------------------------------- CONTA O NÚMERO DE COMPUTADORES VINCULADO A CONTA
  167.  
  168.                 $vlx = 0;
  169.                 $numeroComputador = DB::table('dados_usuario')
  170.                     ->where('email', '=', Auth::user()->email)
  171.                     ->select('usuario')
  172.                     ->GroupBy('usuario')
  173.                     ->get();
  174.                 foreach($numeroComputador as $n){
  175.                     $vlx+=1;
  176.  
  177.                 }
  178.                 $numeroComputador = $vlx;
  179.  
  180.         //--------------------------------- MOSTRA OS 50 RECENTES ACESSOS INDEVIDOS
  181.  
  182.                 $aviso = DB::table('tempindevidos')
  183.                     ->where('email', '=', Auth::user()->email)
  184.                     ->where('segundos', '=','10')
  185.                     ->orderBy('id','asc')
  186.                     ->take('50');
  187.  
  188.         //-------------- RETORNA PARA HOME
  189.  
  190.                 return view('home')
  191.                     ->with('usuarios', $online)->with('desempenho', $desempenho)->with('ocioso',0)
  192.                     ->with('indevidos', 0)->with('indevidosCont',$indevidosCont)
  193.                     ->with('Programa', $vlProgramas)->with('navegador', $vlInternet)
  194.                     ->with('nComputador',  $numeroComputador)->with('nRegistro', 0)->with('computador', $computador )
  195.                     ->with('contadorOnline',$online)->with('ocioso',$ociosoCont)->with('impressora',$impressora)
  196.                     ->with('tdGeral',$geral)->with('aviso',$aviso)
  197.                     ->with('impGrafico',$impGrafico)
  198.                     ->with('dt1',$dt1)
  199.                     ->with('dt2',$dt2)
  200.                     ->with('qtdImpressora',$qtdImpressora);
  201.  
  202.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement