fixes for CRM-16719
authorKurund Jalmi <kurund@yahoo.com>
Tue, 13 Oct 2015 14:38:09 +0000 (15:38 +0100)
committerKurund Jalmi <kurund@yahoo.com>
Tue, 13 Oct 2015 14:38:09 +0000 (15:38 +0100)
CRM/Report/Form.php
CRM/Report/Form/ActivitySummary.php

index ee00b3c2adf65fb95cf1fc3c2b4ac1b56f90b0e8..5d5899a934494bde9462c09e0d34ab715cf8d68a 100644 (file)
@@ -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);
index 897e516b9745a2b3829247b03036a021137c012d..deaf0df632445f57353b9c15ba9ad362f723ebde 100644 (file)
@@ -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);
   }