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

class category_model extends CI_Model 
{

	function __construct()
    {
        parent::__construct();
        
    }
    function allcategory_details(){ 
        $this->db->select('name,id,');
        $this->db->from('category');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->order_by("name", "asc");
        $query=$this->db->get();
        return $query->result_array();
    }
   
    function addcategory($data){
        if($data['name']!=''){
            $name = $this->category_model->check_already_category($data['name']);
            if($name>0){
                $return = array();
                $return['msg']='alreadyexist';
                $return['error']='none';
            }else{
               $this->db->insert('category', $data);
               $return = array();
               $return['msg']=$this->db->insert_id();
               $return['error']='none';
            }
        }   
        return $return;
    }
    function check_already_category($name){
        $this->db->select('name');
        $this->db->from('category');
        $this->db->where('name', $name);
        $query = $this->db->get();
        $numr =$query->num_rows();
        return $numr;
    }
    function editcategory($data){
        $this->db->update("category", $data, array('id' => $data['id']));
        return $this->db->affected_rows();
    }
    function single_category_details($categoryid){ 
        $this->db->select('*');
        $this->db->from('category');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->where("id", $categoryid);
        $query=$this->db->get();
        return $query->row_array();
    }
    function category_details($categoryid){ 
        $this->db->select('name,id,');
        $this->db->from('category');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->where_in('id',$categoryid);
        $this->db->order_by("name", "asc");
        $query=$this->db->get();
        return $query->result_array();
    }
    
       
}
?>
