CRM-17571 - enabling search builder through label instead of id (activity)
authorUelen Paulo <uelenpaulo@gmail.com>
Fri, 4 Mar 2016 03:46:06 +0000 (00:46 -0300)
committerUelen Paulo <uelenpaulo@gmail.com>
Fri, 4 Mar 2016 03:46:06 +0000 (00:46 -0300)
CRM/Activity/BAO/Activity.php
CRM/Contact/Form/Search/Builder.php
templates/CRM/Contact/Form/Search/Builder.js

index f5a5a0ac46b849a5e850e4071dd0d4b8f9379f03..7a41374b58556491f267c3a55f90dcacc446e919 100644 (file)
@@ -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);
index 5577b25610cb85b60e57342d9b1ccede76366ee1..85077a6d740e224176de25c6957f3c4d4fe23d18 100644 (file)
@@ -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
index 7a246032d6b9513c2bab788afb29bfa944c71a06..5ac08815bdd8bdba88c12858e8d1c75eeca695d9 100644 (file)
       }
     }
     $.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('<option value="' + option.key + '"' + selected + '>' + option.value + '</option>');
     });
     select.change();