Advertisement
Guest User

Function Index

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