dev/core#1710 Ensure that civicrm_case_activity is properly populated for use by...
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 21 Apr 2020 09:21:23 +0000 (19:21 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 26 Apr 2020 23:44:33 +0000 (09:44 +1000)
Move table definition into constructor to set alias using standard ways and only rely on the code in the buildQuery to add in the case_id column as necessary

Fix hiding of case_id column

Update to include Case ID column

CRM/Report/Form/Activity.php

index 6bd904d4d73b7d96881bb6a84759313149826ea4..ed95a7722c04f9f21def9d64a83d8ebd63a787e4 100644 (file)
@@ -312,6 +312,10 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         'operatorType' => CRM_Report_Form::OP_SELECT,
         'options' => ['0' => ts('No'), '1' => ts('Yes')],
       ];
+      $this->_columns['civicrm_case_activity'] = [
+        'dao' => 'CRM_Case_DAO_CaseActivity',
+        'fields' => [],
+      ];
     }
 
     if ($campaignEnabled) {
@@ -349,22 +353,16 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
     parent::__construct();
   }
 
-  public function preProcess() {
-    // Is "Include Case Activities" selected?  If yes, include the case_id as a hidden column
-    $formToUse = $this->noController ? NULL : $this;
-    $includeCaseActivities = CRM_Utils_Request::retrieve('include_case_activities_value', 'Boolean', $formToUse);
-    if (!empty($includeCaseActivities)) {
-      $this->_columns['civicrm_case_activity'] = [
-        'dao' => 'CRM_Case_DAO_CaseActivity',
-        'fields' => [
-          'case_id' => [
-            'no_display' => TRUE,
-            'required' => TRUE,
-          ],
-        ],
-      ];
-    }
-    parent::preProcess();
+  protected static function addCaseActivityColumns($columns) {
+    $columns['civicrm_case_activity']['fields'] = [
+      'case_id' => [
+        'title' => ts('Case ID'),
+        'required' => TRUE,
+        'dbAlias' => $columns['civicrm_case_activity']['alias'] . '.case_id',
+        'type' => CRM_Utils_Type::T_INT,
+      ],
+    ];
+    return $columns;
   }
 
   /**
@@ -733,6 +731,10 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
       }
     }
 
+    if (!empty($this->_params['include_case_activities_value'])) {
+      $this->_columns = self::addCaseActivityColumns($this->_columns);
+    }
+
     // @todo - all this temp table stuff is here because pre 4.4 the activity contact
     // form did not exist.
     // Fixing the way the construct method declares them will make all this redundant.