1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/controllers/Base_Controller.php');
- class Data extends Base_Controller {
- public function __construct() {
- parent::__construct();
- $this->load->model('Company_model');
- $this->load->model('Project_model');
- $this->load->model('Network_model');
- $this->load->model('Lamp_model');
- $this->load->model('Videomonitor_model');
- }
- public function index() {
- $project_id = $this->input->post('project_id', true);
- $show_projects = $this->input->post('show_projects', true);
- $show_networks = $this->input->post('show_networks', true);
- $show_lamps = $this->input->post('show_lamps', true);
- $lng_low = $this->input->post('lng_low', true);
- $lng_high = $this->input->post('lng_high', true);
- $lat_low = $this->input->post('lat_low', true);
- $lat_high = $this->input->post('lat_high', true);
- $companyid = $this->get_user_info('companyid');
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- $project_total = $this->Project_model->getTotal(array(), $role, $companyid, $userid);
- $network_total = $this->Network_model->getTotal(array(), $role, $companyid, $userid);
- $lamp_total = $this->Lamp_model->getTotal(array(), $role, $companyid, $userid);
- $data = array(
- "total_project" => intval($project_total),
- "total_network" => intval($network_total),
- "total_lamp" => intval($lamp_total)
- );
- $project_id = intval($project_id);
- $condition = array();
- if ($project_id > 0) {
- $condition['id'] = $project_id;
- }
- $project_data = $this->Project_model->getMultiData($condition, 'P.id, P.projectname as name', $role, $companyid, $userid);
- $pid_arr = array();
- foreach ($project_data as $key => $value) {
- $pid_arr[] = $value['id'];
- }
- if ($show_projects) {
- $data['projects'] = $project_data;
- }
- if ($show_networks) {
- $data['networks'] = !empty($pid_arr) ? $this->Network_model->get_list_in('projectid', $pid_arr, 'id, status, networkname as name') : array();
- }
- if ($show_lamps) {
- $filter = array();
- if (is_numeric($lng_low)) {
- $filter['lng_low'] = $lng_low;
- }
- if (is_numeric($lng_high)) {
- $filter['lng_high'] = $lng_high;
- }
- if (is_numeric($lat_low)) {
- $filter['lat_low'] = $lat_low;
- }
- if (is_numeric($lat_high)) {
- $filter['lat_high'] = $lat_high;
- }
- $data['lamps'] = !empty($pid_arr) ? $this->Lamp_model->get_list_in('L.projectid', $pid_arr, 'L.id, IFNULL(L.status,0) as status, L.isfaulted, N.status as online, L.longitude, L.latitude', $filter) : array();
- }
- exit(json_result('0000', $this->response['0000'], $data));
- }
-
- public function get_project_company(){
- $id = $this->input->post('id',true);
- $type = $this->input->post('type',true);
- if ($type == 1) {
- $data = $this->Lamp_model->get_project_company(array('L.id'=>$id),'P.id as projectid,P.company as companyid,L.longitude,L.latitude,L.direction');
- }else{
- $data = $this->Videomonitor_model->get_project_company(array('V.id'=>$id),'P.id as projectid,P.company as companyid,V.longitude,V.latitude');
- }
- $data['longitude'] = empty($data['longitude']) ? 0 : floatval($data['longitude']);
- $data['latitude'] = empty($data['latitude']) ? 0 : floatval($data['latitude']);
- exit(json_result('0000',$this->response['0000'],$data));
- }
- }
|