CRM-21715: Activity Report: move SQL creation in a buildQuery function.
authorMathieu Lutfy <mathieu@bidon.ca>
Thu, 25 Jan 2018 03:53:42 +0000 (22:53 -0500)
committerMathieu Lutfy <mathieu@bidon.ca>
Fri, 26 Jan 2018 21:11:49 +0000 (16:11 -0500)
CRM/Report/Form/Activity.php

index ede7d340c68fe6fcdac42bf44768bb2a57b8129c..e024ba937e62d54fe21dda9efc3cf828ee55385e 100644 (file)
@@ -781,12 +781,12 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
     return $errors;
   }
 
-  public function postProcess() {
-    //reset value of activity_date
-    if (!empty($this->_resetDateFilter)) {
-      $this->_formValues["activity_date_time_relative"] = NULL;
-    }
-    $this->beginPostProcess();
+  /**
+   * @param $applyLimit
+   *
+   * @return string
+   */
+  public function buildQuery($applyLimit = TRUE) {
     $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
 
@@ -868,7 +868,11 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
         $this->alterSectionHeaderForDateTime('civireport_activity_temp_target', $section['tplField']);
       }
     }
-    $this->limit();
+
+    if ($applyLimit) {
+      $this->limit();
+    }
+
     $groupByFromSelect = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, 'civicrm_activity_id');
 
     $this->_where = " WHERE (1)";
@@ -885,7 +889,20 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
       LEFT JOIN civicrm_contact contact_civireport ON contact_civireport.id = {$this->_aliases['civicrm_activity_contact']}.contact_id
       {$this->_where} {$groupByFromSelect} {$this->_having} {$this->_orderBy} {$this->_limit}";
 
+    CRM_Utils_Hook::alterReportVar('sql', $this, $this);
     $this->addToDeveloperTab($sql);
+
+    return $sql;
+  }
+
+  public function postProcess() {
+    //reset value of activity_date
+    if (!empty($this->_resetDateFilter)) {
+      $this->_formValues["activity_date_time_relative"] = NULL;
+    }
+
+    $this->beginPostProcess();
+    $sql = $this->buildQuery(TRUE);
     $this->buildRows($sql, $rows);
 
     // format result set.