public function get_result($callback, Criteria $criteria = null, $namespace_model_method = FALSE) { if (!$criteria) { $criteria = new Criteria(); } if ($this->_CI->uri->segment(2, 'index') != 'get_notes' && $this->_CI->uri->segment(2, 'index') != 'get_logs') { $criteria->order($this->_get_order() . ' ' . $this->_get_direction()); } if ($namespace_model_method !== FALSE) { $temp = explode('|', $this->_CI->encrypt->decode($namespace_model_method)); if (count($temp) == 3) { $namespace = $temp[0]; $model = $temp[1]; $method = $temp[2]; $callback = array($this->_CI->{$model}, $method); //get search conditions from session using namespace. $search_conditions = $this->_CI->session->userdata($namespace . '_search_conditions'); $narrow_search_conditions = $this->_CI->session->userdata($namespace . '_search_narrow_conditions'); //now convert these above conditions to criteria $criteria = $this->_CI->get_search_criteria($search_conditions); $criteria = $this->_CI->get_search_criteria($narrow_search_conditions, $criteria); //get order_field and its direction $order_field = FALSE; $direction = FALSE; if ($this->_CI->session->userdata($namespace . '_order_field')) { $order_field = $this->_CI->session->userdata($namespace . '_order_field'); } if ($this->_CI->session->userdata($namespace . '_direction')) { $direction = $this->_CI->session->userdata($namespace . '_direction'); } if ($order_field !== FALSE && $direction !== FALSE) { $criteria->order($order_field . ' ' . $direction); } } } if ($this->_disallow_empty && count($criteria->spec_where()) < 2) { $result = array('list' => array(), 'count' => 0); $data['empty_request'] = true; } else { $result = call_user_func($callback, $criteria); } if ($this->_map) { $result['list'] = call_user_func($this->_map, $result['list']); } $data['list'] = $result['list']; $data['count'] = $result['count']; return $data; }
public function get_list(Criteria $criteria = null) { if (!$criteria) { $criteria = new Criteria(); } if ($criteria->order()) { $this->db->order_by($criteria->order()); } if ($criteria->limit()) { $this->db->limit($criteria->limit(), $criteria->offset()); } $this->_prepare_fields($criteria); $this->_prepare_from(); $this->_prepare_where($criteria); if ($this->_debug) { $res = $this->db->get(); log_message('debug', $this->db->last_query()); return $res->result_array(); } $result = $this->db->get(); if ($result === false) { throw new Exception($this->db->_error_message()); } return $result->result_array(); }