<?php if(!defined('BASEPATH')) exit('No direct script access allowed');   
class Purchase_Model extends CI_Model {
    
    public function  __construct(){      
        parent::__construct();        
    }

    function  get_tag($type="") {
    	if($type){
    		$this->db->like("user_type",$type);
    	}
    	$this->db->group_by('tag_name');
    	$this->db->select('*,count(*) as all_count');
    	$query = $this->db->get('pts_tags');
		if($query->num_rows()>0) {
			//pr($query->result());die;
			return $query->result();
		} else {
			return false;
		}
	}


	function  get_tag_id($id) {
		$this->db->where('tag_id',$id);
		$query = $this->db->get('pts_tags');
		if($query->num_rows()>0) {
			return $query->row();
		} else {
			return false;
		}
	}

	function  save($data) {
		$query = $this->db->insert('pts_tags', $data); 
		if($query){	return  $this->db->insert_id(); } else { return false; }
	}

	function  update($id,$data) {
		$this->db->where('tag_id', $id);
		$query = $this->db->update('pts_tags', $data); 
		if($query){
			return true;
		} else {
			return false;
		}
	}

	function  delete($id) {
		$this->db->where('tag_id', $id);
		$query = $this->db->delete('pts_tags'); 
		if($query){
			return true;
		} else {
			return false;
		}
	}

	function  status($id,$status) {
		$data = array('status'=>$status);
		$this->db->where('tag_id', $id);
		$query = $this->db->update('get_tags', $data); 
		//echo $this->db->last_query();
		if($query){
			return true;
		} else {
			return false;
		}
	}

}
