<?php

/**
 * Toko
 * 
 * Description...
 * 
 * @package toko
 * @author user <your@email.com>
 * @version 0.0.0
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Toko_model extends CI_Model {

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

    function getRows($params = array()) {
        $mid = $this->input->get('id');
        $gid = $this->session->userdata('catid');
        $id = "";
        if ($mid == 0) {
            $id = $gid;
        } else {
            $id = $mid;
        }

        $this->db->select('*');
        $this->db->from('product');
        $this->db->where('category_id', $id);
        $this->db->order_by('id', 'desc');

        if (array_key_exists("start", $params) && array_key_exists("limit", $params)) {
            $this->db->limit($params['limit'], $params['start']);
        } elseif (!array_key_exists("start", $params) && array_key_exists("limit", $params)) {
            $this->db->limit($params['limit']);
        }

        $query = $this->db->get();

        return ($query->num_rows() > 0) ? $query->result() : FALSE;
    }

    function getRowsSearch($params = array()) {
        $ses_kt = $this->session->userdata('keyword_sc');
        if ($ses_kt == "") {
            $keyword_sc = $this->input->post('keyword');
        } else {
            $keyword_sc = $ses_kt;
        }

        $this->db->select('*');
        $this->db->from('product');
        $this->db->where('category_id', "!= 2");
        $ids = explode(' ', $keyword_sc);
        foreach ($ids as $is) {
            $this->db->like('product_name', $is);
        }

        if (array_key_exists("start", $params) && array_key_exists("limit", $params)) {
            $this->db->limit($params['limit'], $params['start']);
        } elseif (!array_key_exists("start", $params) && array_key_exists("limit", $params)) {
            $this->db->limit($params['limit']);
        }

        $query = $this->db->get();

        return ($query->num_rows() > 0) ? $query->result() : FALSE;
    }

}

/* End of file toko.php */
/* Location: ./application/models/toko.php */