<?php 
class subservices_model extends CI_Model {
	public function _consruct(){
		parent::_construct();
	}


public function getsubcatData($subcat_id='',$view=''){
		$cond  = (!empty($view))?" status IN ($view) ":" ss.status != '2'";
		$cond .= (!empty($subcat_id))?" AND ss.id='$subcat_id' ":"";

		$subcatData = $this->db->query("SELECT ss.*,s.service_name FROM sub_services as ss
           LEFT JOIN  services as s ON s.id = ss.service_id 


			WHERE $cond AND s.status!='2' Order by ss.id DESC");

		if(!empty($subcatData)){
			return (empty($subcat_id))?$subcatData->result():$subcatData->row();
		}
		return 0;
	}

	 public function add_subservices($subcatData){

		$qry = $this->db->insert('sub_services',$subcatData);

		if ($this->db->trans_status() === TRUE)
		{
			$this->db->trans_commit();
			return TRUE;
		}else
		{
			$this->db->trans_rollback();
			return false;
		}
	}

 function update_subservices($id,$subcatData)
    {


        $this->db->where('id',$id);
        $qry = $this->db->update('sub_services',$subcatData);
        return true;


    }
function getcatData(){
		$query = $this->db->query("SELECT * FROM `services` WHERE status='1' order by id DESC ");
		if(!empty($query)){
			return $query->result_array();
		}
		return;
	}
function delete_subservices($id) {
		$data = array(  
			'status' => '2'   
		);  
		$this->db->where('id', $id);
		$result =  $this->db->update('sub_services', $data); 
		if($result) {
			return "Success";
		}
		else {
			return "Error";
		}
	}


}
