public function desbloquear($id)
 {
     if (Auth::guest()) {
         return view('login');
     } else {
         global $id1;
         $id1 = $id;
         DB::transaction(function () {
             $risk_category = \Ermtool\Risk_category::find($GLOBALS['id1']);
             $risk_category->status = 0;
             $risk_category->save();
             if (Session::get('languaje') == 'en') {
                 Session::flash('message', 'Risk category successfully unblocked');
             } else {
                 Session::flash('message', 'Categoría de riesgo desbloqueada correctamente');
             }
         });
         return Redirect::to('/categorias_risks');
     }
 }
Exemple #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if (Auth::guest()) {
         return view('login');
     } else {
         $riesgostipo = array();
         if (isset($_GET['verbloqueados'])) {
             $riesgostipo2 = \Ermtool\Risk::where('type2', 0)->where('status', 1)->get();
             //select riesgos tipo bloqueados
         } else {
             $riesgostipo2 = \Ermtool\Risk::where('type2', 0)->where('status', 0)->get();
             //select riesgos tipo desbloqueados
         }
         $i = 0;
         // ---recorremos todos los riesgos tipo para asignar formato de datos correspondientes--- //
         foreach ($riesgostipo2 as $riesgo) {
             //damos formato a fecha expiración
             if ($riesgo['expiration_date'] == NULL or $riesgo['expiration_date'] == "0000-00-00") {
                 $fecha_exp = NULL;
             } else {
                 $expiration_date = new DateTime($riesgo['expiration_date']);
                 $fecha_exp = date_format($expiration_date, 'd-m-Y');
                 $fecha_exp .= " a las " . date_format($expiration_date, "H:i:s");
             }
             //damos formato a fecha creación
             if ($riesgo['created_at'] != NULL) {
                 $fecha_creacion = date_format($riesgo['created_at'], "d-m-Y");
             } else {
                 $fecha_creacion = NULL;
             }
             //damos formato a fecha de actualización
             if ($riesgo['updated_at'] != NULL) {
                 $fecha_act = date_format($riesgo['updated_at'], "d-m-Y");
             } else {
                 $fecha_act = NULL;
             }
             //obtenemos categoría de riesgo
             $categoria = \Ermtool\Risk_category::find($riesgo['risk_category_id']);
             //obtenemos causas si es que tiene
             $causes = DB::table('cause_risk')->join('causes', 'causes.id', '=', 'cause_risk.cause_id')->where('cause_risk.risk_id', '=', $riesgo['id'])->select('causes.name')->get();
             if ($causes) {
                 $causas = array();
                 $j = 0;
                 foreach ($causes as $cause) {
                     $causas[$j] = $cause->name;
                     $j += 1;
                 }
             } else {
                 $causas = NULL;
             }
             //obtenemos efectos si es que existen
             $effects = DB::table('effect_risk')->join('effects', 'effects.id', '=', 'effect_risk.effect_id')->where('effect_risk.risk_id', '=', $riesgo['id'])->select('effects.name')->get();
             if ($effects) {
                 $efectos = array();
                 $j = 0;
                 foreach ($effects as $effect) {
                     $efectos[$j] = $effect->name;
                     $j += 1;
                 }
             } else {
                 $efectos = NULL;
             }
             $riesgostipo[$i] = array('id' => $riesgo['id'], 'nombre' => $riesgo['name'], 'descripcion' => $riesgo['description'], 'fecha_creacion' => $fecha_creacion, 'fecha_act' => $fecha_act, 'fecha_exp' => $fecha_exp, 'causas' => $causas, 'efectos' => $efectos, 'categoria' => $categoria['name'], 'estado' => $riesgo['status']);
             $i += 1;
         }
         if (Session::get('languaje') == 'en') {
             return view('en.datos_maestros.riesgos_tipo.index', ['riesgos' => $riesgostipo]);
         } else {
             return view('datos_maestros.riesgos_tipo.index', ['riesgos' => $riesgostipo]);
         }
     }
 }