Exemple #1
0
 public function getObjetivos($org)
 {
     if (Auth::guest()) {
         return view('login');
     } else {
         $results = array();
         $objectives = \Ermtool\Objective::where('organization_id', (int) $org)->get();
         $i = 0;
         //contador de objetivos
         foreach ($objectives as $objective) {
             $results[$i] = ['name' => $objective['name'], 'id' => $objective['id']];
             $i += 1;
         }
         return json_encode($results);
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function kpiEdit($id)
 {
     if (Auth::guest()) {
         return view('login');
     } else {
         $obj_selected = array();
         $kpi = \Ermtool\kpi::find($id);
         //obtenemos todos los objetivos de la organización
         $objectives = \Ermtool\Objective::where('organization_id', '=', $_GET['org_id'])->where('status', 0)->lists('name', 'id');
         $org_selected = \Ermtool\Organization::name($_GET['org_id']);
         $stakeholders = \Ermtool\Stakeholder::where('status', 0)->select('id', DB::raw('CONCAT(name, " ", surnames) AS full_name'))->orderBy('name')->lists('full_name', 'id');
         //obtenemos los objetivos relacionados al kpi
         $objs = DB::table('kpi_objective')->where('kpi_id', '=', $kpi->id)->select('objective_id')->get();
         $i = 0;
         foreach ($objs as $obj) {
             $obj_selected[$i] = $obj->objective_id;
             $i += 1;
         }
         if (Session::get('languaje') == 'en') {
             return view('en.gestion_estrategica.editkpi', ['objectives' => $objectives, 'org_selected' => $org_selected, 'org_id' => $_GET['org_id'], 'stakeholders' => $stakeholders, 'obj_selected' => $obj_selected, 'kpi' => $kpi]);
         } else {
             return view('gestion_estrategica.editkpi', ['objectives' => $objectives, 'org_selected' => $org_selected, 'org_id' => $_GET['org_id'], 'stakeholders' => $stakeholders, 'obj_selected' => $obj_selected, 'kpi' => $kpi]);
         }
     }
 }
Exemple #3
0
 public function getObjectives($org)
 {
     $results = array();
     //obtenemos objetivos
     $objectives = \Ermtool\Objective::where('status', 0)->where('organization_id', (int) $org)->select('name', 'id')->groupBy('id')->get();
     $i = 0;
     foreach ($objectives as $objective) {
         $results[$i] = ['id' => $objective->id, 'name' => $objective->name];
         $i += 1;
     }
     return json_encode($results);
 }
Exemple #4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if (Auth::guest()) {
         return view('login');
     } else {
         global $id1;
         $id1 = $id;
         //creamos una transacción para cumplir con atomicidad
         DB::transaction(function () {
             $riesgo = \Ermtool\Risk::find($GLOBALS['id1']);
             //vemos si se agrego alguna causa nueva
             if (isset($_POST['causa_nueva'])) {
                 $new_causa = \Ermtool\Cause::create(['name' => $_POST['causa']]);
                 //guardamos en cause_risk
                 DB::table('cause_risk')->insert(['risk_id' => $riesgo->id, 'cause_id' => $new_causa->id]);
             } else {
                 if (isset($_POST['cause_id'])) {
                     foreach ($_POST['cause_id'] as $cause_id) {
                         //primero buscamos si es que existe previamente
                         $cause = DB::table('cause_risk')->where('cause_id', '=', $cause_id)->where('risk_id', '=', $riesgo->id)->first();
                         if (!$cause) {
                             DB::table('cause_risk')->insert(['risk_id' => $riesgo->id, 'cause_id' => $cause_id]);
                         }
                     }
                 }
             }
             //vemos si se agrego algún efecto nuevo
             if (isset($_POST['efecto_nuevo'])) {
                 $new_effect = \Ermtool\Effect::create(['name' => $_POST['efecto']]);
                 //guardamos en cause_risk
                 DB::table('effect_risk')->insert(['risk_id' => $riesgo->id, 'effect_id' => $new_effect->id]);
             } else {
                 if (isset($_POST['effect_id'])) {
                     foreach ($_POST['effect_id'] as $effect_id) {
                         //primero buscamos si es que existe previamente
                         $effect = DB::table('effect_risk')->where('effect_id', '=', $effect_id)->where('risk_id', '=', $riesgo->id)->first();
                         if (!$effect) {
                             //insertamos cada causa en cause_risk
                             DB::table('effect_risk')->insert(['risk_id' => $riesgo->id, 'effect_id' => $effect_id]);
                         }
                     }
                 }
             }
             //ahora recorreremos todas las causas y efectos de este riesgo, para saber si es que no se borró alguna
             $causas = DB::table('cause_risk')->where('risk_id', '=', $riesgo->id)->select('cause_id')->get();
             foreach ($causas as $cause) {
                 $cont = 0;
                 //si se mantiene en cero, nunca habrán sido iguales, por lo que significa que se habria borrado
                 //ahora recorremos todas las causas que se agregaron para comparar
                 foreach ($_POST['cause_id'] as $cause_add) {
                     if ($cause_add == $cause->cause_id) {
                         $cont += 1;
                     }
                 }
                 if ($cont == 0) {
                     DB::table('cause_risk')->where('risk_id', '=', $riesgo->id)->where('cause_id', '=', $cause->cause_id)->delete();
                 }
             }
             //lo mismo ahora para efectos
             $efectos = DB::table('effect_risk')->where('risk_id', '=', $riesgo->id)->select('effect_id')->get();
             foreach ($efectos as $effect) {
                 $cont = 0;
                 //si se mantiene en cero, nunca habrán sido iguales, por lo que significa que se habria borrado
                 //ahora recorremos todas las causas que se agregaron para comparar
                 foreach ($_POST['effect_id'] as $effect_add) {
                     if ($effect_add == $effect->effect_id) {
                         $cont += 1;
                     }
                 }
                 if ($cont == 0) {
                     DB::table('effect_risk')->where('risk_id', '=', $riesgo->id)->where('effect_id', '=', $effect->effect_id)->delete();
                 }
             }
             if (!isset($_POST['stakeholder_id']) || $_POST['stakeholder_id'] == "") {
                 $stake = NULL;
             } else {
                 $stake = $_POST['stakeholder_id'];
             }
             if ($riesgo->type == 0) {
                 //primero eliminamos relaciones previas
                 DB::table('risk_subprocess')->where('risk_id', '=', $riesgo->id)->delete();
                 //agregamos en tabla risk_subprocess
                 foreach ($_POST['subprocess_id'] as $subprocess_id) {
                     $subprocess = \Ermtool\Subprocess::find($subprocess_id);
                     $subprocess->risks()->attach($riesgo);
                 }
             } else {
                 if ($riesgo->type == 1) {
                     //primero eliminamos relaciones previas
                     DB::table('objective_risk')->where('risk_id', '=', $riesgo->id)->delete();
                     //agregamos en tabla objective_risk
                     foreach ($_POST['objective_id'] as $objective_id) {
                         $objective = \Ermtool\Objective::find($objective_id);
                         $objective->risks()->attach($riesgo);
                     }
                 }
             }
             //eliminamos salto de linea del final de cada una de las textarea (en este caso solo descripción)
             $riesgo->name = $_POST['name'];
             $riesgo->description = $_POST['description'];
             $riesgo->expiration_date = $_POST['expiration_date'];
             $riesgo->type2 = 1;
             $riesgo->risk_category_id = $_POST['risk_category_id'];
             $riesgo->expected_loss = $_POST['expected_loss'];
             $riesgo->stakeholder_id = $stake;
             $riesgo->save();
             if (Session::get('languaje') == 'en') {
                 Session::flash('message', 'Risk successfully updated');
             } else {
                 Session::flash('message', 'Riesgo actualizado correctamente');
             }
         });
         return Redirect::to('riesgos.index2?organization_id=' . $_POST['org_id']);
     }
 }