function getMetOrgDataByValue($valId) { $value = getGeneric($this, $this->value, ['id' => [$valId]])[0]; $metOrg = getGeneric($this, $this->title, ['id' => [$value->metorg]])[0]; $metric = getGeneric($this, $this->metric, ['id' => [$metOrg->metric]])[0]; $metric->metric = $metric->id; $metric->id = $metOrg->id; $metric->org = $metOrg->org; return $metric; }
function getOrCreateDashboard($org) { $this->db->from($this->dashboard); $this->db->where('org', $org); $q = $this->db->get(); if (count($q->result()) == 0) { $organization = getGeneric($this, $this->org, ['id' => [$org]]); if (count($organization) == 0) { return false; } $organization = $organization[0]; $this->db->insert($this->dashboard, ['org' => $org, 'title' => 'Dashboard ' . $organization->name]); $id = $this->db->insert_id(); $q = $this->db->get_where($this->dashboard, array('id' => $id)); return count($q->result()) == 1 ? $q->row() : false; } return $q->row(); }
function getPermit($data) { return getGeneric($this, $this->permit, $data); }
public function validar() { if (is_null($this->session->rut)) { redirect('salir'); } $permits = $this->session->userdata(); $prod = array_unique(array_merge($permits['foda']['validate'], $permits['metaP']['validate'])); $finan = array_unique(array_merge($permits['valorF']['validate'], $permits['metaF']['validate'])); if (!count($prod) && !count($finan)) { redirect('inicio'); } $this->load->model('Dashboard_model'); $this->load->model('Organization_model'); $this->load->model('User_model'); $success = $this->session->flashdata('success'); if (is_null($success)) { $success = 2; } if (count($prod) && count($finan)) { $orgs = array_unique(array_merge($prod, $finan)); $category = null; } elseif (count($prod)) { $orgs = $prod; $category = 1; } elseif (count($finan)) { $orgs = $finan; $category = 2; } $data = array(); foreach ($orgs as $org) { $data[$org]['org'] = $this->Organization_model->getByID($org); $metrics = $this->Dashboard_model->getAllMetrics($org, $category, 1); $metrics = !$metrics ? [] : $metrics; foreach ($metrics as $metric) { $perm['valor'] = $metric->category == 1 ? in_array($org, $permits['foda']['validate']) : in_array($org, $permits['valorF']['validate']); $perm['meta'] = $metric->category == 1 ? in_array($org, $permits['metaP']['validate']) : in_array($org, $permits['metaF']['validate']); $data[$org]['metorg'][$metric->metorg]['permits'] = $perm; $data[$org]['metorg'][$metric->metorg]['metric'] = $metric; $values = getGeneric($this->Dashboard_model, $this->Dashboard_model->value, array('metorg' => [$metric->metorg], 'state' => [0, -1], 'order' => [['year', 'ASC'], ['x_value', 'ASC'], ['proposed_x_value', 'ASC']])); $data[$org]['metorg'][$metric->metorg]['values'] = $values; for ($i = 0; $i < count($values); $i++) { $value = $values[$i]; //quitar el valor si este se eliminara y no se tiene permiso para validar la eliminacion //o si el elemento se modificara y no se tienen los permisos para el valor if ($value->state == -1 && !$perm['meta'] || $value->state == 0 && (!$value->proposed_value && $perm['valor'] && !$perm['meta'] || !$value->proposed_expected && !$value->proposed_target && !$value->proposed_x_value && !$perm['valor'] && $perm['meta'])) { unset($data[$org]['metorg'][$metric->metorg]['values'][$i]); } } if (!count($data[$org]['metorg'][$metric->metorg]['values'])) { unset($data[$org]['metorg'][$metric->metorg]); } } if (!key_exists('metorg', $data[$org]) || !count($data[$org]['metorg'])) { unset($data[$org]); } } $users = []; foreach ($this->User_model->getAllUsers() as $user) { $users[$user->id] = $user->name; } $result = defaultResult($permits, $this->Dashboard_model); $result['success'] = $success; $result['users'] = $users; $result['data'] = $data; $this->load->view('validar', $result); }
function validateData($id, $validVal, $validMet) { $this->load->library('session'); $query = $this->db->get_where('Value', array('id' => $id)); $value = $query->row(); $old_x = $value->x_value; if ($value->state == -1) { $values = getGeneric($this, $this->value, ['metorg' => [$value->metorg], 'year' => [$value->year], 'x_value' => [$value->x_value], 'id !=' => [$value->id], 'order' => [['state', "ASC"]]]); $done = $this->deleteData($value->id, $validVal, $validMet); foreach ($values as $v) { $done = $done && $this->deleteData($v->id, $validVal, $validMet); } return $done; } $value2 = clone $value; $data = array('state' => 1, 'validator' => $this->session->userdata('rut')); $this->load->model('Metorg_model'); $metorg = $this->Metorg_model->getMetOrgDataByValue($value->id); if ($metorg->x_name == "") { $data['x_value'] = ""; $data['proposed_x_value'] = null; $value2->proposed_x_value = null; } if ($validVal && !is_null($value->proposed_value)) { $data['value'] = $value->proposed_value; $data['proposed_value'] = null; $value2->proposed_value = null; } if ($validMet && !is_null($value->proposed_target)) { $data['target'] = $value->proposed_target; $data['proposed_target'] = null; $value2->proposed_target = null; } if ($validMet && !is_null($value->proposed_expected)) { $data['expected'] = $value->proposed_expected; $data['proposed_expected'] = null; $value2->proposed_expected = null; } if ($validMet && !is_null($value->proposed_x_value)) { $data['x_value'] = $value->proposed_x_value; $data['proposed_x_value'] = null; $value2->proposed_x_value = null; } if ((!array_key_exists('x_value', $data) || is_null($data['x_value'])) && (!array_key_exists('value', $data) || is_null($data['value'])) && (!array_key_exists('expected', $data) || is_null($data['expected'])) && (!array_key_exists('target', $data) || is_null($data['target']))) { return false; } if (!is_null($value2->proposed_value) || !is_null($value2->proposed_target) || !is_null($value2->proposed_expected) || !is_null($value2->proposed_x_value)) { $data2 = array('metorg' => $value->metorg, 'year' => $value->year, 'updater' => $value->updater, 'dateup' => $value->dateup, 'value' => $value->value, 'x_value' => $value->x_value, 'target' => $value->target, 'expected' => $value->expected, 'state' => 0, 'proposed_value' => $value2->proposed_value, 'proposed_target' => $value2->proposed_target, 'proposed_expected' => $value2->proposed_expected, 'proposed_x_value' => $value2->proposed_x_value); $data['proposed_value'] = null; $data['proposed_target'] = null; $data['proposed_expected'] = null; $data['proposed_x_value'] = null; $this->db->insert($this->value, $data2); } $data['dateval'] = date('Y-m-d H:i:s'); $this->db->reset_query(); $this->db->where('id', $id); $q = $this->db->update($this->value, $data); if (!is_null($old_x)) { $this->_overrideData($value->metorg, $value->year, $old_x, $id); } $query = $this->db->get_where($this->value, array('id' => $id)); $value = $query->row(); $values = $this->getValue(array('metorg' => [$value->metorg], 'year' => [$value->year], 'x_value' => [$old_x, null], 'id !=' => [$id])); $this->updateValuesWith($values, array('value' => $value->value, 'expected' => $value->expected, 'target' => $value->target, 'x_value' => $value->x_value), 1); return $q; }
public function getGoalItem($data) { return getGeneric($this, $this->goalItem, $data); }
public function getType($data) { return getGeneric($this, $this->type, $data); }
function getMetric($data) { return getGeneric($this, $this->title, $data); }
function getAllIds() { $orgs = getGeneric($this, $this->title, array()); $result = array(); foreach ($orgs as $org) { $result[] = $org->id; } return $result; }