Skip to content

Commit

Permalink
Fix fatal error when sorting by status in activity search
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 21, 2019
1 parent 448b2c0 commit 441f527
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2475,15 +2475,15 @@ 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'])) {
$fields[$pseudoConstant['optionGroupName']] = [
'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.
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/CRM/Activity/Selector/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 441f527

Please sign in to comment.