<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Servey_model extends CI_Model {


    public function fetch_record() {
  	
        $data['guard'] = array();
        $guards = $this->db->where('Deleted_DT IS NULL')->or_where('(deleted_DT IS NOT NULL AND deactive_cronjob_flag = 1)')->get('mst_guard')->result();
        if (!empty($guards)) {
            foreach ($guards as $guard) {
                $data['guard'][$guard->id]['name'] = $guard->name;
                $data['guard'][$guard->id]['contact'] = $guard->contact;
            }
        }
        $data['questions'] = array();
        $questions = $this->db->where('deleted_DT IS NULL')->get('health_survey_questions')->result();
        if (!empty($questions)) {
            foreach ($questions as $quest) {
                $data['questions'][$quest->hs_id] = $quest->question;
            }
        }

        $data['answers'] = array();
        $data['questionids'] = array();
        if(!empty($_POST['date'])) {
            $this->db->where('date(inserted_DT)', $_POST['date']);
        }
        
        $answers = $this->db->where('Deleted_DT IS NULL')->order_by('inserted_DT', 'DESC')->get('health_survey_ans')->result();
        if (!empty($answers)) {
            foreach ($answers as $ans) {
                $data['answers'][date('Y-m-d', strtotime($ans->inserted_DT))][$ans->inserted_SI][$ans->questionid] = (!empty($ans->answer) ? (($ans->answer == 1) ? 'Yes' : 'No') : '');
                
            }
        }
        
        return $data;
    }
	

	
	
	public function field_serve2()
	{
	  $this->db->select('*'); 
  	  $this->db->from('reg__new_docw');
  	  $this->db->where('deleted_dt',NULL);
  	  $this->db->order_by('docw_regid','DESC');
 	  $query = $this->db->get();
      return $query->result();
  	
  	   /* $this->db->select('tad.d_id,mst_office.name as o_name,mst_office.city,mst_guard.name,mst_guard.DOJ');
	 	$this->db->where('tad.deleted_DT',NULL);
		$this->db->from('tr_assign_duty tad');
		$this->db->join('mst_office','mst_office.id=tad.office_name','left');
		$this->db->join('mst_guard','mst_guard.id=tad.guard_name','left');
		$this->db->order_by("tad.d_id","desc");
		return $query=$this->db->get()->result();*/
	}
	
}

?>