public function company_tree() { $this->load->model('companies_model', 'companies'); $result = $this->companies->get_sector(); $json = '{"name": "Companies","children": ['; $v1_count = count($result); $i = 1; foreach ($result as $row) { $json .= '{'; $json .= '"name": "' . string_to_json($row->sector) . '",'; $json .= '"children": ['; $result_industry = $this->companies->get_industry_and_count($row->sector); $v2_count = count($result_industry); $j = 1; foreach ($result_industry as $row2) { $json .= '{'; $name = $row2->industry . '\\n # Companies: ' . $row2->count; $json .= '"name": "' . $name . '",'; $json .= '"id": "' . $row2->industry . '",'; $json .= '"size": "' . $row2->count . '"'; $json .= '}'; if ($j != $v2_count) { $json .= ','; } $j++; } $json .= ']'; $json .= '}'; if ($i != $v1_count) { $json .= ','; } $i++; } $json .= ']'; $json .= '}'; $data['json'] = $json; $this->load->view('commun/json_view', $data); }
public function tree() { $this->load->model('explore_model'); $this->load->model('card_companies_model'); $this->load->model('card_kpis_model'); $s_companies = $this->input->get('companies'); $list_companies = array(); if (empty($s_companies)) { $where = array("card" => $this->input->get('id')); $companies = $this->card_companies_model->list_records($where); foreach ($companies as $c) { $list_companies[] = sprintf("%06d", $c->company); } } else { $r_companies = explode(",", $s_companies); foreach ($r_companies as $c) { if (!empty($c)) { $list_companies[] = sprintf("%06d", $c); } } } $s_kpis = $this->input->get('kpis'); $r_kpis = explode(",", $s_kpis); $list_kpis = array(); foreach ($r_kpis as $c) { if (!empty($c)) { $list_kpis[] = sprintf("%06d", $c); } } $kpi = $this->input->get('kpi'); if (empty($kpi)) { $kpi = $r_kpis[0]; } $kpi = sprintf("%06d", $kpi); $period = array($this->input->get('period')); $_companies = $this->explore_model->get_companies_api($list_companies, $list_kpis, $period, $kpi); unset($_companies['datasources']); if ($_companies == "API_ERROR") { $data['API_ERROR'] = "API_ERROR"; } else { $sectors = array(); $_companies = $this->remove_null_comps($_companies, $kpi); foreach ($_companies as $company) { $sector_value = $company['info']['sector']; if (!in_array($sector_value, $sectors)) { $sectors[] = $sector_value; } } $z = 1; $json = '{"children": ['; $v1_count = count($sectors); $i = 1; foreach ($sectors as $sector) { $json .= '{'; $json .= '"name": "' . string_to_json($sector) . '",'; $v2_count = 0; foreach ($_companies as $company) { if ($company['info']['sector'] == $sector) { $v2_count++; } } $json .= '"children": ['; $j = 1; foreach ($_companies as $company) { $sector_value = $company['info']['sector']; $company_name = $company['info']['company_name']; $kpi_value = $company[$kpi]; $kpi_value = empty($kpi_value) ? 1000000 : $kpi_value; if ($sector_value == $sector) { $json .= '{'; $name = string_to_json($company_name); $json .= '"name": "' . $name . '",'; $json .= '"data-index": "' . $z . '",'; $z++; /* foreach ($r_kpis as $c) { if(!empty($c)){ $json .= '"data-'.$c.'": "'.$company[sprintf( "%06d", $c )].'",'; } } */ foreach ($r_kpis as $c) { if (array_key_exists($c, $company)) { if (empty($company[$c])) { $json .= ' "data-' . $c . '" : "0",'; $json .= ' "data-' . $c . '-exist" : "false",'; } else { $json .= ' "data-' . $c . '" : "' . $company[sprintf("%06d", $c)] . '",'; $json .= ' "data-' . $c . '-exist" : "true",'; } } } $json .= '"size": "' . $kpi_value . '"'; $json .= '}'; if ($j != $v2_count) { $json .= ','; } $j++; } } $json .= ']'; $json .= '}'; if ($i != $v1_count) { $json .= ','; } $i++; } $json .= ']'; $json .= '}'; $data['json'] = $json; } $this->load->view('commun/json_view', $data); }