From 15c80835853b8d08da02641b5970a9a8b5b2e984 Mon Sep 17 00:00:00 2001 From: Uelen Paulo Date: Fri, 4 Mar 2016 00:46:06 -0300 Subject: [PATCH] CRM-17571 - enabling search builder through label instead of id (activity) --- CRM/Activity/BAO/Activity.php | 2 ++ CRM/Contact/Form/Search/Builder.php | 6 ++++++ templates/CRM/Contact/Form/Search/Builder.js | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index f5a5a0ac46..7a41374b58 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2173,11 +2173,13 @@ AND cl.modified_id = c.id 'title' => ts('Activity Type'), 'name' => 'activity_type', 'type' => CRM_Utils_Type::T_STRING, + 'searchByLabel' => true, ), 'activity_status' => array( 'title' => ts('Activity Status'), 'name' => 'activity_status', 'type' => CRM_Utils_Type::T_STRING, + 'searchByLabel' => true, ), ); $fields = array_merge($Activityfields, $exportableFields); diff --git a/CRM/Contact/Form/Search/Builder.php b/CRM/Contact/Form/Search/Builder.php index 5577b25610..85077a6d74 100644 --- a/CRM/Contact/Form/Search/Builder.php +++ b/CRM/Contact/Form/Search/Builder.php @@ -94,10 +94,15 @@ class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search { // Get fields of type date // FIXME: This is a hack until our fields contain this meta-data $dateFields = array(); + $searchByLabelFields = array(); foreach ($fields as $name => $field) { if (strpos($name, '_date') || CRM_Utils_Array::value('data_type', $field) == 'Date') { $dateFields[] = $name; } + // it's necessary to know which of the fields are searchable by label + if (isset($field['searchByLabel']) && $field['searchByLabel']) { + $searchByLabelFields[] = $name; + } } // Add javascript CRM_Core_Resources::singleton() @@ -108,6 +113,7 @@ class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search { 'newBlock' => $this->get('newBlock'), 'dateFields' => $dateFields, 'fieldOptions' => self::fieldOptions(), + 'searchByLabelFields' => $searchByLabelFields, ), )); //get the saved search mapping id diff --git a/templates/CRM/Contact/Form/Search/Builder.js b/templates/CRM/Contact/Form/Search/Builder.js index 7a246032d6..5ac08815bd 100644 --- a/templates/CRM/Contact/Form/Search/Builder.js +++ b/templates/CRM/Contact/Form/Search/Builder.js @@ -123,7 +123,11 @@ } } $.each(CRM.searchBuilder.fieldOptions[field], function(key, option) { - var selected = ($.inArray(''+option.key, options) > -1) ? 'selected="selected"' : ''; + var optionKey = option.key; + if ($.inArray(field, CRM.searchBuilder.searchByLabelFields) >= 0) { + optionKey = option.value; + } + var selected = ($.inArray(''+optionKey, options) > -1) ? 'selected="selected"' : ''; select.append(''); }); select.change(); -- 2.25.1