From 441f527ca8f16d8d049d2bb8a55cc91a66d314cc Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 22 Nov 2019 11:53:02 +1300 Subject: [PATCH] Fix fatal error when sorting by status in activity search --- CRM/Activity/BAO/Activity.php | 5 ++- CRM/Core/DAO.php | 4 +- .../CRM/Activity/Selector/SearchTest.php | 38 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index a18061ae9667..11e8a49c5a2c 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2119,6 +2119,9 @@ public static function exportableFields($name = 'Activity') { 'type' => CRM_Utils_Type::T_STRING, ]; + // @todo - remove these - they are added by CRM_Core_DAO::appendPseudoConstantsToFields + // below. That search label stuff is referenced in search builder but is likely just + // a hack that duplicates, maybe differently, other functionality. $Activityfields = [ 'activity_type' => [ 'title' => ts('Activity Type'), @@ -2189,7 +2192,7 @@ public static function exportableFields($name = 'Activity') { // add custom data for case activities $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Activity')); - + CRM_Core_DAO::appendPseudoConstantsToFields($fields); self::$_exportableFields[$name] = $fields; return self::$_exportableFields[$name]; } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index c2f024face8a..4f1bad0a36a7 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2475,7 +2475,7 @@ public static function getGlobalSetting($name, $default = NULL) { * @param array $fields */ public static function appendPseudoConstantsToFields(&$fields) { - foreach ($fields as $field) { + foreach ($fields as $fieldUniqueName => $field) { if (!empty($field['pseudoconstant'])) { $pseudoConstant = $field['pseudoconstant']; if (!empty($pseudoConstant['optionGroupName'])) { @@ -2483,7 +2483,7 @@ public static function appendPseudoConstantsToFields(&$fields) { 'title' => CRM_Core_BAO_OptionGroup::getTitleByName($pseudoConstant['optionGroupName']), 'name' => $pseudoConstant['optionGroupName'], 'data_type' => CRM_Utils_Type::T_STRING, - 'is_pseudofield_for' => $field['name'], + 'is_pseudofield_for' => $fieldUniqueName, ]; } // We restrict to id + name + FK as we are extending this a bit, but cautiously. diff --git a/tests/phpunit/CRM/Activity/Selector/SearchTest.php b/tests/phpunit/CRM/Activity/Selector/SearchTest.php index 9370cd56c007..c6eec4180d86 100644 --- a/tests/phpunit/CRM/Activity/Selector/SearchTest.php +++ b/tests/phpunit/CRM/Activity/Selector/SearchTest.php @@ -47,4 +47,42 @@ public function testActivitySearchComponentPermission() { $this->assertEquals("civicrm_activity.location = 'Baker Street'", $queryObject->_where[''][0]); } + public function testActivityOrderBy() { + $sortVars = [ + 1 => [ + 'name' => 'activity_date_time', + 'sort' => 'activity_date_time', + 'direction' => 2, + 'title' => 'Date', + ], + 2 => [ + 'name' => 'activity_type_id', + 'sort' => 'activity_type_id', + 'direction' => 4, + 'title' => 'Type', + ], + 3 => [ + 'name' => 'activity_subject', + 'sort' => 'activity_subject', + 'direction' => 4, + 'title' => 'Subject', + ], + 4 => [ + 'name' => 'source_contact', + 'sort' => 'source_contact', + 'direction' => 4, + 'title' => 'Added By', + ], + 5 => [ + 'name' => 'activity_status', + 'sort' => 'activity_status', + 'direction' => 1, + 'title' => 'Status', + ], + ]; + $sort = new CRM_Utils_Sort($sortVars, '5_u'); + $searchSelector = new CRM_Activity_Selector_Search($queryParams, CRM_Core_Action::VIEW); + $searchSelector->getRows(4, 0, 50, $sort); + } + }