From baa8595a662051e3061debfd7e070f8f3b2b536b Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Tue, 13 Oct 2015 15:38:09 +0100 Subject: [PATCH] fixes for CRM-16719 --- CRM/Report/Form.php | 10 +++++++++- CRM/Report/Form/ActivitySummary.php | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index ee00b3c2ad..5d5899a934 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -4444,7 +4444,15 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a 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, "; - $select = str_ireplace('SELECT SQL_CALC_FOUND_ROWS ', $select, $this->_select); + + // 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); + } $sql = "{$select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy}"; $sql = str_replace('WITH ROLLUP', '', $sql); diff --git a/CRM/Report/Form/ActivitySummary.php b/CRM/Report/Form/ActivitySummary.php index 897e516b97..deaf0df632 100644 --- a/CRM/Report/Form/ActivitySummary.php +++ b/CRM/Report/Form/ActivitySummary.php @@ -522,7 +522,6 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form { // now build the query for duration sum $this->from(TRUE); - $this->customDataFrom(); $this->where(TRUE); // build the query to calulate duration sum @@ -557,6 +556,11 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form { // assign variables to templates $this->doTemplateAssignment($rows); + //reset the sql building to default, which is used / called during other actions like "add to group" + // now build the query for duration sum + $this->from(); + $this->where(); + // do print / pdf / instance stuff if needed $this->endPostProcess($rows); } -- 2.25.1