/home/dvjjulio/softtrash/app/Helpers/Helpers.php
<?php

class Helper {

    public static function determinaCals($score){
        switch ($score) {
            case 'p':
                return "Positivo";
                break;
            case 'n':
                return "Neutro";
                break;
            case 'nn':
                return "Negativo";
                break;

            default:
                # code...
                break;
        }
    }

    public static function colorCal($score){
        switch ($score) {
            case 'p':
                return "Green";
                break;
            case 'n':
                return "Gray";
                break;
            case 'nn':
                return "Red";
                break;

            default:
                # code...
                break;
        }
    }
    public static function mark($text,$word){
            $text = trim(preg_replace("/".$word."/i", "<mark>".$word."</mark>", $text));
        return $text;

    }
    public static function get_ip() {
      // $ip =Config::get('rest.ip');

          /* if($ip=="::1")
            {
             $customer="http://192.168.3.154";
            }else{
             $customer="http://187.247.253.5";
            }*/
            $customer="http://187.247.253.5";
       return $customer;
    }

    public static function mostrar_fecha_completa($fecha) {
        $subfecha = explode("-", $fecha);
       // for ($i = 0; $subfecha[$i]; $i++)

        $año = $subfecha[0];
        $mes = $subfecha[1];
        $dia = $subfecha[2];


        $dia2 = date("d", mktime(0, 0, 0, $mes, $dia, $año));
        $mes2 = date("m", mktime(0, 0, 0, $mes, $dia, $año));
        $año2 = date("Y", mktime(0, 0, 0, $mes, $dia, $año));
        $dia_sem = date("w", mktime(0, 0, 0, $mes, $dia, $año));

        switch ($dia_sem) {
            case "0":   // Bloque 1
                $dia_sem3 = 'Domingo';
                break;

            case "1":   // Bloque 1
                $dia_sem3 = 'Lunes';
                break;

            case "2":   // Bloque 1
                $dia_sem3 = 'Martes';
                break;

            case "3":   // Bloque 1
                $dia_sem3 = 'Miercoles';
                break;

            case "4":   // Bloque 1
                $dia_sem3 = 'Jueves';
                break;

            case "5":   // Bloque 1
                $dia_sem3 = 'Viernes';
                break;

            case "6":   // Bloque 1
                $dia_sem3 = 'Sabado';
                break;

            default:   // Bloque 3
        };

        switch ($mes2) {
            case "1":   // Bloque 1
                $mes3 = 'Enero';
                break;

            case "2":   // Bloque 1
                $mes3 = 'Febrero';
                break;

            case "3":   // Bloque 1
                $mes3 = 'Marzo';
                break;

            case "4":   // Bloque 1
                $mes3 = 'Abril';
                break;

            case "5":   // Bloque 1
                $mes3 = 'Mayo';
                break;

            case "6":   // Bloque 1
                $mes3 = 'Junio';
                break;

            case "7":   // Bloque 1
                $mes3 = 'Julio';
                break;

            case "8":   // Bloque 1
                $mes3 = 'Agosto';
                break;

            case "9":   // Bloque 1
                $mes3 = 'Septiembre';
                break;

            case "10":   // Bloque 1
                $mes3 = 'Octubre';
                break;

            case "11":   // Bloque 1
                $mes3 = 'Noviembre';
                break;

            case "12":   // Bloque 1
                $mes3 = 'Diciembre';
                break;

            default:   // Bloque 3
                break;
        };


        $fecha_texto = $dia_sem3 . ' ' . $dia2 . ' ' . 'de' . ' ' . $mes3 . ' ' . 'del' . ' ' . $año2;

        return $fecha_texto;
    }

    public static function getDif($fecha1,$fecha2){
        $fecha1=date_create($fecha1);
        $fecha2=date_create($fecha2);
        $diferencia =  date_diff($fecha1,$fecha2);
        return $diferencia->format("%H:%I:%S");
    }
    public static function distanciaGeodesica($lat1, $long1, $lat2, $long2){

    $degtorad = 0.01745329;
    $radtodeg = 57.29577951;

    $dlong = ($long1 - $long2);
    $dvalue = (sin($lat1 * $degtorad) * sin($lat2 * $degtorad))
    + (cos($lat1 * $degtorad) * cos($lat2 * $degtorad)
    * cos($dlong * $degtorad));

    $dd = acos($dvalue) * $radtodeg;

    $miles = ($dd * 69.16);
    $km = ($dd * 111.302);

        //return number_format($km,2);
        Helper::colorCoor(number_format($km,2));
    }

    public static function colorCoor($val){
        $color = '';
        switch ($val) {
            case ($val <= 1):
                $color = 'success';
                break;
            case ($val > 1) && ($val <= 2):
                $color = 'warning';
                break;
             case ($val > 2):
                $color = 'danger';
                break;

            default:
                break;
        }
        echo $color;
    }

    public static function km_rest($km_f, $km_i){
        echo $km_f - $km_i;
    }

    public static function to_late($obj){
      $time = date('H:i:s');
      $hora_sum = strtotime ( '+2 hours' , strtotime ( $obj->hora ) );
      $time_max = date ( 'H:i:s' , $hora_sum );
      if($obj->orden_no == null){
        if($time_max <= $time ){
          return true;
        }else{
          return false;
        }
      }else{
        return false;
      }
    }

  public static function month($mes3){
    switch ($mes3) {
        case "1":   // Bloque 1
            $mes3 = 'Enero';
            break;

        case "2":   // Bloque 1
            $mes3 = 'Febrero';
            break;

        case "3":   // Bloque 1
            $mes3 = 'Marzo';
            break;

        case "4":   // Bloque 1
            $mes3 = 'Abril';
            break;

        case "5":   // Bloque 1
            $mes3 = 'Mayo';
            break;

        case "6":   // Bloque 1
            $mes3 = 'Junio';
            break;

        case "7":   // Bloque 1
            $mes3 = 'Julio';
            break;

        case "8":   // Bloque 1
            $mes3 = 'Agosto';
            break;

        case "9":   // Bloque 1
            $mes3 = 'Septiembre';
            break;

        case "10":   // Bloque 1
            $mes3 = 'Octubre';
            break;

        case "11":   // Bloque 1
            $mes3 = 'Noviembre';
            break;

        case "12":   // Bloque 1
            $mes3 = 'Diciembre';
            break;

        default:   // Bloque 3
           $mes3 = "Error";
            break;
    };
    return $mes3;
  }

  public static function redondeado ($numero, $decimales) {
     $factor = pow(10, $decimales);
     $numero_decimal = (round($numero*$factor)/$factor);
     return number_format($numero_decimal,$decimales,'.','.');
  }

  public static function getStartAndEndDate($week, $year) {
    $dto = new DateTime();
    $dto->setISODate($year, $week);
    // $ret['week_start'] = $dto->format('Y-m-d');
    $day_start = $dto->format('d');
    $dto->modify('+6 days');
    // $ret['week_end'] = $dto->format('Y-m-d');
    $day_end = $dto->format('d');
    $month = $dto->format('m');
    // return $ret;
    return $day_start."-".$day_end." ".Helper::month($month)." ".$year;
  }

}

?>