From da8931de22346a9c5c1e5b3922b0ea0f1a3c1a54 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 21 Apr 2020 19:21:23 +1000 Subject: [PATCH] dev/core#1710 Ensure that civicrm_case_activity is properly populated for use by report query when run in force mode 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 --- CRM/Report/Form/Activity.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index 6bd904d4d73b..3329fdaf1650 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -312,6 +312,10 @@ public function __construct() { '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,15 @@ public function __construct() { 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' => [ + 'no_display' => TRUE, + 'required' => TRUE, + 'dbAlias' => $columns['civicrm_case_activity']['alias'] . '.case_id', + ], + ]; + return $columns; } /** @@ -733,6 +730,11 @@ public function buildQuery($applyLimit = TRUE) { } } + if (!empty($this->_params['include_case_activities_value'])) { + $columns = self::addCaseActivityColumns($this->_columns); + $this->_columns = $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.