/** * This function only produces the COUNT query wrapped in `_dt_record_cnt` * The parent function produces the main select queries */ protected function _build_select() { if (!$this->cnt_query) { return parent::_build_select(); } // If the query is raw we need to remove the LIMIT and OFFSET and // replace the param values before proceeding. if ($this->_is_raw_query) { $this->_values = $this->_raw_parameters; $query = $this->_raw_query; $new_vals = array(); if (is_array($this->_values)) { foreach ($this->_values as $k => $v) { // @todo find a better way to do this for raw_queries if ($k == 'limit') { $query = str_ireplace('LIMIT :limit', '', $query); continue; } if ($k == 'offset') { $query = str_ireplace('OFFSET :offset', '', $query); continue; } if (!is_numeric($v)) { $v = '"' . $v . '"'; } $query = str_replace(':' . $k, $v, $query); } } $query = "SELECT COUNT(*) as _dt_record_cnt FROM (" . $query . ") dt_bridge_cnt"; return $query; } // Build and return the full SELECT statement by concatenating // the results of calling each separate builder method. $query = $this->_join_if_not_empty(" ", array($this->_build_select_start(), $this->_build_join(), $this->_build_where(), $this->_build_group_by(), $this->_build_having(), $this->_build_order_by(), $this->_build_limit(), $this->_build_offset())); $query = "SELECT COUNT(*) as _dt_record_cnt FROM (" . $query . ") dt_bridge_cnt"; return $query; }