<?php

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

class Category_model extends CI_Model
{

    public $table = 'category';
    public $id = 'id';
    public $order = 'DESC';

    function __construct()
    {
        parent::__construct();
    }

    // get all
    function get_all()
    {
        $this->db->order_by($this->id, $this->order);
        return $this->db->get($this->table)->result();
    }

    // get data by id
    function get_by_id($id)
    {
        $this->db->where($this->id, $id);
        return $this->db->get($this->table)->row();
    }
    
    // get total rows
    function total_rows($q = NULL) {
        $this->db->join('menu','category.fiMenuId=menu.id', 'right');
        $this->db->where("(`category.id` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fiMenuId` LIKE '%".$q."%' ESCAPE '!' OR `menu`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' )");
	$this->db->from($this->table);
        return $this->db->count_all_results();
    }

    // get data with limit and search
    function get_limit_data($limit, $start = 0, $q = NULL) {
        $this->db->select('category.*,menu.fsTitle fsmenu');
        $this->db->join('menu','category.fiMenuId=menu.id', 'right');
        $this->db->order_by($this->id, $this->order);
        // $this->db->where("(`category.id` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fiMenuId` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fsImage` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fiStatus` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fdCreateDate` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fdUpdateDate` LIKE '%".$q."%' ESCAPE '!' )");
        $this->db->where("(`category.id` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fiMenuId` LIKE '%".$q."%' ESCAPE '!' OR `menu`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' OR `category`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' )");
	$this->db->limit($limit, $start);
        return $this->db->get($this->table)->result();
    }

    // insert data
    function insert($data)
    {
        $this->db->insert($this->table, $data);
    }

    // update data
    function update($id, $data)
    {
        $this->db->where($this->id, $id);
        $this->db->update($this->table, $data);
    }

    // delete data
    function delete($id)
    {
        $this->db->where($this->id, $id);
        $this->db->delete($this->table);
    }

}

/* End of file Category_model.php */
/* Location: ./application/models/Category_model.php */
/* Please DO NOT modify this information : */
/* Generated by Harviacode Codeigniter CRUD Generator 2020-03-13 09:27:44 */
/* http://harviacode.com */