$rowCount = $this->_dashBoardRowCount;
}
if ($this->addPaging) {
- $this->_select = str_ireplace('SELECT ', 'SELECT SQL_CALC_FOUND_ROWS ', $this->_select);
+ $this->_select = preg_replace('/SELECT(\s+SQL_CALC_FOUND_ROWS)?\s+/i', 'SELECT SQL_CALC_FOUND_ROWS ', $this->_select);
$pageId = CRM_Utils_Request::retrieve('crmPID', 'Integer');
public function add2group($groupID) {
if (is_numeric($groupID) && isset($this->_aliases['civicrm_contact'])) {
$select = "SELECT DISTINCT {$this->_aliases['civicrm_contact']}.id AS addtogroup_contact_id, ";
-
- // here are we are prepending / adding contact id field that could be used for adding group
- // so first check for "SELECT SQL_CALC_FOUND_ROWS" and if does not exist replace "SELECT"
- if (preg_match('/^SELECT SQL_CALC_FOUND_ROWS/', $this->_select)) {
- $select = str_ireplace('SELECT SQL_CALC_FOUND_ROWS ', $select, $this->_select);
- }
- else {
- $select = str_ireplace('SELECT ', $select, $this->_select);
- }
-
+ $select = preg_replace('/SELECT(\s+SQL_CALC_FOUND_ROWS)?\s+/i', $select, $this->_select);
$sql = "{$select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy}";
$sql = str_replace('WITH ROLLUP', '', $sql);
$dao = CRM_Core_DAO::executeQuery($sql);